Skip to content

Markdown support for endnotes, "endnotes" extension for both reader an writer#11508

Open
massifrg wants to merge 11 commits intojgm:mainfrom
massifrg:md-endnotes
Open

Markdown support for endnotes, "endnotes" extension for both reader an writer#11508
massifrg wants to merge 11 commits intojgm:mainfrom
massifrg:md-endnotes

Conversation

@massifrg
Copy link
Contributor

@massifrg massifrg commented Mar 6, 2026

This PR provides support for endnotes in markdown:

  • when they are specified with a Note embedded in a Span of class "endnote"
  • it works only when the endnotes extension (disabled by default) is enabled
  • it's the same convention used in DOCX writer and reader: support for endnotes #11501, which provides support for endnotes for the DOCX format,
    both for reader and writer (always under the condition that the endnotes extension is enabled)

In Pandoc AST, endnotes are Notes wrapped in a Span.endnote, so in markdown you can write:

This paragraph has an endnote[[^1]]{.endnote}.

[^1]: Endnote text.

If you use the endnotes extension with the markdown reader with -f markdown+endnotes,
you'll obtain the same AST if you write your source this way:

This paragraph has an endnote[^EN1].

[^EN1]: Endnote text.

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.

massifrg added 11 commits March 5, 2026 19:20
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.
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.

1 participant