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:
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
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)).
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.
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?
Alternatives
Use instead of SnakeMD: tools that do the same job, closest first.