Markdown support for endnotes, "endnotes" extension for both reader an writer#11508
Open
Markdown support for endnotes, "endnotes" extension for both reader an writer#11508
Conversation
The extension "endnotes" to support endnotes specified as a Note embedded in a Span with class "endnote" has been added to markdown. The extension is disabled by default.
When the "endnotes" extension is enabled, notes with a reference starting with "EN" are embedded in a Span with class "endnote". "EN" is the value of a constant `endnotePrefix`, which could set with an option in the future.
When checking out Extensions.hs from the docx-endnotes branch, I forgot to remove the "endnotes" extension from docx, since this branch comes from "main".
stEndnotes and stEndnoteNum have been added to WriterState, along with stNotes and stNoteNum. The goal is to put every Note, that is embedded in a Span.endnote, in stEndnotes, so to have two distinct groups of notes at the end, and endnotes' references prefixed with "EN".
The new option is used when the "endnotes" extensions is enabled to set the prefix of endnotes in markdown, both in the Reader and in the Writer. If not set, the current default is "EN".
When "endnotes" extension is enabled, the markdown Reader uses the value of option --endnotes-prefix to discriminate between footnotes and endnotes (which are the ones whose ref starts with that prefix).
When the endnotes extension is active, Notes inside Span of class "endnote" are treated as endnotes: - their refs are prefixed with "EN" or the prefix set with --endnotes-prefix - they are listed together after all the normal notes (footnotes)
When the "endnotes" extension is enabled, the endnotes (Notes wrapped in a Span of class "endnote") are written with refs that start with the prefix set with the --endnotes-prefix option. Moreover, notes' texts are written in a different way: first all the footnotes, then all the endnotes.
When a Span has the "endnote" class but it does not contain only a Note, the "endnote" class is not suppressed when endnotes extension is enabled.
This was referenced Mar 10, 2026
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.
This PR provides support for endnotes in markdown:
Noteembedded in aSpanof class "endnote"endnotesextension (disabled by default) is enabledboth for reader and writer (always under the condition that the
endnotesextension is enabled)In Pandoc AST, endnotes are Notes wrapped in a Span.endnote, so in markdown you can write:
If you use the
endnotesextension with the markdown reader with-f markdown+endnotes,you'll obtain the same AST if you write your source this way:
That's because the reader considers endnotes the notes that have a reference starting with "EN".
Footnotes are all the other notes that don't start with that prefix.
It's a prefix that can be set with the
--endnotes-prefix.For further reference, see the command/11503.md test and the second part of the first message in discussion #11503.
On the writer side, with
-t markdown+endnotes, you'll get all the endnotes prefixed with "EN"(or the string passed with
--endnotes-prefix).Moreover, all the footnotes' texts will be written before all the endnotes' ones.
In combination with PR #11501, you can write a markdown document with both footnotes and endnotes,
without the need to specify the
[...]{.endnote}Span, and then convert it to a DOCX file where footnotes and endnotes are distinct.