-
Notifications
You must be signed in to change notification settings - Fork 882
Fix footnote ordering #1546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
aeskildsen
wants to merge
6
commits into
Python-Markdown:master
Choose a base branch
from
aeskildsen:footnotes-order
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Fix footnote ordering #1546
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d7203c9
Fix footnote ordering so footnotes are listed in the order in which t…
aeskildsen 1d13ae4
Minor fixes for work on footnotes extension
aeskildsen a6d1e0f
Add comprehensive tests for footnotes extension
aeskildsen 9547ade
Merge remote-tracking branch 'upstream/master' into footnotes-order
aeskildsen 0c2e4bf
Rework new tests for footnote extension
aeskildsen ce45459
Add tricky edge case that messes with the reordering introduced in d7…
aeskildsen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -336,3 +336,220 @@ def test_superscript_text(self): | |
'</div>', | ||
extension_configs={'footnotes': {'SUPERSCRIPT_TEXT': '[{}]'}} | ||
) | ||
|
||
def test_footnote_order(self): | ||
"""Test that footnotes occur in order of reference appearance.""" | ||
|
||
self.assertMarkdownRenders( | ||
'First footnote reference[^first]. Second footnote reference[^last].\n\n' | ||
'[^last]: Second footnote.\n[^first]: First footnote.', | ||
'<p>First footnote reference<sup id="fnref:first"><a class="footnote-ref" ' | ||
'href="#fn:first">1</a></sup>. Second footnote reference<sup id="fnref:last">' | ||
'<a class="footnote-ref" href="#fn:last">2</a></sup>.</p>\n' | ||
'<div class="footnote">\n' | ||
'<hr />\n' | ||
'<ol>\n' | ||
'<li id="fn:first">\n' | ||
'<p>First footnote. <a class="footnote-backref" href="#fnref:first" ' | ||
'title="Jump back to footnote 1 in the text">↩</a></p>\n' | ||
'</li>\n' | ||
'<li id="fn:last">\n' | ||
'<p>Second footnote. <a class="footnote-backref" href="#fnref:last" ' | ||
'title="Jump back to footnote 2 in the text">↩</a></p>\n' | ||
'</li>\n' | ||
'</ol>\n' | ||
'</div>' | ||
) | ||
|
||
def test_footnote_order_tricky(self): | ||
"""Test that tricky sequence of footnote references.""" | ||
|
||
self.assertMarkdownRenders( | ||
'`Footnote reference in code spans should be ignored[^tricky]`. ' | ||
'A footnote reference[^ordinary]. ' | ||
'Another footnote reference[^tricky].\n\n' | ||
'[^ordinary]: This should be the first footnote.\n' | ||
'[^tricky]: This should be the second footnote.', | ||
'<p><code>Footnote reference in code spans should be ignored[^tricky]</code>. ' | ||
'A footnote reference<sup id="fnref:ordinary"><a class="footnote-ref" ' | ||
'href="#fn:ordinary">1</a></sup>. Another footnote reference<sup id="fnref:tricky">' | ||
'<a class="footnote-ref" href="#fn:tricky">2</a></sup>.</p>\n' | ||
'<div class="footnote">\n' | ||
'<hr />\n' | ||
'<ol>\n' | ||
'<li id="fn:ordinary">\n' | ||
'<p>This should be the first footnote. <a class="footnote-backref" ' | ||
'href="#fnref:ordinary" title="Jump back to footnote 1 in the text">↩</a></p>\n' | ||
'</li>\n' | ||
'<li id="fn:tricky">\n' | ||
'<p>This should be the second footnote. <a class="footnote-backref" ' | ||
'href="#fnref:tricky" title="Jump back to footnote 2 in the text">↩</a></p>\n' | ||
'</li>\n' | ||
'</ol>\n' | ||
'</div>' | ||
) | ||
|
||
def test_footnote_reference_within_code_span(self): | ||
"""Test footnote reference within a code span.""" | ||
|
||
self.assertMarkdownRenders( | ||
'A `code span with a footnote[^1] reference`.', | ||
'<p>A <code>code span with a footnote[^1] reference</code>.</p>' | ||
) | ||
|
||
def test_footnote_reference_within_link(self): | ||
"""Test footnote reference within a link.""" | ||
|
||
self.assertMarkdownRenders( | ||
'A [link with a footnote[^1] reference](http://example.com).', | ||
'<p>A <a href="http://example.com">link with a footnote[^1] reference</a>.</p>' | ||
) | ||
|
||
def test_footnote_reference_within_footnote_definition(self): | ||
"""Test footnote definition containing another footnote reference.""" | ||
|
||
self.assertMarkdownRenders( | ||
'Main footnote[^main].\n\n' | ||
'[^main]: This footnote references another[^nested].\n' | ||
'[^nested]: Nested footnote.', | ||
'<p>Main footnote<sup id="fnref:main"><a class="footnote-ref" href="#fn:main">1</a></sup>.</p>\n' | ||
'<div class="footnote">\n' | ||
'<hr />\n' | ||
'<ol>\n' | ||
'<li id="fn:main">\n' | ||
'<p>This footnote references another<sup id="fnref:nested"><a class="footnote-ref" ' | ||
'href="#fn:nested">2</a></sup>. <a class="footnote-backref" href="#fnref:main" ' | ||
'title="Jump back to footnote 1 in the text">↩</a></p>\n' | ||
'</li>\n' | ||
'<li id="fn:nested">\n' | ||
'<p>Nested footnote. <a class="footnote-backref" href="#fnref:nested" ' | ||
'title="Jump back to footnote 2 in the text">↩</a></p>\n' | ||
'</li>\n' | ||
'</ol>\n' | ||
'</div>' | ||
) | ||
|
||
def test_footnote_reference_within_blockquote(self): | ||
"""Test footnote reference within a blockquote.""" | ||
|
||
self.assertMarkdownRenders( | ||
'> This is a quote with a footnote[^quote].\n\n[^quote]: Quote footnote.', | ||
'<blockquote>\n' | ||
'<p>This is a quote with a footnote<sup id="fnref:quote">' | ||
'<a class="footnote-ref" href="#fn:quote">1</a></sup>.</p>\n' | ||
'</blockquote>\n' | ||
'<div class="footnote">\n' | ||
'<hr />\n' | ||
'<ol>\n' | ||
'<li id="fn:quote">\n' | ||
'<p>Quote footnote. <a class="footnote-backref" href="#fnref:quote" ' | ||
'title="Jump back to footnote 1 in the text">↩</a></p>\n' | ||
'</li>\n' | ||
'</ol>\n' | ||
'</div>' | ||
) | ||
|
||
def test_footnote_reference_within_list(self): | ||
"""Test footnote reference within a list item.""" | ||
|
||
self.assertMarkdownRenders( | ||
'1. First item with footnote[^note]\n1. Second item\n\n[^note]: List footnote.', | ||
'<ol>\n' | ||
'<li>First item with footnote<sup id="fnref:note">' | ||
'<a class="footnote-ref" href="#fn:note">1</a></sup></li>\n' | ||
'<li>Second item</li>\n' | ||
'</ol>\n' | ||
'<div class="footnote">\n' | ||
'<hr />\n' | ||
'<ol>\n' | ||
'<li id="fn:note">\n' | ||
'<p>List footnote. <a class="footnote-backref" href="#fnref:note" ' | ||
'title="Jump back to footnote 1 in the text">↩</a></p>\n' | ||
'</li>\n' | ||
'</ol>\n' | ||
'</div>' | ||
) | ||
|
||
def test_footnote_reference_within_html(self): | ||
"""Test footnote reference within HTML tags.""" | ||
|
||
self.assertMarkdownRenders( | ||
'A <span>footnote reference[^1] within a span element</span>.\n\n[^1]: The footnote.', | ||
'<p>A <span>footnote reference<sup id="fnref:1">' | ||
'<a class="footnote-ref" href="#fn:1">1</a>' | ||
'</sup> within a span element</span>.</p>\n' | ||
'<div class="footnote">\n' | ||
'<hr />\n' | ||
'<ol>\n' | ||
'<li id="fn:1">\n' | ||
'<p>The footnote. <a class="footnote-backref" href="#fnref:1" ' | ||
'title="Jump back to footnote 1 in the text">↩</a></p>\n' | ||
'</li>\n' | ||
'</ol>\n' | ||
'</div>' | ||
) | ||
Comment on lines
+392
to
+490
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These test parsing of footnote references within other structures. |
||
|
||
def test_duplicate_footnote_references(self): | ||
"""Test multiple references to the same footnote.""" | ||
|
||
self.assertMarkdownRenders( | ||
'First[^dup] and second[^dup] reference.\n\n[^dup]: Duplicate footnote.', | ||
'<p>First<sup id="fnref:dup">' | ||
'<a class="footnote-ref" href="#fn:dup">1</a></sup> and second<sup id="fnref2:dup">' | ||
'<a class="footnote-ref" href="#fn:dup">1</a></sup> reference.</p>\n' | ||
'<div class="footnote">\n' | ||
'<hr />\n' | ||
'<ol>\n' | ||
'<li id="fn:dup">\n' | ||
'<p>Duplicate footnote. ' | ||
'<a class="footnote-backref" href="#fnref:dup" ' | ||
'title="Jump back to footnote 1 in the text">↩</a>' | ||
'<a class="footnote-backref" href="#fnref2:dup" ' | ||
'title="Jump back to footnote 1 in the text">↩</a></p>\n' | ||
'</li>\n' | ||
'</ol>\n' | ||
'</div>' | ||
) | ||
|
||
def test_footnote_reference_without_definition(self): | ||
"""Test footnote reference without corresponding definition.""" | ||
|
||
self.assertMarkdownRenders( | ||
'This has a missing footnote[^missing].', | ||
'<p>This has a missing footnote[^missing].</p>' | ||
) | ||
|
||
def test_footnote_definition_without_reference(self): | ||
"""Test footnote definition without corresponding reference.""" | ||
|
||
self.assertMarkdownRenders( | ||
'No reference here.\n\n[^orphan]: Orphaned footnote.', | ||
'<p>No reference here.</p>\n' | ||
'<div class="footnote">\n' | ||
'<hr />\n' | ||
'<ol>\n' | ||
'<li id="fn:orphan">\n' | ||
'<p>Orphaned footnote. <a class="footnote-backref" href="#fnref:orphan" ' | ||
'title="Jump back to footnote 1 in the text">↩</a></p>\n' | ||
'</li>\n' | ||
'</ol>\n' | ||
'</div>' | ||
) | ||
|
||
def test_footnote_id_with_special_chars(self): | ||
"""Test footnote id containing special and Unicode characters.""" | ||
|
||
self.assertMarkdownRenders( | ||
'Special footnote id[^!#¤%/()=?+}{§øé].\n\n[^!#¤%/()=?+}{§øé]: The footnote.', | ||
'<p>Special footnote id<sup id="fnref:!#¤%/()=?+}{§øé">' | ||
'<a class="footnote-ref" href="#fn:!#¤%/()=?+}{§øé">1</a></sup>.</p>\n' | ||
'<div class="footnote">\n' | ||
'<hr />\n' | ||
'<ol>\n' | ||
'<li id="fn:!#¤%/()=?+}{§øé">\n' | ||
'<p>The footnote. <a class="footnote-backref" href="#fnref:!#¤%/()=?+}{§øé" ' | ||
'title="Jump back to footnote 1 in the text">↩</a></p>\n' | ||
'</li>\n' | ||
'</ol>\n' | ||
'</div>' | ||
) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tests the new behavior (footnotes ordered by reference appearence).