Skip to main content

Welcome to SnakeMD

SnakeMD is your ticket to generating Markdown in Python. To prove it to you, we've generated this entire README using SnakeMD. See readme.py for how it was done. To get started, download and install SnakeMD:

pip install snakemd

In the remainder of this document, we'll show you all of the things this library can do. For more information, check out the official documentation here.

Table of Contents

Below you'll find the table of contents, but these can also be generated programatically for every Markdown document as follows:

def _table_of_contents(doc: Document):
    doc.add_table_of_contents(range(2, 4))
  1. Table of Contents
  2. Paragraphs
  3. Links
  4. Images
  5. Lists
    1. Ordered List
    2. Unordered List
    3. Checklist
    4. Nested Lists
  6. Tables
  7. Code Blocks
  8. Quotes
  9. Horizontal Rule
  10. Raw

Paragraphs

Paragraphs are the most basic feature of any Markdown file. As a result, they are very easy to create using SnakeMD.

SnakeMD Source

def _paragraph(doc: Document):
    doc.add_paragraph("I think. Therefore, I am.")

Markdown Source

I think. Therefore, I am.

Rendered Result

I think. Therefore, I am.

Links are targets to files or web pages and can be embedded in paragraphs in a variety of ways, such as with the insert_link() method.

SnakeMD Source

def _insert_link(doc: Document):
    doc.add_paragraph(
        "Learn to program with The Renegade Coder (@RenegadeCoder94)."
    ).insert_link("The Renegade Coder", "https://therenegadecoder.com").insert_link(
        "@RenegadeCoder94", "https://twitter.com/RenegadeCoder94"
    )

Markdown Source

Learn to program with [The Renegade Coder](https://therenegadecoder.com) ([@RenegadeCoder94](https://twitter.com/RenegadeCoder94)).

Rendered Result

Learn to program with The Renegade Coder (@RenegadeCoder94).

Images

Images can be added by embedding Inline elements in a paragraph.

SnakeMD Source

def _image(doc: Document):
    logo = "https://therenegadecoder.com/wp-content/uploads/2020/05/header-logo-without-tag-300x75.png"
    doc.add_block(Paragraph([Inline("Logo", image=logo)]))

Markdown Source

![Logo](https://therenegadecoder.com/wp-content/uploads/2020/05/header-logo-without-tag-300x75.png)

Rendered Result

Logo

Lists

SnakeMD can make a variety of Markdown lists. The three main types of lists are ordered, unordered, and checked.

Ordered List

Ordered lists are lists in which the order of the items matters. As a result, we number them.

SnakeMD Source

def _ordered_list(doc: Document):
    doc.add_ordered_list(["Deku", "Bakugo", "Uraraka", "Tsuyu"])

Markdown Source

1. Deku
2. Bakugo
3. Uraraka
4. Tsuyu

Rendered Result

  1. Deku
  2. Bakugo
  3. Uraraka
  4. Tsuyu

Unordered List

Unordered lists are lists in which the order of the items does not matter. As a result, we bullet them.

SnakeMD Source

def _unordered_list(doc: Document):
    doc.add_unordered_list(["Crosby", "Malkin", "Lemieux"])

Markdown Source

- Crosby
- Malkin
- Lemieux

Rendered Result

  • Crosby
  • Malkin
  • Lemieux

Checklist

Checklists are lists in which the items themselves can be checked on and off. This feature is new as of v0.10.0.

SnakeMD Source

def _checklist(doc: Document):
    doc.add_checklist(["Pass the puck", "Shoot the puck", "Score a goal"])

Markdown Source

- [ ] Pass the puck
- [ ] Shoot the puck
- [ ] Score a goal

Rendered Result

  • Pass the puck
  • Shoot the puck
  • Score a goal

Nested Lists

Nested lists are complex lists that contain lists. Currently, SnakeMD does not support any convenience methods to generate nested lists, but they can be created manually using the MDList object.

SnakeMD Source

def _nested_list(doc: Document):
    doc.add_block(
        MDList(
            [
                "Apples",
                Inline("Onions", bold=True),
                MDList(["Sweet", "Red"]),
                Paragraph(["This is the end of the list!"]),
            ]
        )
    )

Markdown Source

- Apples
- **Onions**
  - Sweet
  - Red
- This is the end of the list!

Rendered Result

  • Apples
  • Onions
    • Sweet
    • Red
  • This is the end of the list!

Tables

Tables are sets of rows and columns which can display text in a grid. To style any of the contents of a table, consider using Paragraph or Inline.

SnakeMD Source

def _table(doc: Document):
    doc.add_table(
        ["Height (cm)", "Weight (kg)", "Age (y)"],
        [["150", "70", "21"], ["164", "75", "19"], ["181", "87", "40"]],
        [Table.Align.LEFT, Table.Align.CENTER, Table.Align.RIGHT],
        0,
    )

Markdown Source

| Height (cm) | Weight (kg) | Age (y) |
| :---------- | :---------: | ------: |
| 150         | 70          | 21      |
| 164         | 75          | 19      |
| 181         | 87          | 40      |

Rendered Result

Height (cm) Weight (kg) Age (y)
150 70 21
164 75 19
181 87 40

Code Blocks

Code blocks are a form of structured text for sharing code snippets with syntax highlighting.

SnakeMD Source

def _code(doc: Document):
    doc.add_code("x = 5", lang="py")

Markdown Source

```py
x = 5
```

Rendered Result

x = 5

Quotes

Quotes are blocks of text that represent quotes from people.

SnakeMD Source

def _quote(doc: Document):
    doc.add_quote("How Now Brown Cow")

Markdown Source

> How Now Brown Cow

Rendered Result

How Now Brown Cow

Horizontal Rule

Horizontal Rules are visible dividers in a document.

SnakeMD Source

def _horizontal_rule(doc: Document):
    doc.add_horizontal_rule()

Markdown Source

***

Rendered Result


Raw

If at any time SnakeMD doesn't meet your needs, you can always add your own text using a raw block. These can be used to insert any preformatted text you like, such as HTML tags, Jekyll frontmatter, and more.

SnakeMD Source

def _raw(doc: Document):
    doc.add_raw("4<sup>2</sup> = 16<br />How cool is that?")

Markdown Source

4<sup>2</sup> = 16<br />How cool is that?

Rendered Result

42 = 16
How cool is that?

Metadata

Release files for SnakeMD 2.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for SnakeMD 2.4.1
File Size Uploaded
snakemd-2.4.1.tar.gz 24.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for SnakeMD 2.4.1
File Interpreter ABI Platform
snakemd-2.4.1-py3-none-any.whl Python 3 none any Details

Total release size: 49.0 kB

Release files / snakemd-2.4.1.tar.gz

Download URL snakemd-2.4.1.tar.gz
Size 24.3 kB
Tags Source
SHA-256 checksum
How to use checksums
574b232a61177d74270cff3d855b4eb8392f21bba7f02287f350daf3ac34c620
BLAKE2b-256 checksum
How to use checksums
2251d4f3bc43678766af9a9f43958cb64e73eb65368146e9d3a53f02fb56e526
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.0 CPython/3.10.20 Linux/6.17.0-1015-azure

Release files / snakemd-2.4.1-py3-none-any.whl

Download URL snakemd-2.4.1-py3-none-any.whl
Size 24.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3f1cc8547dbd5b28114be8c4a933159703ff81f0f1332ef4c03150a74193e60c
BLAKE2b-256 checksum
How to use checksums
beccc99dcb7f30ed5872440c7a9ab37cfb693fc584fe00539779371718640068
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.0 CPython/3.10.20 Linux/6.17.0-1015-azure

Release history Release notifications | RSS feed

This release

2.4.1 This release

2 release files

2.4.0

2 release files

2.3.0

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.0

2 release files

0.15.0

2 release files

0.14.0

2 release files

0.13.0

2 release files

0.10.1

2 release files

0.9.3

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page