question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support footnote links

See original GitHub issue
  • Markwon version: 4.6.2

Hey @noties. It’s more of a feature request. Can markwon support footnotes or maybe how can i implement footnote links ?

Here's a simple footnote,[^1] and here's a longer one.[^bignote]

[^1]: This is the first footnote.

[^bignote]: Here's one with multiple paragraphs and code.

In the above example, clicking on [^1], scrolls to to bottom [^1]: This is the first footnote.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
notiescommented, Jul 28, 2021

Hello @damionx7 ,

the [comment]: comment markdown is actually a link reference, for example:

<!-- the [link] would become [link](https://example.com) -->
This is a [link]

[link]: https://example.com

And footnotes indeed are clashing with those. Unfortunately the link references are hardcoded into the parser, so it is not easy to add support for footnotes with current syntax

0reactions
notiescommented, Jul 29, 2021

Hello @damionx7 ,

yeah, sorry, I was unavailable. I don’t think it is possible to override default handling of reference links within the parser itself. There are just too many parts to consider. If you are interested you can take a look at the LinkReferenceDefinitionParser in the commonmark-java project. And related ParagraphParser and DocumentParser parsers. Adding footnotes support would require a major change to all these components.

I guess this is where commonmark-java inflexibility starts to play a role. Markwon has been relying on commonmark internals in order to tweak its parsing and make it more flexible. But lately they had changed internals in order to add support for source positions (unfortunately they are not suitable for editors, so good for nothing really). And this left Markwon behind as change is a bit more that I had anticipated before. Right now I’m seriously consider moving to other parsing stack, but still not sure if an abstract parsing layer should be added (so backends could be changed) or a different engine should be solely used or, finally, writing own solution for parsing.

Anyway, right now I see conceptually only one solution to the footnotes. Preprocess raw markdown and do no rely on parser at all. For example it is no uncommon for footnotes to be styled (marked) so you would want to run Markwon other then also. Something along these lines (pseudocode):

// matcher to match `[^1]` links to actual footnote contents
val matcher = referencesMatcher(markdown)
while (matcher.find() {
  val content = findContent(matcher, markdown)
  // content is found `[^1]: My contents`
  if (content != null) {
    // replace link `[^1]` so parser do not handle it
    replaceFootnoteLink()
    // footnote contents can be markdown itself, so parse it
    val footnote = markwon.toMarkdown(content)
    addFootnote(footnote)
  }
}
  1. find all footnote links in text [^1]
  2. check if those have footnote content [^1]: **Footnote** content
  3. exclude those from being parsed (but still be referenced after parsing, important thing to decide on)
  4. find a way to display footnote and handle clicks on it (or other way of handling them altogether)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Insert footnotes and endnotes - Microsoft Support
Insert footnotes and endnotes · Click where you want to reference to the footnote or endnote. · On the References tab, select Insert...
Read more >
ii.com: Links and Footnotes in Markdown - Infinite Ink
All flavors of Markdown support by-reference links, but only some support footnotes. I'll use the Markdown source code of this article to test...
Read more >
Footnotes now supported in Markdown fields - The GitHub Blog
You can now use footnote syntax in any Markdown field! Footnotes are displayed as superscript links. Click them to jump to their referenced ......
Read more >
Support footnote return links · Issue #40 · yuin/goldmark - GitHub
As mentioned in gohugoio/hugo/issues/6551 Goldmark seems to not support footnote return links although they are supported by PHP Markdown ...
Read more >
Creating footnotes in WORD - Chicago Manual of Style and ...
2.Click the References tab. · 3.In the Footnotes group, choose Insert Footnote. This inserts the superscript number in the text and then moves...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found