-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Previously, the footer (if footnote definitions were found) showed all footnote definitions, in definition order. Even footnote definitions with the same identifier were transformed to multiple definitions. remarkjs/remark-rehype#11 shows that definition order does not make sense if inline footnotes (`[^Some text]`) are used in combination with footnote references (`[^id]`) and footnote definitions (`[^id]: Some text`). Investigating this, I came to the conclusion that it also does not make sense to output all definitions, whether they are used (or even duplicate) or not. Instead, it makes sense to track the order in which footnotes are used (first), and only output a definition for the used inline footnotes / footnote references, in the order they were used. This is in line with how link definitions are used as well. Closes remarkjs/remark-rehype#11. Closes GH-32.
- Loading branch information
Showing
7 changed files
with
195 additions
and
31 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,91 @@ | ||
'use strict' | ||
|
||
var test = require('tape') | ||
var u = require('unist-builder') | ||
var to = require('..') | ||
|
||
test('Footnote', function(t) { | ||
var mdast = to( | ||
u('root', [ | ||
u('paragraph', [ | ||
u('text', 'Alpha'), | ||
u('footnote', [u('text', 'Charlie')]) | ||
]), | ||
u('paragraph', [ | ||
u('text', 'Bravo'), | ||
u('footnoteReference', {identifier: 'x'}) | ||
]), | ||
u('footnoteDefinition', {identifier: 'x'}, [ | ||
u('paragraph', [u('text', 'Delta')]) | ||
]) | ||
]) | ||
) | ||
|
||
var hast = u('root', [ | ||
u('element', {tagName: 'p', properties: {}}, [ | ||
u('text', 'Alpha'), | ||
u('element', {tagName: 'sup', properties: {id: 'fnref-1'}}, [ | ||
u( | ||
'element', | ||
{ | ||
tagName: 'a', | ||
properties: {href: '#fn-1', className: ['footnote-ref']} | ||
}, | ||
[u('text', '1')] | ||
) | ||
]) | ||
]), | ||
u('text', '\n'), | ||
u('element', {tagName: 'p', properties: {}}, [ | ||
u('text', 'Bravo'), | ||
u('element', {tagName: 'sup', properties: {id: 'fnref-x'}}, [ | ||
u( | ||
'element', | ||
{ | ||
tagName: 'a', | ||
properties: {href: '#fn-x', className: ['footnote-ref']} | ||
}, | ||
[u('text', 'x')] | ||
) | ||
]) | ||
]), | ||
u('text', '\n'), | ||
u('element', {tagName: 'div', properties: {className: ['footnotes']}}, [ | ||
u('text', '\n'), | ||
u('element', {tagName: 'hr', properties: {}}, []), | ||
u('text', '\n'), | ||
u('element', {tagName: 'ol', properties: {}}, [ | ||
u('text', '\n'), | ||
u('element', {tagName: 'li', properties: {id: 'fn-1'}}, [ | ||
u('text', 'Charlie'), | ||
u( | ||
'element', | ||
{ | ||
tagName: 'a', | ||
properties: {href: '#fnref-1', className: ['footnote-backref']} | ||
}, | ||
[u('text', '↩')] | ||
) | ||
]), | ||
u('text', '\n'), | ||
u('element', {tagName: 'li', properties: {id: 'fn-x'}}, [ | ||
u('text', 'Delta'), | ||
u( | ||
'element', | ||
{ | ||
tagName: 'a', | ||
properties: {href: '#fnref-x', className: ['footnote-backref']} | ||
}, | ||
[u('text', '↩')] | ||
) | ||
]), | ||
u('text', '\n') | ||
]), | ||
u('text', '\n') | ||
]) | ||
]) | ||
|
||
t.deepEqual(mdast, hast, 'should order the footnote section by usage') | ||
|
||
t.end() | ||
}) |
This file contains 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