Maintain order of appearance in footnotes#536
Merged
nicholasserra merged 2 commits intotrentm:masterfrom Nov 21, 2023
Merged
Conversation
Collaborator
|
Nice, thank you! |
|
Hello! import markdown2
print(f'Markdown Version: {markdown2.__version__}')
print('-----')
MD = """
aboba [^1]
biba [^2]
boba [^3]
- 1
- 1.1 [^4]
- 2
- 2.1 [^5]
- 3
- 3.1 [^6]
[^1]: aboba
[^2]: biba
[^3]: boba
[^4]: 1.1
[^5]: 2.1
[^6]: 3.1
"""
extensions = ["footnotes", "tables", 'cuddled-lists']
extension_configs = {}
print(markdown2.markdown(MD, extras=extensions))and result is Markdown Version: 2.5.1
-----
<p>aboba <sup class="footnote-ref" id="fnref-1"><a href="#fn-1">4</a></sup>
biba <sup class="footnote-ref" id="fnref-2"><a href="#fn-2">5</a></sup>
boba <sup class="footnote-ref" id="fnref-3"><a href="#fn-3">6</a></sup></p>
<ul>
<li><p>1</p>
<ul>
<li>1.1 <sup class="footnote-ref" id="fnref-4"><a href="#fn-4">1</a></sup></li>
</ul></li>
<li><p>2</p>
<ul>
<li>2.1 <sup class="footnote-ref" id="fnref-5"><a href="#fn-5">2</a></sup></li>
</ul></li>
<li><p>3</p>
<ul>
<li>3.1 <sup class="footnote-ref" id="fnref-6"><a href="#fn-6">3</a></sup></li>
</ul></li>
</ul>
<div class="footnotes">
<hr />
<ol>
<li id="fn-1">
<p>aboba <a href="#fnref-1" class="footnoteBackLink" title="Jump back to footnote 1 in the text.">↩</a></p>
</li>
<li id="fn-2">
<p>biba <a href="#fnref-2" class="footnoteBackLink" title="Jump back to footnote 2 in the text.">↩</a></p>
</li>
<li id="fn-3">
<p>boba <a href="#fnref-3" class="footnoteBackLink" title="Jump back to footnote 3 in the text.">↩</a></p>
</li>
<li id="fn-4">
<p>1.1 <a href="#fnref-4" class="footnoteBackLink" title="Jump back to footnote 4 in the text.">↩</a></p>
</li>
<li id="fn-5">
<p>2.1 <a href="#fnref-5" class="footnoteBackLink" title="Jump back to footnote 5 in the text.">↩</a></p>
</li>
<li id="fn-6">
<p>3.1 <a href="#fnref-6" class="footnoteBackLink" title="Jump back to footnote 6 in the text.">↩</a></p>
</li>
</ol>
</div> |
Contributor
Author
nicholasserra
added a commit
that referenced
this pull request
Dec 7, 2024
Fix footnote labels appearing out-of-order (#536)
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 closes #533 by making sure footnotes maintain their order of appearance in the final HTML.
Previously, the order of the final footnotes list was based on the insertion order of
footnote_ids. This array was populated as the parser processed the text and encountered footnotes. The problem is that markdown isn't processed entirely in order, leading to a disorganised footnotes list being generated.This PR changes this by instead using the insertion order of
footnotes, which is populated at the beginning of the conversion process by_strip_footnote_definitions.The result is that the generated list of footnotes will appear in the same order as the footnote definitions.