Skip to main content

A markdown generation library for Python.

Project description

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 from The Renegade Coder.

Table of Contents

Below you'll find the table of contents, but these can also be generated programatically for every markdown document.

def _table_of_contents(doc: Document):
    doc.add_table_of_contents()
  1. Table of Contents
  2. Paragraphs
  3. Links
  4. Images
  5. Lists
  6. Tables
  7. Code Blocks
  8. Quotes
  9. Horizontal Rule

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

Links are targets to files or web pages and can be embedded in a Paragraph using InlineText.

SnakeMD Source

def _link(doc: Document):
    doc.add_element(Paragraph([
        InlineText("Learn to program with"),
        InlineText("The Renegade Coder", url="https://therenegadecoder.com")
    ]))

Markdown Source

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

Rendered Result

Learn to program with The Renegade Coder

Images

Images can be added by embedding InlineText 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_element(Paragraph([InlineText("Logo", url=logo, image=True)]))

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 two main types of lists are ordered and unordered.

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

Nested List

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_element(
        MDList([
            InlineText("Apples"),
            InlineText("Onions"),
            MDList([
                InlineText("Sweet"),
                InlineText("Red")
            ]),
            InlineText("Grapes")
        ])
    )

Markdown Source

- Apples
- Onions
  - Sweet
  - Red
- Grapes

Rendered Result

  • Apples
  • Onions
    • Sweet
    • Red
  • Grapes

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 InlineText.

SnakeMD Source

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

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


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

SnakeMD-0.2.0.tar.gz (11.7 kB view hashes)

Uploaded Source

Built Distribution

SnakeMD-0.2.0-py3-none-any.whl (12.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page