Repository navigation
Closed
Labels
Description
The following:
Foo[^foo]
Bar[^bar]
[^foo]:
FooDef1
FooDef2
[^bar]:
BarDef
renders like so on GitHub:
but pulldown_cmark::Parser gets confused:
- It sees the definition text as indented code blocks.
- It does not see the end of the first definition before the start of the second.
Running the following code:
static MARKDOWN: &str = r#"\
Foo[^foo]
Bar[^bar]
[^foo]:
FooDef1
FooDef2
[^bar]:
BarDef
"#;
fn main() {
use pulldown_cmark::{Options, Parser};
let options = Options::empty().union(Options::ENABLE_FOOTNOTES);
let parser = Parser::new_ext(MARKDOWN, options);
for event in parser {
eprintln!("{event:?}");
}
}yields the following events:
- Start(Paragraph)
- HardBreak
- Text(Borrowed("Foo"))
- FootnoteReference(Borrowed("foo"))
- SoftBreak
- Text(Borrowed("Bar"))
- FootnoteReference(Borrowed("bar"))
- End(Paragraph)
- Start(FootnoteDefinition(Borrowed("foo")))
- Start(CodeBlock(Indented))
- Text(Borrowed("FooDef1\n"))
- Text(Borrowed("FooDef2\n"))
- End(CodeBlock(Indented))
- Start(FootnoteDefinition(Borrowed("bar")))
- Start(CodeBlock(Indented))
- Text(Borrowed("BarDef\n"))
- End(CodeBlock(Indented))
- End(FootnoteDefinition(Borrowed("bar")))
- End(FootnoteDefinition(Borrowed("foo")))
I would expect it to:
- treat the indented definitions as part of the definition, and
- end the first definition before starting the second.
There is a workaround:
Foo[^foo]
Bar[^bar]
[^foo]: FooDef1
FooDef2
[^bar]: BarDef
This yields:
- ...
- Start(FootnoteDefinition(Borrowed("foo")))
- Start(Paragraph)
- Text(Borrowed("FooDef1"))
- SoftBreak
- Text(Borrowed("FooDef2"))
- End(Paragraph)
- End(FootnoteDefinition(Borrowed("foo")))
- Start(FootnoteDefinition(Borrowed("bar")))
- Start(Paragraph)
- Text(Borrowed("BarDef"))
- End(Paragraph)
- End(FootnoteDefinition(Borrowed("bar")))
i.e. by putting content on the same line as the definition begins, the parser is happy. Unfortunately, at least one code formatter in VSCode for Markdown (maybe the built-in one?) likes to format long definitions indented below the [^foo]: opener.
Reacted by Toby Fleming, eitsupi and Evgeny

Activity
allenap commentedon Nov 27, 2022
Fwiw, I think this is the de facto documentation on GitHub footnotes, and it specifically mentions how indented blocks should be interpreted.
Add a separate mode to parse footnotes the same way GitHub does
Add a separate mode to parse footnotes the same way GitHub does
Keats commentedon Jun 3, 2023
Indented code blocks break lots of things, could there be an option to disable them?
Martin1887 commentedon Jun 4, 2023
What do you mean? Indented code blocks are in the CommonMark spec, so an option to disable them will not exist. This issue with indented footnote definitions will be fixed in the next release in the coming weeks.
Keats commentedon Jun 4, 2023
I've just been running into this issue with indented code messing up things (things built on top of pulldown-cmark, no issues with this crate) that I wish I could disable them. I might just eventually end up forking this crate just to do so.
Martin1887 commentedon Jun 6, 2023
#654 fixes this issue and it is already merged in the
masterbranch, so you can use themasterbranch until the 0.10 version is published instead of creating a fork.