Skip to content

Commit

Permalink
Fix footnote keys such as constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Feb 3, 2023
1 parent ed45ec4 commit 0c67e83
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ export function footer(state) {
let index = -1

while (++index < state.footnoteOrder.length) {
const def = state.footnoteById[state.footnoteOrder[index].toUpperCase()]
const def = state.footnoteById[state.footnoteOrder[index]]

if (!def) {
continue
}

const content = state.all(def)
const id = String(def.identifier)
const id = String(def.identifier).toUpperCase()
const safeId = normalizeUri(id.toLowerCase())
let referenceIndex = 0
/** @type {Array<ElementContent>} */
Expand Down
2 changes: 1 addition & 1 deletion lib/handlers/footnote-reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {normalizeUri} from 'micromark-util-sanitize-uri'
* hast node.
*/
export function footnoteReference(state, node) {
const id = String(node.identifier)
const id = String(node.identifier).toUpperCase()
const safeId = normalizeUri(id.toLowerCase())
const index = state.footnoteOrder.indexOf(id)
/** @type {number} */
Expand Down
26 changes: 26 additions & 0 deletions test/footnote.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,30 @@ test('footnote', () => {
</section>`,
'should support a `footnoteLabelProperties`'
)

tree = toHast(
fromMarkdown(
'a[^__proto__] b[^__proto__] c[^constructor]\n\n[^__proto__]: d\n[^constructor]: e',
{
extensions: [gfm()],
mdastExtensions: [gfmFromMarkdown()]
}
)
)
assert(tree, 'expected node')
assert.equal(
toHtml(tree),
`<p>a<sup><a href="#user-content-fn-__proto__" id="user-content-fnref-__proto__" data-footnote-ref aria-describedby="footnote-label">1</a></sup> b<sup><a href="#user-content-fn-__proto__" id="user-content-fnref-__proto__-2" data-footnote-ref aria-describedby="footnote-label">1</a></sup> c<sup><a href="#user-content-fn-constructor" id="user-content-fnref-constructor" data-footnote-ref aria-describedby="footnote-label">2</a></sup></p>
<section data-footnotes class="footnotes"><h2 class="sr-only" id="footnote-label">Footnotes</h2>
<ol>
<li id="user-content-fn-__proto__">
<p>d <a href="#user-content-fnref-__proto__" data-footnote-backref class="data-footnote-backref" aria-label="Back to content">↩</a> <a href="#user-content-fnref-__proto__-2" data-footnote-backref class="data-footnote-backref" aria-label="Back to content">↩<sup>2</sup></a></p>
</li>
<li id="user-content-fn-constructor">
<p>e <a href="#user-content-fnref-constructor" data-footnote-backref class="data-footnote-backref" aria-label="Back to content">↩</a></p>
</li>
</ol>
</section>`,
'should support funky footnote identifiers'
)
})

0 comments on commit 0c67e83

Please sign in to comment.