Skip to content

Add Markdown footnote support to from_markdown#56

Open
MattFisher wants to merge 1 commit into
ma2za:mainfrom
MattFisher:add-footnote-support
Open

Add Markdown footnote support to from_markdown#56
MattFisher wants to merge 1 commit into
ma2za:mainfrom
MattFisher:add-footnote-support

Conversation

@MattFisher

Copy link
Copy Markdown

Parse standard Markdown footnotes (text[^label] references and [^label]: definition lines) into Substack's footnoteAnchor inline nodes and footnote blocks.

Footnotes are numbered by order of first reference and labels may be numeric or named.

Also adds Post.footnote_anchor() and Post.footnote() helpers for building footnotes manually, plus tests.

Parse standard Markdown footnotes (`text[^label]` references and
`[^label]: definition` lines) into Substack's footnoteAnchor inline nodes
and footnote blocks. Footnotes are numbered by order of first reference and
labels may be numeric or named. Also adds Post.footnote_anchor() and
Post.footnote() helpers for building footnotes manually, plus tests.
@ma2za

ma2za commented Jun 18, 2026

Copy link
Copy Markdown
Owner

I found a regression in the footnote pass: it runs before/after Markdown parsing at document scope, so footnote-like text inside code can be removed or rewritten.

Could you add regression coverage for these cases before merge?

def test_footnote_definition_inside_fenced_code_stays_code():
    post = make_post()
    post.from_markdown("```\n[^1]: not a footnote\n```")
    content = body_content(post)
    assert len(content) == 1
    assert content[0]["type"] == "codeBlock"
    assert content[0]["content"][0]["text"] == "[^1]: not a footnote"


def test_footnote_reference_inside_fenced_code_stays_text():
    post = make_post()
    post.from_markdown("```\ncode [^1]\n```\n\n[^1]: note")
    content = body_content(post)
    assert content[0]["type"] == "codeBlock"
    assert content[0]["content"][0]["text"] == "code [^1]"


def test_footnote_reference_inside_inline_code_stays_text():
    post = make_post()
    post.from_markdown("`code [^1]`\n\n[^1]: note")
    content = body_content(post)
    assert content[0]["type"] == "paragraph"
    assert content[0]["content"][0]["text"] == "code [^1]"
    assert content[0]["content"][0]["marks"] == [{"type": "code"}]

The first test currently fails on this branch with content[0]["type"] == "footnote" instead of codeBlock. The fix should keep footnote extraction out of fenced code blocks and skip injecting anchors into inline code-marked text nodes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants