|
| 1 | +# Markdown support |
| 2 | + |
| 3 | +`Post.from_markdown(markdown_content, api=None)` converts a Markdown document |
| 4 | +into Substack's document format. Parsing is handled by |
| 5 | +[markdown-it-py](https://github.com/executablebooks/markdown-it-py) (CommonMark) |
| 6 | +plus a few plugins, so standard CommonMark works as you'd expect. This page |
| 7 | +documents everything that maps to a Substack node. |
| 8 | + |
| 9 | +```python |
| 10 | +from substack.post import Post |
| 11 | + |
| 12 | +post = Post(title="My Post", subtitle="", user_id=api.get_user_id()) |
| 13 | +post.from_markdown(open("post.md").read(), api=api) |
| 14 | +draft = api.post_draft(post.get_draft()) |
| 15 | +``` |
| 16 | + |
| 17 | +Pass `api=` when your Markdown references local images so they can be uploaded |
| 18 | +(see [Images](#images)); it is optional otherwise. |
| 19 | + |
| 20 | +## Text formatting |
| 21 | + |
| 22 | +| Markdown | Result | |
| 23 | +|-------------------------------|-------------------| |
| 24 | +| `**bold**` | **bold** | |
| 25 | +| `*italic*` | *italic* | |
| 26 | +| `***bold italic***` | ***bold italic*** | |
| 27 | +| `` `inline code` `` | `inline code` | |
| 28 | +| `~~strikethrough~~` | ~~strikethrough~~ | |
| 29 | +| `^superscript^` | superscript | |
| 30 | +| `~subscript~` | subscript | |
| 31 | +| `[text](https://example.com)` | link | |
| 32 | +| `<https://example.com>` | autolinked URL | |
| 33 | + |
| 34 | +Note that subscript uses a single tilde (`~x~`) and strikethrough uses a double |
| 35 | +tilde (`~~x~~`); both work in the same document. |
| 36 | + |
| 37 | +## Headings |
| 38 | + |
| 39 | +Levels 1–6, using `#` through `######`. Headings may contain inline formatting |
| 40 | +and links. |
| 41 | + |
| 42 | +```markdown |
| 43 | +# Heading level 1 |
| 44 | +## Heading level 2 with **bold** and a [link](https://example.com) |
| 45 | +``` |
| 46 | + |
| 47 | +## Paragraphs and line breaks |
| 48 | + |
| 49 | +Blank lines separate paragraphs. A single newline within a paragraph is treated |
| 50 | +as a space (soft break), matching CommonMark. |
| 51 | + |
| 52 | +## Lists |
| 53 | + |
| 54 | +Bullet lists (`-`, `*`, or `+`) and ordered lists (`1.`), including nesting: |
| 55 | + |
| 56 | +```markdown |
| 57 | +- Bullet one |
| 58 | +- Bullet two |
| 59 | + - Nested bullet |
| 60 | + 1. Nested number |
| 61 | + |
| 62 | +1. Ordered one |
| 63 | +2. Ordered two |
| 64 | +``` |
| 65 | + |
| 66 | +## Blockquotes |
| 67 | + |
| 68 | +```markdown |
| 69 | +> A blockquote. |
| 70 | +> |
| 71 | +> With multiple paragraphs. |
| 72 | +``` |
| 73 | + |
| 74 | +## Code blocks |
| 75 | + |
| 76 | +Fenced code blocks, with an optional language for syntax highlighting, and |
| 77 | +indented code blocks: |
| 78 | + |
| 79 | +````markdown |
| 80 | +```python |
| 81 | +print("hello") |
| 82 | +``` |
| 83 | +```` |
| 84 | + |
| 85 | +## Horizontal rule |
| 86 | + |
| 87 | +```markdown |
| 88 | +--- |
| 89 | +``` |
| 90 | + |
| 91 | +## Images |
| 92 | + |
| 93 | +A paragraph containing only an image becomes a captioned image. |
| 94 | + |
| 95 | +```markdown |
| 96 | + |
| 97 | +``` |
| 98 | + |
| 99 | +- **Caption:** use the CommonMark title slot — ``. |
| 100 | +- **Link:** wrap the image in a link — `[](https://target.com)`. |
| 101 | +- **Local upload:** if `api=` is passed and the `src` is a local path (not an |
| 102 | + `http(s)` URL), the file is uploaded to Substack and the returned URL is used. |
| 103 | + Local paths resolve relative to the current working directory. |
| 104 | + |
| 105 | +```markdown |
| 106 | + |
| 107 | +``` |
| 108 | + |
| 109 | +## Footnotes |
| 110 | + |
| 111 | +References become inline anchors; definitions become footnote blocks at the end, |
| 112 | +numbered by order of first appearance. Labels may be numeric or named, and a |
| 113 | +definition may contain block content such as lists or multiple paragraphs. |
| 114 | + |
| 115 | +```markdown |
| 116 | +A claim that needs support.[^1] Another, with a named label.[^source] |
| 117 | + |
| 118 | +[^1]: The supporting detail, with a [link](https://example.com). |
| 119 | +[^source]: Author, *Title* (2025). |
| 120 | +``` |
| 121 | + |
| 122 | +A reference used more than once is emitted as a separate numbered anchor each |
| 123 | +time, mirroring the Substack editor. Definitions that are never referenced are |
| 124 | +dropped. |
| 125 | + |
| 126 | +## Math (LaTeX) |
| 127 | + |
| 128 | +Inline math with single dollars, block math with double dollars: |
| 129 | + |
| 130 | +```markdown |
| 131 | +Einstein showed $E=mc^2$ inline. |
| 132 | + |
| 133 | +$$ |
| 134 | +\int_0^\infty e^{-x} \, dx = 1 |
| 135 | +$$ |
| 136 | +``` |
| 137 | + |
| 138 | +Delimiters follow Pandoc's rules: the opening `$` must not be followed by |
| 139 | +whitespace, and the closing `$` must not be preceded by whitespace or followed |
| 140 | +by a digit. Ordinary dollar amounts (`$5 million to $10 million`) therefore |
| 141 | +stay plain text. A label after a block (`$$ ... $$ (label)`) is accepted but |
| 142 | +discarded, since Substack has no equation labels. |
| 143 | + |
| 144 | +## Pull quotes and callouts |
| 145 | + |
| 146 | +These use fenced-container syntax (`:::`), since they have no native Markdown |
| 147 | +equivalent: |
| 148 | + |
| 149 | +```markdown |
| 150 | +:::pullquote |
| 151 | +A highlighted pull quote. **Formatting** works inside. |
| 152 | +::: |
| 153 | + |
| 154 | +:::callout |
| 155 | +A callout block, e.g. an aside or note. |
| 156 | +::: |
| 157 | +``` |
| 158 | + |
| 159 | +## Not supported |
| 160 | + |
| 161 | +- **Tables** — Substack has no table renderer or editor UI for them, so GFM |
| 162 | + table syntax is not converted. To include tabular data, embed a chart (for |
| 163 | + example via [Datawrapper](https://support.substack.com/hc/en-us/articles/15722290158100)) |
| 164 | + and add it in the Substack editor. |
| 165 | +- Widgets authored only in the Substack editor (buttons, polls, embeds, etc.) |
| 166 | + have no Markdown equivalent. |
0 commit comments