🎉 initiate project *astro_rewrite*
This commit is contained in:
parent
ffd4d5e86c
commit
2ba37bfbe3
8658 changed files with 2268794 additions and 2538 deletions
64
node_modules/mdast-util-to-hast/lib/handlers/footnote-reference.js
generated
vendored
Normal file
64
node_modules/mdast-util-to-hast/lib/handlers/footnote-reference.js
generated
vendored
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/**
|
||||
* @typedef {import('mdast').FootnoteReference} FootnoteReference
|
||||
* @typedef {import('hast').Element} Element
|
||||
* @typedef {import('../state.js').State} State
|
||||
*/
|
||||
|
||||
import {normalizeUri} from 'micromark-util-sanitize-uri'
|
||||
|
||||
/**
|
||||
* Turn an mdast `footnoteReference` node into hast.
|
||||
*
|
||||
* @param {State} state
|
||||
* Info passed around.
|
||||
* @param {FootnoteReference} node
|
||||
* mdast node.
|
||||
* @returns {Element}
|
||||
* hast node.
|
||||
*/
|
||||
export function footnoteReference(state, node) {
|
||||
const id = String(node.identifier).toUpperCase()
|
||||
const safeId = normalizeUri(id.toLowerCase())
|
||||
const index = state.footnoteOrder.indexOf(id)
|
||||
/** @type {number} */
|
||||
let counter
|
||||
|
||||
if (index === -1) {
|
||||
state.footnoteOrder.push(id)
|
||||
state.footnoteCounts[id] = 1
|
||||
counter = state.footnoteOrder.length
|
||||
} else {
|
||||
state.footnoteCounts[id]++
|
||||
counter = index + 1
|
||||
}
|
||||
|
||||
const reuseCounter = state.footnoteCounts[id]
|
||||
|
||||
/** @type {Element} */
|
||||
const link = {
|
||||
type: 'element',
|
||||
tagName: 'a',
|
||||
properties: {
|
||||
href: '#' + state.clobberPrefix + 'fn-' + safeId,
|
||||
id:
|
||||
state.clobberPrefix +
|
||||
'fnref-' +
|
||||
safeId +
|
||||
(reuseCounter > 1 ? '-' + reuseCounter : ''),
|
||||
dataFootnoteRef: true,
|
||||
ariaDescribedBy: ['footnote-label']
|
||||
},
|
||||
children: [{type: 'text', value: String(counter)}]
|
||||
}
|
||||
state.patch(node, link)
|
||||
|
||||
/** @type {Element} */
|
||||
const sup = {
|
||||
type: 'element',
|
||||
tagName: 'sup',
|
||||
properties: {},
|
||||
children: [link]
|
||||
}
|
||||
state.patch(node, sup)
|
||||
return state.applyData(node, sup)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue