Skip to content

Commit 0c67e83

Browse files
committed
Fix footnote keys such as constructor
1 parent ed45ec4 commit 0c67e83

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

lib/footer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ export function footer(state) {
2121
let index = -1
2222

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

2626
if (!def) {
2727
continue
2828
}
2929

3030
const content = state.all(def)
31-
const id = String(def.identifier)
31+
const id = String(def.identifier).toUpperCase()
3232
const safeId = normalizeUri(id.toLowerCase())
3333
let referenceIndex = 0
3434
/** @type {Array<ElementContent>} */

lib/handlers/footnote-reference.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {normalizeUri} from 'micromark-util-sanitize-uri'
1717
* hast node.
1818
*/
1919
export function footnoteReference(state, node) {
20-
const id = String(node.identifier)
20+
const id = String(node.identifier).toUpperCase()
2121
const safeId = normalizeUri(id.toLowerCase())
2222
const index = state.footnoteOrder.indexOf(id)
2323
/** @type {number} */

test/footnote.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,4 +278,30 @@ test('footnote', () => {
278278
</section>`,
279279
'should support a `footnoteLabelProperties`'
280280
)
281+
282+
tree = toHast(
283+
fromMarkdown(
284+
'a[^__proto__] b[^__proto__] c[^constructor]\n\n[^__proto__]: d\n[^constructor]: e',
285+
{
286+
extensions: [gfm()],
287+
mdastExtensions: [gfmFromMarkdown()]
288+
}
289+
)
290+
)
291+
assert(tree, 'expected node')
292+
assert.equal(
293+
toHtml(tree),
294+
`<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>
295+
<section data-footnotes class="footnotes"><h2 class="sr-only" id="footnote-label">Footnotes</h2>
296+
<ol>
297+
<li id="user-content-fn-__proto__">
298+
<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>
299+
</li>
300+
<li id="user-content-fn-constructor">
301+
<p>e <a href="#user-content-fnref-constructor" data-footnote-backref class="data-footnote-backref" aria-label="Back to content">↩</a></p>
302+
</li>
303+
</ol>
304+
</section>`,
305+
'should support funky footnote identifiers'
306+
)
281307
})

0 commit comments

Comments
 (0)