Add Markdown footnote support to from_markdown#56
Open
MattFisher wants to merge 1 commit into
Open
Conversation
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.
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Parse standard Markdown footnotes (
text[^label]references and[^label]: definitionlines) into Substack'sfootnoteAnchorinline nodes and footnote blocks.Footnotes are numbered by order of first reference and labels may be numeric or named.
Also adds
Post.footnote_anchor()andPost.footnote()helpers for building footnotes manually, plus tests.