@mdit/plugin-footnote 1.1.1 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"cdn.umd.js","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["/** Forked from https://github.com/markdown-it/markdown-it-footnote/blob/master/index.mjs */\n\nimport type { BlockRule, CoreRule, InlineRule, PluginSimple } from \"@mdit/helper\";\nimport type { RendererRule, StateBlock, StateCore, StateInline, Token } from \"markdown-it\";\n\nimport type { FootNoteEnv, FootNoteToken } from \"./types.js\";\n\ninterface FootNoteStateBlock extends StateBlock {\n env: FootNoteEnv;\n}\n\ninterface FootNoteStateInline extends StateInline {\n env: FootNoteEnv;\n}\n\ninterface FootNoteStateCore extends StateCore {\n env: FootNoteEnv;\n}\n\ntype FootNoteMeta = FootNoteToken[\"meta\"];\n\nconst getIDSuffix = (tokens: Token[], index: number): string => {\n // add suffix when multiple id was found\n const { subId } = tokens[index].meta as FootNoteMeta;\n\n return subId > 0 ? `:${subId}` : \"\";\n};\n\nconst renderFootnoteAnchorName: RendererRule = (tokens, index, _options, env) => {\n // prefix\n const docId = env?.docId;\n // increasing id\n const id = (tokens[index].meta as FootNoteMeta).id;\n\n return `${typeof docId === \"string\" ? `-${docId}-` : \"\"}${(id + 1).toString()}`;\n};\n\nconst renderFootnoteCaption: RendererRule = (tokens: Token[], index) =>\n `[${\n // number\n ((tokens[index].meta as FootNoteMeta).id + 1).toString()\n }${getIDSuffix(tokens, index)}]`;\n\nconst renderFootnoteRef: RendererRule = (tokens, index, options, env, self) => {\n const id = self.rules.footnote_anchor_name(tokens, index, options, env, self);\n const caption = self.rules.footnote_caption(tokens, index, options, env, self);\n\n // A separate anchor element allows scroll offset control via CSS\n // (e.g. `.footnote-anchor { scroll-margin-top: 80px; }` to leave\n // space for a fixed navbar), which isn't possible when id and href\n // share the same <a> element.\n return `<sup class=\"footnote-ref\"><a href=\"#footnote${id}\">${caption}</a><a class=\"footnote-anchor\" id=\"footnote-ref${id}${getIDSuffix(\n tokens,\n index,\n )}\"></a></sup>`;\n};\n\nconst renderFootnoteBlockOpen: RendererRule = (_tokens, _index, options) =>\n `\\\n<hr class=\"footnotes-sep\"${options.xhtmlOut ? \" /\" : \"\"}>\n<section class=\"footnotes\">\n<ol class=\"footnotes-list\">\n`;\n\nconst renderFootnoteBlockClose = (): string => `\\\n</ol>\n</section>\n`;\n\nconst renderFootnoteOpen: RendererRule = (tokens, index, options, env, self) =>\n `<li id=\"footnote${self.rules.footnote_anchor_name(\n tokens,\n index,\n options,\n env,\n self,\n )}${getIDSuffix(tokens, index)}\" class=\"footnote-item\">`;\n\nconst renderFootnoteClose: RendererRule = () => \"</li>\\n\";\n\nconst renderFootnoteAnchor: RendererRule = (tokens, index, options, env, self) =>\n ` <a href=\"#footnote-ref${self.rules.footnote_anchor_name(tokens, index, options, env, self)}${\n getIDSuffix(tokens, index)\n /* ↩ with escape code to prevent display as Apple Emoji on iOS */\n }\" class=\"footnote-backref\">\\u21A9\\uFE0E</a>`;\n\n// Process footnote block definition\nconst footnoteDef: BlockRule = (state: FootNoteStateBlock, startLine, endLine, silent) => {\n const start = state.bMarks[startLine] + state.tShift[startLine];\n const max = state.eMarks[startLine];\n let charCode: number;\n\n if (\n // line should be at least 5 chars - \"[^x]:\"\n start + 4 > max ||\n state.src.charCodeAt(start) !== 91 /* [ */ ||\n state.src.charCodeAt(start + 1) !== 94 /* ^ */\n )\n return false;\n\n let pos = start + 2;\n\n while (pos < max) {\n charCode = state.src.charCodeAt(pos);\n if (charCode === 32 /* space */) return false;\n\n if (charCode === 93 /* ] */) break;\n\n pos++;\n }\n\n if (\n // empty footnote label\n pos === start + 2 ||\n pos + 1 >= max ||\n state.src.charCodeAt(++pos) !== 58 /* : */\n )\n return false;\n\n if (silent) return true;\n\n pos++;\n\n (state.env.footnotes ??= {}).refs ??= {};\n\n const label = state.src.slice(start + 2, pos - 2);\n\n state.env.footnotes.refs[`:${label}`] = -1;\n\n const referenceOpenToken = state.push(\"footnote_reference_open\", \"\", 1);\n\n referenceOpenToken.meta = { label };\n referenceOpenToken.level = state.level++;\n\n const oldBMark = state.bMarks[startLine];\n const oldTShift = state.tShift[startLine];\n const oldSCount = state.sCount[startLine];\n const oldParentType = state.parentType;\n const posAfterColon = pos;\n const initial =\n state.sCount[startLine] + pos - (state.bMarks[startLine] + state.tShift[startLine]);\n\n let offset = initial;\n\n while (pos < max) {\n charCode = state.src.charCodeAt(pos);\n\n if (charCode === 9 /* \\t */) offset += 4 - (offset % 4);\n else if (charCode === 32 /* space */) offset++;\n else break;\n\n pos++;\n }\n\n state.tShift[startLine] = pos - posAfterColon;\n state.sCount[startLine] = offset - initial;\n state.bMarks[startLine] = posAfterColon;\n state.blkIndent += 4;\n state.parentType = \"footnote\";\n\n if (state.sCount[startLine] < state.blkIndent) state.sCount[startLine] += state.blkIndent;\n\n state.md.block.tokenize(state, startLine, endLine);\n\n state.parentType = oldParentType;\n state.blkIndent -= 4;\n state.tShift[startLine] = oldTShift;\n state.sCount[startLine] = oldSCount;\n state.bMarks[startLine] = oldBMark;\n\n const referenceCloseToken = state.push(\"footnote_reference_close\", \"\", -1);\n\n referenceCloseToken.level = --state.level;\n\n return true;\n};\n\n// Process inline footnotes (^[...])\nconst footnoteInline: InlineRule = (state: FootNoteStateInline, silent) => {\n const max = state.posMax;\n const start = state.pos;\n\n if (\n start + 2 >= max ||\n state.src.charCodeAt(start) !== 94 /* ^ */ ||\n state.src.charCodeAt(start + 1) !== 91 /* [ */\n )\n return false;\n\n const labelEnd = state.md.helpers.parseLinkLabel(state, start + 1);\n\n // parser failed to find ']', so it’s not a valid note\n if (labelEnd < 0) return false;\n\n const labelStart = start + 2;\n\n /*\n * We found the end of the link, and know for a fact it’s a valid link;\n * so all that’s left to do is to call tokenizer.\n *\n */\n // silent mode is hard to trigger with standard syntax\n // this is more like a guard to prevent run tokenizer in silent mode\n if (!silent) {\n const list = ((state.env.footnotes ??= {}).list ??= []);\n const footnoteId = list.length;\n const tokens: Token[] = [];\n\n state.md.inline.parse(state.src.slice(labelStart, labelEnd), state.md, state.env, tokens);\n\n const refToken = state.push(\"footnote_ref\", \"\", 0);\n\n refToken.meta = { id: footnoteId };\n\n state.env.footnotes.list[footnoteId] = {\n content: state.src.slice(labelStart, labelEnd),\n tokens,\n };\n }\n\n state.pos = labelEnd + 1;\n state.posMax = max;\n\n return true;\n};\n\n// Process footnote references ([^...])\nconst footnoteRef: InlineRule = (state: FootNoteStateInline, silent) => {\n const start = state.pos;\n const max = state.posMax;\n\n if (\n // should be at least 4 chars - \"[^x]\"\n start + 3 > max ||\n !state.env.footnotes?.refs ||\n state.src.charCodeAt(start) !== 91 /* [ */ ||\n state.src.charCodeAt(start + 1) !== 94 /* ^ */\n )\n return false;\n\n let pos = start + 2;\n let charCode: number;\n\n while (pos < max) {\n charCode = state.src.charCodeAt(pos);\n if (charCode === 32 /* space */ || charCode === 10 /* \\n */) return false;\n\n if (charCode === 93 /* ] */) break;\n\n pos++;\n }\n\n // empty footnote labels\n if (pos === start + 2 || pos >= max) return false;\n\n pos++;\n\n const label = state.src.slice(start + 2, pos - 1);\n\n if (typeof state.env.footnotes.refs[`:${label}`] !== \"number\") return false;\n\n // silent mode is hard to trigger with standard syntax\n // this is more like a guard to prevent run tokenizer in silent mode\n if (!silent) {\n const list = (state.env.footnotes.list ??= []);\n const { refs } = state.env.footnotes;\n let footnoteId: number;\n\n if (refs[`:${label}`] < 0) {\n footnoteId = list.length;\n list[footnoteId] = { label, count: 0 };\n refs[`:${label}`] = footnoteId;\n } else {\n footnoteId = refs[`:${label}`];\n }\n\n // oxlint-disable-next-line typescript/no-non-null-assertion\n const subId = list[footnoteId].count!;\n\n // oxlint-disable-next-line typescript/no-non-null-assertion\n list[footnoteId].count! += 1;\n\n const refToken = state.push(\"footnote_ref\", \"\", 0);\n\n refToken.meta = { id: footnoteId, subId, label };\n }\n\n state.pos = pos;\n state.posMax = max;\n\n return true;\n};\n\n// Glue footnote tokens to end of token stream\nconst footnoteTail: CoreRule = (state: FootNoteStateCore) => {\n const refTokens: Record<string, Token[]> = {};\n\n let current: Token[], currentLabel: string;\n let isInsideRef = false;\n\n if (!state.env.footnotes?.list) {\n // If no footnotes list, remove all footnote reference tokens\n state.tokens = state.tokens.filter((stateToken) => {\n if (stateToken.type === \"footnote_reference_open\") {\n isInsideRef = true;\n\n return false;\n }\n\n if (stateToken.type === \"footnote_reference_close\") {\n isInsideRef = false;\n\n return false;\n }\n\n return !isInsideRef;\n });\n\n return;\n }\n\n const { list } = state.env.footnotes;\n\n state.tokens = state.tokens.filter((stateToken) => {\n if (stateToken.type === \"footnote_reference_open\") {\n isInsideRef = true;\n current = [];\n currentLabel = (stateToken.meta as { label: string }).label;\n\n return false;\n }\n\n if (stateToken.type === \"footnote_reference_close\") {\n isInsideRef = false;\n // prepend ':' to avoid conflict with Object.prototype members\n refTokens[`:${currentLabel}`] = current;\n\n return false;\n }\n if (isInsideRef) current.push(stateToken);\n\n return !isInsideRef;\n });\n\n const footnoteBlockOpenToken = new state.Token(\"footnote_block_open\", \"\", 1);\n\n state.tokens.push(footnoteBlockOpenToken);\n\n const listLength = list.length;\n\n for (let index = 0; index < listLength; index++) {\n const footnoteOpenToken = new state.Token(\"footnote_open\", \"\", 1);\n\n footnoteOpenToken.meta = { id: index, label: list[index].label };\n state.tokens.push(footnoteOpenToken);\n\n if (list[index].tokens) {\n const paragraphOpenToken = new state.Token(\"paragraph_open\", \"p\", 1);\n\n paragraphOpenToken.block = true;\n\n const inlineToken = new state.Token(\"inline\", \"\", 0);\n\n // oxlint-disable-next-line typescript/no-non-null-assertion\n inlineToken.children = list[index].tokens!;\n // oxlint-disable-next-line typescript/no-non-null-assertion\n inlineToken.content = list[index].content!;\n\n const paragraphCloseToken = new state.Token(\"paragraph_close\", \"p\", -1);\n\n paragraphCloseToken.block = true;\n\n state.tokens.push(paragraphOpenToken, inlineToken, paragraphCloseToken);\n } else {\n // oxlint-disable-next-line typescript/no-non-null-assertion\n const tokens = refTokens[`:${list[index].label!}`];\n\n // oxlint-disable-next-line typescript/strict-boolean-expressions\n if (tokens) state.tokens.push(...tokens);\n }\n\n const lastParagraph =\n // oxlint-disable-next-line typescript/no-non-null-assertion\n state.tokens[state.tokens.length - 1].type === \"paragraph_close\" ? state.tokens.pop()! : null;\n\n // oxlint-disable-next-line typescript/no-non-null-assertion\n for (let j = 0; j < (Number(list[index].count) > 0 ? list[index].count! : 1); j++) {\n const footnoteAnchorToken = new state.Token(\"footnote_anchor\", \"\", 0);\n\n footnoteAnchorToken.meta = {\n id: index,\n subId: j,\n label: list[index].label,\n };\n state.tokens.push(footnoteAnchorToken);\n }\n\n if (lastParagraph) state.tokens.push(lastParagraph);\n\n state.tokens.push(new state.Token(\"footnote_close\", \"\", -1));\n }\n\n state.tokens.push(new state.Token(\"footnote_block_close\", \"\", -1));\n};\n\nexport const footnote: PluginSimple = (md) => {\n md.renderer.rules.footnote_ref = renderFootnoteRef;\n md.renderer.rules.footnote_block_open = renderFootnoteBlockOpen;\n md.renderer.rules.footnote_block_close = renderFootnoteBlockClose;\n md.renderer.rules.footnote_open = renderFootnoteOpen;\n md.renderer.rules.footnote_close = renderFootnoteClose;\n md.renderer.rules.footnote_anchor = renderFootnoteAnchor;\n\n // helpers (only used in other rules, no tokens are attached to those)\n // helpers (only used in other rules, no tokens are attached to those)\n md.renderer.rules.footnote_caption = renderFootnoteCaption;\n md.renderer.rules.footnote_anchor_name = renderFootnoteAnchorName;\n\n md.block.ruler.before(\"reference\", \"footnoteDef\", footnoteDef, {\n alt: [\"paragraph\", \"reference\"],\n });\n md.inline.ruler.after(\"image\", \"footnoteInline\", footnoteInline);\n md.inline.ruler.after(\"footnoteInline\", \"footnote_ref\", footnoteRef);\n md.core.ruler.after(\"inline\", \"footnoteTail\", footnoteTail);\n};\n"],"mappings":"0RAqBA,IAAM,GAAe,EAAiB,IAA0B,CAE9D,GAAM,CAAE,SAAU,E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D,EAAM,OAAO,KAAK,IAAI,EAAM,MAAM,iBAAkB,GAAI,EAAE,CAAC,CAC7D,CAEA,EAAM,OAAO,KAAK,IAAI,EAAM,MAAM,uBAAwB,GAAI,EAAE,CAAC,CACnE,aAEuC,GAAO,CAC5C,EAAG,SAAS,MAAM,aAAe,EACjC,EAAG,SAAS,MAAM,oBAAsB,EACxC,EAAG,SAAS,MAAM,qBAAuB,EACzC,EAAG,SAAS,MAAM,cAAgB,EAClC,EAAG,SAAS,MAAM,eAAiB,EACnC,EAAG,SAAS,MAAM,gBAAkB,EAIpC,EAAG,SAAS,MAAM,iBAAmB,EACrC,EAAG,SAAS,MAAM,qBAAuB,EAEzC,EAAG,MAAM,MAAM,OAAO,YAAa,cAAe,EAAa,CAC7D,IAAK,CAAC,YAAa,WAAW,CAChC,CAAC,EACD,EAAG,OAAO,MAAM,MAAM,QAAS,iBAAkB,CAAc,EAC/D,EAAG,OAAO,MAAM,MAAM,iBAAkB,eAAgB,CAAW,EACnE,EAAG,KAAK,MAAM,MAAM,SAAU,eAAgB,CAAY,CAC5D"}
1
+ {"version":3,"file":"cdn.umd.js","names":["factory","global","exports","getIDSuffix","tokens","index","subId","renderFootnoteAnchorName","docId","env","id","renderFootnoteCaption","renderFootnoteRef","self","options","renderFootnoteBlockOpen","renderFootnoteBlockClose","renderFootnoteOpen","renderFootnoteClose","renderFootnoteAnchor","footnoteDef","start","state","startLine","max","charCode","pos","silent","label","referenceOpenToken","oldBMark","oldTShift","oldSCount","oldParentType","posAfterColon","initial","offset","endLine","referenceCloseToken","footnoteInline","labelEnd","labelStart","footnoteId","refToken","footnoteRef","list","refs","footnoteTail","refTokens","current","currentLabel","isInsideRef","stateToken","footnoteBlockOpenToken","listLength","footnoteOpenToken","paragraphOpenToken","inlineToken","paragraphCloseToken","lastParagraph","j","footnoteAnchorToken","md"],"sources":["../src/plugin.ts"],"sourcesContent":["/** Forked from https://github.com/markdown-it/markdown-it-footnote/blob/master/index.mjs */\n\nimport type { BlockRule, CoreRule, InlineRule, PluginSimple } from \"@mdit/helper\";\nimport type { RendererRule, StateBlock, StateCore, StateInline, Token } from \"markdown-it\";\n\nimport type { FootNoteEnv, FootNoteToken } from \"./types.js\";\n\ninterface FootNoteStateBlock extends StateBlock {\n env: FootNoteEnv;\n}\n\ninterface FootNoteStateInline extends StateInline {\n env: FootNoteEnv;\n}\n\ninterface FootNoteStateCore extends StateCore {\n env: FootNoteEnv;\n}\n\ntype FootNoteMeta = FootNoteToken[\"meta\"];\n\nconst getIDSuffix = (tokens: Token[], index: number): string => {\n // add suffix when multiple id was found\n const { subId } = tokens[index].meta as FootNoteMeta;\n\n return subId > 0 ? `:${subId}` : \"\";\n};\n\nconst renderFootnoteAnchorName: RendererRule = (tokens, index, _options, env) => {\n // prefix\n const docId = env?.docId;\n // increasing id\n const id = (tokens[index].meta as FootNoteMeta).id;\n\n return `${typeof docId === \"string\" ? `-${docId}-` : \"\"}${(id + 1).toString()}`;\n};\n\nconst renderFootnoteCaption: RendererRule = (tokens: Token[], index) =>\n `[${\n // number\n ((tokens[index].meta as FootNoteMeta).id + 1).toString()\n }${getIDSuffix(tokens, index)}]`;\n\nconst renderFootnoteRef: RendererRule = (tokens, index, options, env, self) => {\n const id = self.rules.footnote_anchor_name(tokens, index, options, env, self);\n const caption = self.rules.footnote_caption(tokens, index, options, env, self);\n\n // A separate anchor element allows scroll offset control via CSS\n // (e.g. `.footnote-anchor { scroll-margin-top: 80px; }` to leave\n // space for a fixed navbar), which isn't possible when id and href\n // share the same <a> element.\n return `<sup class=\"footnote-ref\"><a href=\"#footnote${id}\">${caption}</a><a class=\"footnote-anchor\" id=\"footnote-ref${id}${getIDSuffix(\n tokens,\n index,\n )}\"></a></sup>`;\n};\n\nconst renderFootnoteBlockOpen: RendererRule = (_tokens, _index, options) =>\n `\\\n<hr class=\"footnotes-sep\"${options.xhtmlOut ? \" /\" : \"\"}>\n<section class=\"footnotes\">\n<ol class=\"footnotes-list\">\n`;\n\nconst renderFootnoteBlockClose = (): string => `\\\n</ol>\n</section>\n`;\n\nconst renderFootnoteOpen: RendererRule = (tokens, index, options, env, self) =>\n `<li id=\"footnote${self.rules.footnote_anchor_name(\n tokens,\n index,\n options,\n env,\n self,\n )}${getIDSuffix(tokens, index)}\" class=\"footnote-item\">`;\n\nconst renderFootnoteClose: RendererRule = () => \"</li>\\n\";\n\nconst renderFootnoteAnchor: RendererRule = (tokens, index, options, env, self) =>\n ` <a href=\"#footnote-ref${self.rules.footnote_anchor_name(tokens, index, options, env, self)}${\n getIDSuffix(tokens, index)\n /* ↩ with escape code to prevent display as Apple Emoji on iOS */\n }\" class=\"footnote-backref\">\\u21A9\\uFE0E</a>`;\n\n// Process footnote block definition\nconst footnoteDef: BlockRule = (state: FootNoteStateBlock, startLine, endLine, silent) => {\n const start = state.bMarks[startLine] + state.tShift[startLine];\n const max = state.eMarks[startLine];\n let charCode: number;\n\n if (\n // line should be at least 5 chars - \"[^x]:\"\n start + 4 > max ||\n state.src.charCodeAt(start) !== 91 /* [ */ ||\n state.src.charCodeAt(start + 1) !== 94 /* ^ */\n )\n return false;\n\n let pos = start + 2;\n\n while (pos < max) {\n charCode = state.src.charCodeAt(pos);\n if (charCode === 32 /* space */) return false;\n\n if (charCode === 93 /* ] */) break;\n\n pos++;\n }\n\n if (\n // empty footnote label\n pos === start + 2 ||\n pos + 1 >= max ||\n state.src.charCodeAt(++pos) !== 58 /* : */\n )\n return false;\n\n if (silent) return true;\n\n pos++;\n\n (state.env.footnotes ??= {}).refs ??= {};\n\n const label = state.src.slice(start + 2, pos - 2);\n\n state.env.footnotes.refs[`:${label}`] = -1;\n\n const referenceOpenToken = state.push(\"footnote_reference_open\", \"\", 1);\n\n referenceOpenToken.meta = { label };\n referenceOpenToken.level = state.level++;\n\n const oldBMark = state.bMarks[startLine];\n const oldTShift = state.tShift[startLine];\n const oldSCount = state.sCount[startLine];\n const oldParentType = state.parentType;\n const posAfterColon = pos;\n const initial =\n state.sCount[startLine] + pos - (state.bMarks[startLine] + state.tShift[startLine]);\n\n let offset = initial;\n\n while (pos < max) {\n charCode = state.src.charCodeAt(pos);\n\n if (charCode === 9 /* \\t */) offset += 4 - (offset % 4);\n else if (charCode === 32 /* space */) offset++;\n else break;\n\n pos++;\n }\n\n state.tShift[startLine] = pos - posAfterColon;\n state.sCount[startLine] = offset - initial;\n state.bMarks[startLine] = posAfterColon;\n state.blkIndent += 4;\n state.parentType = \"footnote\";\n\n if (state.sCount[startLine] < state.blkIndent) state.sCount[startLine] += state.blkIndent;\n\n state.md.block.tokenize(state, startLine, endLine);\n\n state.parentType = oldParentType;\n state.blkIndent -= 4;\n state.tShift[startLine] = oldTShift;\n state.sCount[startLine] = oldSCount;\n state.bMarks[startLine] = oldBMark;\n\n const referenceCloseToken = state.push(\"footnote_reference_close\", \"\", -1);\n\n referenceCloseToken.level = --state.level;\n\n return true;\n};\n\n// Process inline footnotes (^[...])\nconst footnoteInline: InlineRule = (state: FootNoteStateInline, silent) => {\n const max = state.posMax;\n const start = state.pos;\n\n if (\n start + 2 >= max ||\n state.src.charCodeAt(start) !== 94 /* ^ */ ||\n state.src.charCodeAt(start + 1) !== 91 /* [ */\n )\n return false;\n\n const labelEnd = state.md.helpers.parseLinkLabel(state, start + 1);\n\n // parser failed to find ']', so it’s not a valid note\n if (labelEnd < 0) return false;\n\n const labelStart = start + 2;\n\n /*\n * We found the end of the link, and know for a fact it’s a valid link;\n * so all that’s left to do is to call tokenizer.\n *\n */\n // silent mode is hard to trigger with standard syntax\n // this is more like a guard to prevent run tokenizer in silent mode\n if (!silent) {\n const list = ((state.env.footnotes ??= {}).list ??= []);\n const footnoteId = list.length;\n const tokens: Token[] = [];\n\n state.md.inline.parse(state.src.slice(labelStart, labelEnd), state.md, state.env, tokens);\n\n const refToken = state.push(\"footnote_ref\", \"\", 0);\n\n refToken.meta = { id: footnoteId };\n\n state.env.footnotes.list[footnoteId] = {\n content: state.src.slice(labelStart, labelEnd),\n tokens,\n };\n }\n\n state.pos = labelEnd + 1;\n state.posMax = max;\n\n return true;\n};\n\n// Process footnote references ([^...])\nconst footnoteRef: InlineRule = (state: FootNoteStateInline, silent) => {\n const start = state.pos;\n const max = state.posMax;\n\n if (\n // should be at least 4 chars - \"[^x]\"\n start + 3 > max ||\n !state.env.footnotes?.refs ||\n state.src.charCodeAt(start) !== 91 /* [ */ ||\n state.src.charCodeAt(start + 1) !== 94 /* ^ */\n )\n return false;\n\n let pos = start + 2;\n let charCode: number;\n\n while (pos < max) {\n charCode = state.src.charCodeAt(pos);\n if (charCode === 32 /* space */ || charCode === 10 /* \\n */) return false;\n\n if (charCode === 93 /* ] */) break;\n\n pos++;\n }\n\n // empty footnote labels\n if (pos === start + 2 || pos >= max) return false;\n\n pos++;\n\n const label = state.src.slice(start + 2, pos - 1);\n\n if (typeof state.env.footnotes.refs[`:${label}`] !== \"number\") return false;\n\n // silent mode is hard to trigger with standard syntax\n // this is more like a guard to prevent run tokenizer in silent mode\n if (!silent) {\n const list = (state.env.footnotes.list ??= []);\n const { refs } = state.env.footnotes;\n let footnoteId: number;\n\n if (refs[`:${label}`] < 0) {\n footnoteId = list.length;\n list[footnoteId] = { label, count: 0 };\n refs[`:${label}`] = footnoteId;\n } else {\n footnoteId = refs[`:${label}`];\n }\n\n // oxlint-disable-next-line typescript/no-non-null-assertion\n const subId = list[footnoteId].count!;\n\n // oxlint-disable-next-line typescript/no-non-null-assertion\n list[footnoteId].count! += 1;\n\n const refToken = state.push(\"footnote_ref\", \"\", 0);\n\n refToken.meta = { id: footnoteId, subId, label };\n }\n\n state.pos = pos;\n state.posMax = max;\n\n return true;\n};\n\n// Glue footnote tokens to end of token stream\nconst footnoteTail: CoreRule = (state: FootNoteStateCore) => {\n const refTokens: Record<string, Token[]> = {};\n\n let current: Token[], currentLabel: string;\n let isInsideRef = false;\n\n if (!state.env.footnotes?.list) {\n // If no footnotes list, remove all footnote reference tokens\n state.tokens = state.tokens.filter((stateToken) => {\n if (stateToken.type === \"footnote_reference_open\") {\n isInsideRef = true;\n\n return false;\n }\n\n if (stateToken.type === \"footnote_reference_close\") {\n isInsideRef = false;\n\n return false;\n }\n\n return !isInsideRef;\n });\n\n return;\n }\n\n const { list } = state.env.footnotes;\n\n state.tokens = state.tokens.filter((stateToken) => {\n if (stateToken.type === \"footnote_reference_open\") {\n isInsideRef = true;\n current = [];\n currentLabel = (stateToken.meta as { label: string }).label;\n\n return false;\n }\n\n if (stateToken.type === \"footnote_reference_close\") {\n isInsideRef = false;\n // prepend ':' to avoid conflict with Object.prototype members\n refTokens[`:${currentLabel}`] = current;\n\n return false;\n }\n if (isInsideRef) current.push(stateToken);\n\n return !isInsideRef;\n });\n\n const footnoteBlockOpenToken = new state.Token(\"footnote_block_open\", \"\", 1);\n\n state.tokens.push(footnoteBlockOpenToken);\n\n const listLength = list.length;\n\n for (let index = 0; index < listLength; index++) {\n const footnoteOpenToken = new state.Token(\"footnote_open\", \"\", 1);\n\n footnoteOpenToken.meta = { id: index, label: list[index].label };\n state.tokens.push(footnoteOpenToken);\n\n if (list[index].tokens) {\n const paragraphOpenToken = new state.Token(\"paragraph_open\", \"p\", 1);\n\n paragraphOpenToken.block = true;\n\n const inlineToken = new state.Token(\"inline\", \"\", 0);\n\n // oxlint-disable-next-line typescript/no-non-null-assertion\n inlineToken.children = list[index].tokens!;\n // oxlint-disable-next-line typescript/no-non-null-assertion\n inlineToken.content = list[index].content!;\n\n const paragraphCloseToken = new state.Token(\"paragraph_close\", \"p\", -1);\n\n paragraphCloseToken.block = true;\n\n state.tokens.push(paragraphOpenToken, inlineToken, paragraphCloseToken);\n } else {\n // oxlint-disable-next-line typescript/no-non-null-assertion\n const tokens = refTokens[`:${list[index].label!}`];\n\n // oxlint-disable-next-line typescript/strict-boolean-expressions\n if (tokens) state.tokens.push(...tokens);\n }\n\n const lastParagraph =\n // oxlint-disable-next-line typescript/no-non-null-assertion\n state.tokens[state.tokens.length - 1].type === \"paragraph_close\" ? state.tokens.pop()! : null;\n\n // oxlint-disable-next-line typescript/no-non-null-assertion\n for (let j = 0; j < (Number(list[index].count) > 0 ? list[index].count! : 1); j++) {\n const footnoteAnchorToken = new state.Token(\"footnote_anchor\", \"\", 0);\n\n footnoteAnchorToken.meta = {\n id: index,\n subId: j,\n label: list[index].label,\n };\n state.tokens.push(footnoteAnchorToken);\n }\n\n if (lastParagraph) state.tokens.push(lastParagraph);\n\n state.tokens.push(new state.Token(\"footnote_close\", \"\", -1));\n }\n\n state.tokens.push(new state.Token(\"footnote_block_close\", \"\", -1));\n};\n\nexport const footnote: PluginSimple = (md) => {\n md.renderer.rules.footnote_ref = renderFootnoteRef;\n md.renderer.rules.footnote_block_open = renderFootnoteBlockOpen;\n md.renderer.rules.footnote_block_close = renderFootnoteBlockClose;\n md.renderer.rules.footnote_open = renderFootnoteOpen;\n md.renderer.rules.footnote_close = renderFootnoteClose;\n md.renderer.rules.footnote_anchor = renderFootnoteAnchor;\n\n // helpers (only used in other rules, no tokens are attached to those)\n // helpers (only used in other rules, no tokens are attached to those)\n md.renderer.rules.footnote_caption = renderFootnoteCaption;\n md.renderer.rules.footnote_anchor_name = renderFootnoteAnchorName;\n\n md.block.ruler.before(\"reference\", \"footnoteDef\", footnoteDef, {\n alt: [\"paragraph\", \"reference\"],\n });\n md.inline.ruler.after(\"image\", \"footnoteInline\", footnoteInline);\n md.inline.ruler.after(\"footnoteInline\", \"footnote_ref\", footnoteRef);\n md.core.ruler.after(\"inline\", \"footnoteTail\", footnoteTail);\n};\n"],"mappings":"C,yRAqBA,IAAMG,GAAe,EAAiB,IAA0B,CAE9D,GAAM,CAAE,SAAUC,EAAOC,EAAM,CAAC,KAEhC,OAAOC,EAAQ,EAAI,IAAIA,IAAU,EACnC,EAEMC,GAA0C,EAAQ,EAAO,EAAU,IAAQ,CAE/E,IAAMC,EAAQC,GAAK,MAEbC,EAAMN,EAAOC,EAAM,CAAC,KAAsB,GAEhD,MAAO,GAAG,OAAOG,GAAU,SAAW,IAAIA,EAAM,GAAK,MAAME,EAAK,E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M,kBAAmB,GAAI,CAAC,EAEpE,EAAoB,KAAO,CACzB,GAAIjB,EACJ,MAAOuD,EACP,MAAOf,EAAKxC,EAAM,CAAC,KACrB,EACAiB,EAAM,OAAO,KAAKuC,CAAmB,CACvC,CAEIF,GAAerC,EAAM,OAAO,KAAKqC,CAAa,EAElDrC,EAAM,OAAO,KAAK,IAAIA,EAAM,MAAM,iBAAkB,GAAI,EAAE,CAAC,CAC7D,CAEAA,EAAM,OAAO,KAAK,IAAIA,EAAM,MAAM,uBAAwB,GAAI,EAAE,CAAC,CACnE,E,WAEuC,GAAO,CAC5C,EAAG,SAAS,MAAM,aAAeV,EACjC,EAAG,SAAS,MAAM,oBAAsBG,EACxC,EAAG,SAAS,MAAM,qBAAuBC,EACzC,EAAG,SAAS,MAAM,cAAgBC,EAClC,EAAG,SAAS,MAAM,eAAiBC,EACnC,EAAG,SAAS,MAAM,gBAAkBC,EAIpC,EAAG,SAAS,MAAM,iBAAmBR,EACrC,EAAG,SAAS,MAAM,qBAAuBJ,EAEzCuD,EAAG,MAAM,MAAM,OAAO,YAAa,cAAe1C,EAAa,CAC7D,IAAK,CAAC,YAAa,WAAW,CAChC,CAAC,EACD0C,EAAG,OAAO,MAAM,MAAM,QAAS,iBAAkBvB,CAAc,EAC/DuB,EAAG,OAAO,MAAM,MAAM,iBAAkB,eAAgBlB,CAAW,EACnEkB,EAAG,KAAK,MAAM,MAAM,SAAU,eAAgBf,CAAY,CAC5D,C"}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["/** Forked from https://github.com/markdown-it/markdown-it-footnote/blob/master/index.mjs */\n\nimport type { BlockRule, CoreRule, InlineRule, PluginSimple } from \"@mdit/helper\";\nimport type { RendererRule, StateBlock, StateCore, StateInline, Token } from \"markdown-it\";\n\nimport type { FootNoteEnv, FootNoteToken } from \"./types.js\";\n\ninterface FootNoteStateBlock extends StateBlock {\n env: FootNoteEnv;\n}\n\ninterface FootNoteStateInline extends StateInline {\n env: FootNoteEnv;\n}\n\ninterface FootNoteStateCore extends StateCore {\n env: FootNoteEnv;\n}\n\ntype FootNoteMeta = FootNoteToken[\"meta\"];\n\nconst getIDSuffix = (tokens: Token[], index: number): string => {\n // add suffix when multiple id was found\n const { subId } = tokens[index].meta as FootNoteMeta;\n\n return subId > 0 ? `:${subId}` : \"\";\n};\n\nconst renderFootnoteAnchorName: RendererRule = (tokens, index, _options, env) => {\n // prefix\n const docId = env?.docId;\n // increasing id\n const id = (tokens[index].meta as FootNoteMeta).id;\n\n return `${typeof docId === \"string\" ? `-${docId}-` : \"\"}${(id + 1).toString()}`;\n};\n\nconst renderFootnoteCaption: RendererRule = (tokens: Token[], index) =>\n `[${\n // number\n ((tokens[index].meta as FootNoteMeta).id + 1).toString()\n }${getIDSuffix(tokens, index)}]`;\n\nconst renderFootnoteRef: RendererRule = (tokens, index, options, env, self) => {\n const id = self.rules.footnote_anchor_name(tokens, index, options, env, self);\n const caption = self.rules.footnote_caption(tokens, index, options, env, self);\n\n // A separate anchor element allows scroll offset control via CSS\n // (e.g. `.footnote-anchor { scroll-margin-top: 80px; }` to leave\n // space for a fixed navbar), which isn't possible when id and href\n // share the same <a> element.\n return `<sup class=\"footnote-ref\"><a href=\"#footnote${id}\">${caption}</a><a class=\"footnote-anchor\" id=\"footnote-ref${id}${getIDSuffix(\n tokens,\n index,\n )}\"></a></sup>`;\n};\n\nconst renderFootnoteBlockOpen: RendererRule = (_tokens, _index, options) =>\n `\\\n<hr class=\"footnotes-sep\"${options.xhtmlOut ? \" /\" : \"\"}>\n<section class=\"footnotes\">\n<ol class=\"footnotes-list\">\n`;\n\nconst renderFootnoteBlockClose = (): string => `\\\n</ol>\n</section>\n`;\n\nconst renderFootnoteOpen: RendererRule = (tokens, index, options, env, self) =>\n `<li id=\"footnote${self.rules.footnote_anchor_name(\n tokens,\n index,\n options,\n env,\n self,\n )}${getIDSuffix(tokens, index)}\" class=\"footnote-item\">`;\n\nconst renderFootnoteClose: RendererRule = () => \"</li>\\n\";\n\nconst renderFootnoteAnchor: RendererRule = (tokens, index, options, env, self) =>\n ` <a href=\"#footnote-ref${self.rules.footnote_anchor_name(tokens, index, options, env, self)}${\n getIDSuffix(tokens, index)\n /* ↩ with escape code to prevent display as Apple Emoji on iOS */\n }\" class=\"footnote-backref\">\\u21A9\\uFE0E</a>`;\n\n// Process footnote block definition\nconst footnoteDef: BlockRule = (state: FootNoteStateBlock, startLine, endLine, silent) => {\n const start = state.bMarks[startLine] + state.tShift[startLine];\n const max = state.eMarks[startLine];\n let charCode: number;\n\n if (\n // line should be at least 5 chars - \"[^x]:\"\n start + 4 > max ||\n state.src.charCodeAt(start) !== 91 /* [ */ ||\n state.src.charCodeAt(start + 1) !== 94 /* ^ */\n )\n return false;\n\n let pos = start + 2;\n\n while (pos < max) {\n charCode = state.src.charCodeAt(pos);\n if (charCode === 32 /* space */) return false;\n\n if (charCode === 93 /* ] */) break;\n\n pos++;\n }\n\n if (\n // empty footnote label\n pos === start + 2 ||\n pos + 1 >= max ||\n state.src.charCodeAt(++pos) !== 58 /* : */\n )\n return false;\n\n if (silent) return true;\n\n pos++;\n\n (state.env.footnotes ??= {}).refs ??= {};\n\n const label = state.src.slice(start + 2, pos - 2);\n\n state.env.footnotes.refs[`:${label}`] = -1;\n\n const referenceOpenToken = state.push(\"footnote_reference_open\", \"\", 1);\n\n referenceOpenToken.meta = { label };\n referenceOpenToken.level = state.level++;\n\n const oldBMark = state.bMarks[startLine];\n const oldTShift = state.tShift[startLine];\n const oldSCount = state.sCount[startLine];\n const oldParentType = state.parentType;\n const posAfterColon = pos;\n const initial =\n state.sCount[startLine] + pos - (state.bMarks[startLine] + state.tShift[startLine]);\n\n let offset = initial;\n\n while (pos < max) {\n charCode = state.src.charCodeAt(pos);\n\n if (charCode === 9 /* \\t */) offset += 4 - (offset % 4);\n else if (charCode === 32 /* space */) offset++;\n else break;\n\n pos++;\n }\n\n state.tShift[startLine] = pos - posAfterColon;\n state.sCount[startLine] = offset - initial;\n state.bMarks[startLine] = posAfterColon;\n state.blkIndent += 4;\n state.parentType = \"footnote\";\n\n if (state.sCount[startLine] < state.blkIndent) state.sCount[startLine] += state.blkIndent;\n\n state.md.block.tokenize(state, startLine, endLine);\n\n state.parentType = oldParentType;\n state.blkIndent -= 4;\n state.tShift[startLine] = oldTShift;\n state.sCount[startLine] = oldSCount;\n state.bMarks[startLine] = oldBMark;\n\n const referenceCloseToken = state.push(\"footnote_reference_close\", \"\", -1);\n\n referenceCloseToken.level = --state.level;\n\n return true;\n};\n\n// Process inline footnotes (^[...])\nconst footnoteInline: InlineRule = (state: FootNoteStateInline, silent) => {\n const max = state.posMax;\n const start = state.pos;\n\n if (\n start + 2 >= max ||\n state.src.charCodeAt(start) !== 94 /* ^ */ ||\n state.src.charCodeAt(start + 1) !== 91 /* [ */\n )\n return false;\n\n const labelEnd = state.md.helpers.parseLinkLabel(state, start + 1);\n\n // parser failed to find ']', so it’s not a valid note\n if (labelEnd < 0) return false;\n\n const labelStart = start + 2;\n\n /*\n * We found the end of the link, and know for a fact it’s a valid link;\n * so all that’s left to do is to call tokenizer.\n *\n */\n // silent mode is hard to trigger with standard syntax\n // this is more like a guard to prevent run tokenizer in silent mode\n if (!silent) {\n const list = ((state.env.footnotes ??= {}).list ??= []);\n const footnoteId = list.length;\n const tokens: Token[] = [];\n\n state.md.inline.parse(state.src.slice(labelStart, labelEnd), state.md, state.env, tokens);\n\n const refToken = state.push(\"footnote_ref\", \"\", 0);\n\n refToken.meta = { id: footnoteId };\n\n state.env.footnotes.list[footnoteId] = {\n content: state.src.slice(labelStart, labelEnd),\n tokens,\n };\n }\n\n state.pos = labelEnd + 1;\n state.posMax = max;\n\n return true;\n};\n\n// Process footnote references ([^...])\nconst footnoteRef: InlineRule = (state: FootNoteStateInline, silent) => {\n const start = state.pos;\n const max = state.posMax;\n\n if (\n // should be at least 4 chars - \"[^x]\"\n start + 3 > max ||\n !state.env.footnotes?.refs ||\n state.src.charCodeAt(start) !== 91 /* [ */ ||\n state.src.charCodeAt(start + 1) !== 94 /* ^ */\n )\n return false;\n\n let pos = start + 2;\n let charCode: number;\n\n while (pos < max) {\n charCode = state.src.charCodeAt(pos);\n if (charCode === 32 /* space */ || charCode === 10 /* \\n */) return false;\n\n if (charCode === 93 /* ] */) break;\n\n pos++;\n }\n\n // empty footnote labels\n if (pos === start + 2 || pos >= max) return false;\n\n pos++;\n\n const label = state.src.slice(start + 2, pos - 1);\n\n if (typeof state.env.footnotes.refs[`:${label}`] !== \"number\") return false;\n\n // silent mode is hard to trigger with standard syntax\n // this is more like a guard to prevent run tokenizer in silent mode\n if (!silent) {\n const list = (state.env.footnotes.list ??= []);\n const { refs } = state.env.footnotes;\n let footnoteId: number;\n\n if (refs[`:${label}`] < 0) {\n footnoteId = list.length;\n list[footnoteId] = { label, count: 0 };\n refs[`:${label}`] = footnoteId;\n } else {\n footnoteId = refs[`:${label}`];\n }\n\n // oxlint-disable-next-line typescript/no-non-null-assertion\n const subId = list[footnoteId].count!;\n\n // oxlint-disable-next-line typescript/no-non-null-assertion\n list[footnoteId].count! += 1;\n\n const refToken = state.push(\"footnote_ref\", \"\", 0);\n\n refToken.meta = { id: footnoteId, subId, label };\n }\n\n state.pos = pos;\n state.posMax = max;\n\n return true;\n};\n\n// Glue footnote tokens to end of token stream\nconst footnoteTail: CoreRule = (state: FootNoteStateCore) => {\n const refTokens: Record<string, Token[]> = {};\n\n let current: Token[], currentLabel: string;\n let isInsideRef = false;\n\n if (!state.env.footnotes?.list) {\n // If no footnotes list, remove all footnote reference tokens\n state.tokens = state.tokens.filter((stateToken) => {\n if (stateToken.type === \"footnote_reference_open\") {\n isInsideRef = true;\n\n return false;\n }\n\n if (stateToken.type === \"footnote_reference_close\") {\n isInsideRef = false;\n\n return false;\n }\n\n return !isInsideRef;\n });\n\n return;\n }\n\n const { list } = state.env.footnotes;\n\n state.tokens = state.tokens.filter((stateToken) => {\n if (stateToken.type === \"footnote_reference_open\") {\n isInsideRef = true;\n current = [];\n currentLabel = (stateToken.meta as { label: string }).label;\n\n return false;\n }\n\n if (stateToken.type === \"footnote_reference_close\") {\n isInsideRef = false;\n // prepend ':' to avoid conflict with Object.prototype members\n refTokens[`:${currentLabel}`] = current;\n\n return false;\n }\n if (isInsideRef) current.push(stateToken);\n\n return !isInsideRef;\n });\n\n const footnoteBlockOpenToken = new state.Token(\"footnote_block_open\", \"\", 1);\n\n state.tokens.push(footnoteBlockOpenToken);\n\n const listLength = list.length;\n\n for (let index = 0; index < listLength; index++) {\n const footnoteOpenToken = new state.Token(\"footnote_open\", \"\", 1);\n\n footnoteOpenToken.meta = { id: index, label: list[index].label };\n state.tokens.push(footnoteOpenToken);\n\n if (list[index].tokens) {\n const paragraphOpenToken = new state.Token(\"paragraph_open\", \"p\", 1);\n\n paragraphOpenToken.block = true;\n\n const inlineToken = new state.Token(\"inline\", \"\", 0);\n\n // oxlint-disable-next-line typescript/no-non-null-assertion\n inlineToken.children = list[index].tokens!;\n // oxlint-disable-next-line typescript/no-non-null-assertion\n inlineToken.content = list[index].content!;\n\n const paragraphCloseToken = new state.Token(\"paragraph_close\", \"p\", -1);\n\n paragraphCloseToken.block = true;\n\n state.tokens.push(paragraphOpenToken, inlineToken, paragraphCloseToken);\n } else {\n // oxlint-disable-next-line typescript/no-non-null-assertion\n const tokens = refTokens[`:${list[index].label!}`];\n\n // oxlint-disable-next-line typescript/strict-boolean-expressions\n if (tokens) state.tokens.push(...tokens);\n }\n\n const lastParagraph =\n // oxlint-disable-next-line typescript/no-non-null-assertion\n state.tokens[state.tokens.length - 1].type === \"paragraph_close\" ? state.tokens.pop()! : null;\n\n // oxlint-disable-next-line typescript/no-non-null-assertion\n for (let j = 0; j < (Number(list[index].count) > 0 ? list[index].count! : 1); j++) {\n const footnoteAnchorToken = new state.Token(\"footnote_anchor\", \"\", 0);\n\n footnoteAnchorToken.meta = {\n id: index,\n subId: j,\n label: list[index].label,\n };\n state.tokens.push(footnoteAnchorToken);\n }\n\n if (lastParagraph) state.tokens.push(lastParagraph);\n\n state.tokens.push(new state.Token(\"footnote_close\", \"\", -1));\n }\n\n state.tokens.push(new state.Token(\"footnote_block_close\", \"\", -1));\n};\n\nexport const footnote: PluginSimple = (md) => {\n md.renderer.rules.footnote_ref = renderFootnoteRef;\n md.renderer.rules.footnote_block_open = renderFootnoteBlockOpen;\n md.renderer.rules.footnote_block_close = renderFootnoteBlockClose;\n md.renderer.rules.footnote_open = renderFootnoteOpen;\n md.renderer.rules.footnote_close = renderFootnoteClose;\n md.renderer.rules.footnote_anchor = renderFootnoteAnchor;\n\n // helpers (only used in other rules, no tokens are attached to those)\n // helpers (only used in other rules, no tokens are attached to those)\n md.renderer.rules.footnote_caption = renderFootnoteCaption;\n md.renderer.rules.footnote_anchor_name = renderFootnoteAnchorName;\n\n md.block.ruler.before(\"reference\", \"footnoteDef\", footnoteDef, {\n alt: [\"paragraph\", \"reference\"],\n });\n md.inline.ruler.after(\"image\", \"footnoteInline\", footnoteInline);\n md.inline.ruler.after(\"footnoteInline\", \"footnote_ref\", footnoteRef);\n md.core.ruler.after(\"inline\", \"footnoteTail\", footnoteTail);\n};\n"],"mappings":"AAqBA,MAAM,GAAe,EAAiB,IAA0B,CAE9D,GAAM,CAAE,SAAU,EAAO,EAAM,CAAC,KAEhC,OAAO,EAAQ,EAAI,IAAI,IAAU,EACnC,EAEM,GAA0C,EAAQ,EAAO,EAAU,IAAQ,CAE/E,IAAM,EAAQ,GAAK,MAEb,EAAM,EAAO,EAAM,CAAC,KAAsB,GAEhD,MAAO,GAAG,OAAO,GAAU,SAAW,IAAI,EAAM,GAAK,MAAM,EAAK,EAAA,CAAG,SAAS,GAC9E,EAEM,GAAuC,EAAiB,IAC5D,KAEI,EAAO,EAAM,CAAC,KAAsB,GAAK,EAAA,CAAG,SAAS,IACtD,EAAY,EAAQ,CAAK,EAAE,GAE1B,GAAmC,EAAQ,EAAO,EAAS,EAAK,IAAS,CAC7E,IAA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C,EAAG,MAAM,MAAM,OAAO,YAAa,cAAe,EAAa,CAC7D,IAAK,CAAC,YAAa,WAAW,CAChC,CAAC,EACD,EAAG,OAAO,MAAM,MAAM,QAAS,iBAAkB,CAAc,EAC/D,EAAG,OAAO,MAAM,MAAM,iBAAkB,eAAgB,CAAW,EACnE,EAAG,KAAK,MAAM,MAAM,SAAU,eAAgB,CAAY,CAC5D"}
1
+ {"version":3,"file":"index.js","names":["getIDSuffix","tokens","index","subId","renderFootnoteAnchorName","docId","env","id","renderFootnoteCaption","renderFootnoteRef","self","options","renderFootnoteBlockOpen","renderFootnoteBlockClose","renderFootnoteOpen","renderFootnoteClose","renderFootnoteAnchor","footnoteDef","start","state","startLine","max","charCode","pos","silent","label","referenceOpenToken","oldBMark","oldTShift","oldSCount","oldParentType","posAfterColon","initial","offset","endLine","referenceCloseToken","footnoteInline","labelEnd","labelStart","footnoteId","refToken","footnoteRef","list","refs","footnoteTail","refTokens","current","currentLabel","isInsideRef","stateToken","footnoteBlockOpenToken","listLength","footnoteOpenToken","paragraphOpenToken","inlineToken","paragraphCloseToken","lastParagraph","j","footnoteAnchorToken","footnote","md"],"sources":["../src/plugin.ts"],"sourcesContent":["/** Forked from https://github.com/markdown-it/markdown-it-footnote/blob/master/index.mjs */\n\nimport type { BlockRule, CoreRule, InlineRule, PluginSimple } from \"@mdit/helper\";\nimport type { RendererRule, StateBlock, StateCore, StateInline, Token } from \"markdown-it\";\n\nimport type { FootNoteEnv, FootNoteToken } from \"./types.js\";\n\ninterface FootNoteStateBlock extends StateBlock {\n env: FootNoteEnv;\n}\n\ninterface FootNoteStateInline extends StateInline {\n env: FootNoteEnv;\n}\n\ninterface FootNoteStateCore extends StateCore {\n env: FootNoteEnv;\n}\n\ntype FootNoteMeta = FootNoteToken[\"meta\"];\n\nconst getIDSuffix = (tokens: Token[], index: number): string => {\n // add suffix when multiple id was found\n const { subId } = tokens[index].meta as FootNoteMeta;\n\n return subId > 0 ? `:${subId}` : \"\";\n};\n\nconst renderFootnoteAnchorName: RendererRule = (tokens, index, _options, env) => {\n // prefix\n const docId = env?.docId;\n // increasing id\n const id = (tokens[index].meta as FootNoteMeta).id;\n\n return `${typeof docId === \"string\" ? `-${docId}-` : \"\"}${(id + 1).toString()}`;\n};\n\nconst renderFootnoteCaption: RendererRule = (tokens: Token[], index) =>\n `[${\n // number\n ((tokens[index].meta as FootNoteMeta).id + 1).toString()\n }${getIDSuffix(tokens, index)}]`;\n\nconst renderFootnoteRef: RendererRule = (tokens, index, options, env, self) => {\n const id = self.rules.footnote_anchor_name(tokens, index, options, env, self);\n const caption = self.rules.footnote_caption(tokens, index, options, env, self);\n\n // A separate anchor element allows scroll offset control via CSS\n // (e.g. `.footnote-anchor { scroll-margin-top: 80px; }` to leave\n // space for a fixed navbar), which isn't possible when id and href\n // share the same <a> element.\n return `<sup class=\"footnote-ref\"><a href=\"#footnote${id}\">${caption}</a><a class=\"footnote-anchor\" id=\"footnote-ref${id}${getIDSuffix(\n tokens,\n index,\n )}\"></a></sup>`;\n};\n\nconst renderFootnoteBlockOpen: RendererRule = (_tokens, _index, options) =>\n `\\\n<hr class=\"footnotes-sep\"${options.xhtmlOut ? \" /\" : \"\"}>\n<section class=\"footnotes\">\n<ol class=\"footnotes-list\">\n`;\n\nconst renderFootnoteBlockClose = (): string => `\\\n</ol>\n</section>\n`;\n\nconst renderFootnoteOpen: RendererRule = (tokens, index, options, env, self) =>\n `<li id=\"footnote${self.rules.footnote_anchor_name(\n tokens,\n index,\n options,\n env,\n self,\n )}${getIDSuffix(tokens, index)}\" class=\"footnote-item\">`;\n\nconst renderFootnoteClose: RendererRule = () => \"</li>\\n\";\n\nconst renderFootnoteAnchor: RendererRule = (tokens, index, options, env, self) =>\n ` <a href=\"#footnote-ref${self.rules.footnote_anchor_name(tokens, index, options, env, self)}${\n getIDSuffix(tokens, index)\n /* ↩ with escape code to prevent display as Apple Emoji on iOS */\n }\" class=\"footnote-backref\">\\u21A9\\uFE0E</a>`;\n\n// Process footnote block definition\nconst footnoteDef: BlockRule = (state: FootNoteStateBlock, startLine, endLine, silent) => {\n const start = state.bMarks[startLine] + state.tShift[startLine];\n const max = state.eMarks[startLine];\n let charCode: number;\n\n if (\n // line should be at least 5 chars - \"[^x]:\"\n start + 4 > max ||\n state.src.charCodeAt(start) !== 91 /* [ */ ||\n state.src.charCodeAt(start + 1) !== 94 /* ^ */\n )\n return false;\n\n let pos = start + 2;\n\n while (pos < max) {\n charCode = state.src.charCodeAt(pos);\n if (charCode === 32 /* space */) return false;\n\n if (charCode === 93 /* ] */) break;\n\n pos++;\n }\n\n if (\n // empty footnote label\n pos === start + 2 ||\n pos + 1 >= max ||\n state.src.charCodeAt(++pos) !== 58 /* : */\n )\n return false;\n\n if (silent) return true;\n\n pos++;\n\n (state.env.footnotes ??= {}).refs ??= {};\n\n const label = state.src.slice(start + 2, pos - 2);\n\n state.env.footnotes.refs[`:${label}`] = -1;\n\n const referenceOpenToken = state.push(\"footnote_reference_open\", \"\", 1);\n\n referenceOpenToken.meta = { label };\n referenceOpenToken.level = state.level++;\n\n const oldBMark = state.bMarks[startLine];\n const oldTShift = state.tShift[startLine];\n const oldSCount = state.sCount[startLine];\n const oldParentType = state.parentType;\n const posAfterColon = pos;\n const initial =\n state.sCount[startLine] + pos - (state.bMarks[startLine] + state.tShift[startLine]);\n\n let offset = initial;\n\n while (pos < max) {\n charCode = state.src.charCodeAt(pos);\n\n if (charCode === 9 /* \\t */) offset += 4 - (offset % 4);\n else if (charCode === 32 /* space */) offset++;\n else break;\n\n pos++;\n }\n\n state.tShift[startLine] = pos - posAfterColon;\n state.sCount[startLine] = offset - initial;\n state.bMarks[startLine] = posAfterColon;\n state.blkIndent += 4;\n state.parentType = \"footnote\";\n\n if (state.sCount[startLine] < state.blkIndent) state.sCount[startLine] += state.blkIndent;\n\n state.md.block.tokenize(state, startLine, endLine);\n\n state.parentType = oldParentType;\n state.blkIndent -= 4;\n state.tShift[startLine] = oldTShift;\n state.sCount[startLine] = oldSCount;\n state.bMarks[startLine] = oldBMark;\n\n const referenceCloseToken = state.push(\"footnote_reference_close\", \"\", -1);\n\n referenceCloseToken.level = --state.level;\n\n return true;\n};\n\n// Process inline footnotes (^[...])\nconst footnoteInline: InlineRule = (state: FootNoteStateInline, silent) => {\n const max = state.posMax;\n const start = state.pos;\n\n if (\n start + 2 >= max ||\n state.src.charCodeAt(start) !== 94 /* ^ */ ||\n state.src.charCodeAt(start + 1) !== 91 /* [ */\n )\n return false;\n\n const labelEnd = state.md.helpers.parseLinkLabel(state, start + 1);\n\n // parser failed to find ']', so it’s not a valid note\n if (labelEnd < 0) return false;\n\n const labelStart = start + 2;\n\n /*\n * We found the end of the link, and know for a fact it’s a valid link;\n * so all that’s left to do is to call tokenizer.\n *\n */\n // silent mode is hard to trigger with standard syntax\n // this is more like a guard to prevent run tokenizer in silent mode\n if (!silent) {\n const list = ((state.env.footnotes ??= {}).list ??= []);\n const footnoteId = list.length;\n const tokens: Token[] = [];\n\n state.md.inline.parse(state.src.slice(labelStart, labelEnd), state.md, state.env, tokens);\n\n const refToken = state.push(\"footnote_ref\", \"\", 0);\n\n refToken.meta = { id: footnoteId };\n\n state.env.footnotes.list[footnoteId] = {\n content: state.src.slice(labelStart, labelEnd),\n tokens,\n };\n }\n\n state.pos = labelEnd + 1;\n state.posMax = max;\n\n return true;\n};\n\n// Process footnote references ([^...])\nconst footnoteRef: InlineRule = (state: FootNoteStateInline, silent) => {\n const start = state.pos;\n const max = state.posMax;\n\n if (\n // should be at least 4 chars - \"[^x]\"\n start + 3 > max ||\n !state.env.footnotes?.refs ||\n state.src.charCodeAt(start) !== 91 /* [ */ ||\n state.src.charCodeAt(start + 1) !== 94 /* ^ */\n )\n return false;\n\n let pos = start + 2;\n let charCode: number;\n\n while (pos < max) {\n charCode = state.src.charCodeAt(pos);\n if (charCode === 32 /* space */ || charCode === 10 /* \\n */) return false;\n\n if (charCode === 93 /* ] */) break;\n\n pos++;\n }\n\n // empty footnote labels\n if (pos === start + 2 || pos >= max) return false;\n\n pos++;\n\n const label = state.src.slice(start + 2, pos - 1);\n\n if (typeof state.env.footnotes.refs[`:${label}`] !== \"number\") return false;\n\n // silent mode is hard to trigger with standard syntax\n // this is more like a guard to prevent run tokenizer in silent mode\n if (!silent) {\n const list = (state.env.footnotes.list ??= []);\n const { refs } = state.env.footnotes;\n let footnoteId: number;\n\n if (refs[`:${label}`] < 0) {\n footnoteId = list.length;\n list[footnoteId] = { label, count: 0 };\n refs[`:${label}`] = footnoteId;\n } else {\n footnoteId = refs[`:${label}`];\n }\n\n // oxlint-disable-next-line typescript/no-non-null-assertion\n const subId = list[footnoteId].count!;\n\n // oxlint-disable-next-line typescript/no-non-null-assertion\n list[footnoteId].count! += 1;\n\n const refToken = state.push(\"footnote_ref\", \"\", 0);\n\n refToken.meta = { id: footnoteId, subId, label };\n }\n\n state.pos = pos;\n state.posMax = max;\n\n return true;\n};\n\n// Glue footnote tokens to end of token stream\nconst footnoteTail: CoreRule = (state: FootNoteStateCore) => {\n const refTokens: Record<string, Token[]> = {};\n\n let current: Token[], currentLabel: string;\n let isInsideRef = false;\n\n if (!state.env.footnotes?.list) {\n // If no footnotes list, remove all footnote reference tokens\n state.tokens = state.tokens.filter((stateToken) => {\n if (stateToken.type === \"footnote_reference_open\") {\n isInsideRef = true;\n\n return false;\n }\n\n if (stateToken.type === \"footnote_reference_close\") {\n isInsideRef = false;\n\n return false;\n }\n\n return !isInsideRef;\n });\n\n return;\n }\n\n const { list } = state.env.footnotes;\n\n state.tokens = state.tokens.filter((stateToken) => {\n if (stateToken.type === \"footnote_reference_open\") {\n isInsideRef = true;\n current = [];\n currentLabel = (stateToken.meta as { label: string }).label;\n\n return false;\n }\n\n if (stateToken.type === \"footnote_reference_close\") {\n isInsideRef = false;\n // prepend ':' to avoid conflict with Object.prototype members\n refTokens[`:${currentLabel}`] = current;\n\n return false;\n }\n if (isInsideRef) current.push(stateToken);\n\n return !isInsideRef;\n });\n\n const footnoteBlockOpenToken = new state.Token(\"footnote_block_open\", \"\", 1);\n\n state.tokens.push(footnoteBlockOpenToken);\n\n const listLength = list.length;\n\n for (let index = 0; index < listLength; index++) {\n const footnoteOpenToken = new state.Token(\"footnote_open\", \"\", 1);\n\n footnoteOpenToken.meta = { id: index, label: list[index].label };\n state.tokens.push(footnoteOpenToken);\n\n if (list[index].tokens) {\n const paragraphOpenToken = new state.Token(\"paragraph_open\", \"p\", 1);\n\n paragraphOpenToken.block = true;\n\n const inlineToken = new state.Token(\"inline\", \"\", 0);\n\n // oxlint-disable-next-line typescript/no-non-null-assertion\n inlineToken.children = list[index].tokens!;\n // oxlint-disable-next-line typescript/no-non-null-assertion\n inlineToken.content = list[index].content!;\n\n const paragraphCloseToken = new state.Token(\"paragraph_close\", \"p\", -1);\n\n paragraphCloseToken.block = true;\n\n state.tokens.push(paragraphOpenToken, inlineToken, paragraphCloseToken);\n } else {\n // oxlint-disable-next-line typescript/no-non-null-assertion\n const tokens = refTokens[`:${list[index].label!}`];\n\n // oxlint-disable-next-line typescript/strict-boolean-expressions\n if (tokens) state.tokens.push(...tokens);\n }\n\n const lastParagraph =\n // oxlint-disable-next-line typescript/no-non-null-assertion\n state.tokens[state.tokens.length - 1].type === \"paragraph_close\" ? state.tokens.pop()! : null;\n\n // oxlint-disable-next-line typescript/no-non-null-assertion\n for (let j = 0; j < (Number(list[index].count) > 0 ? list[index].count! : 1); j++) {\n const footnoteAnchorToken = new state.Token(\"footnote_anchor\", \"\", 0);\n\n footnoteAnchorToken.meta = {\n id: index,\n subId: j,\n label: list[index].label,\n };\n state.tokens.push(footnoteAnchorToken);\n }\n\n if (lastParagraph) state.tokens.push(lastParagraph);\n\n state.tokens.push(new state.Token(\"footnote_close\", \"\", -1));\n }\n\n state.tokens.push(new state.Token(\"footnote_block_close\", \"\", -1));\n};\n\nexport const footnote: PluginSimple = (md) => {\n md.renderer.rules.footnote_ref = renderFootnoteRef;\n md.renderer.rules.footnote_block_open = renderFootnoteBlockOpen;\n md.renderer.rules.footnote_block_close = renderFootnoteBlockClose;\n md.renderer.rules.footnote_open = renderFootnoteOpen;\n md.renderer.rules.footnote_close = renderFootnoteClose;\n md.renderer.rules.footnote_anchor = renderFootnoteAnchor;\n\n // helpers (only used in other rules, no tokens are attached to those)\n // helpers (only used in other rules, no tokens are attached to those)\n md.renderer.rules.footnote_caption = renderFootnoteCaption;\n md.renderer.rules.footnote_anchor_name = renderFootnoteAnchorName;\n\n md.block.ruler.before(\"reference\", \"footnoteDef\", footnoteDef, {\n alt: [\"paragraph\", \"reference\"],\n });\n md.inline.ruler.after(\"image\", \"footnoteInline\", footnoteInline);\n md.inline.ruler.after(\"footnoteInline\", \"footnote_ref\", footnoteRef);\n md.core.ruler.after(\"inline\", \"footnoteTail\", footnoteTail);\n};\n"],"mappings":"AAqBA,MAAMA,GAAe,EAAiB,IAA0B,CAE9D,GAAM,CAAE,SAAUC,EAAOC,EAAM,CAAC,KAEhC,OAAOC,EAAQ,EAAI,IAAIA,IAAU,EACnC,EAEMC,GAA0C,EAAQ,EAAO,EAAU,IAAQ,CAE/E,IAAMC,EAAQC,GAAK,MAEbC,EAAMN,EAAOC,EAAM,CAAC,KAAsB,GAEhD,MAAO,GAAG,OAAOG,GAAU,SAAW,IAAIA,EAAM,GAAK,MAAME,EAAK,EAAA,CAAG,SAAS,GAC9E,EAEMC,GAAuC,EAAiB,IAC5D,KAEIP,EAAOC,EAAM,CAAC,KAAsB,GAAK,EAAA,CAAG,SAAS,IACtDF,EAAYC,EAAQC,CAAK,EAAE,GAE1BO,GAAmC,EAAQ,EAAO,EAAS,EAAK,IAAS,CAC7E,IAAMF,EAAKG,EAAK,MAAM,qBAAqBT,EAAQC,EAAOS,EAASL,EAAKI,CAAI,EAO5E,MAAO,+CAA+CH,EAAG,IANzCG,EAAK,MAAM,iBAAiBT,EAAQC,EAAOS,EAASL,EAAKI,CAMN,EAAE,iDAAiDH,IAAKP,EACzHC,EACAC,CACF,EAAE,aACJ,EAEMU,GAAyC,EAAS,EAA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ACxC,EAAG,SAAS,MAAM,qBAAuBC,EACzC,EAAG,SAAS,MAAM,cAAgBC,EAClC,EAAG,SAAS,MAAM,eAAiBC,EACnC,EAAG,SAAS,MAAM,gBAAkBC,EAIpC,EAAG,SAAS,MAAM,iBAAmBR,EACrC,EAAG,SAAS,MAAM,qBAAuBJ,EAEzCwD,EAAG,MAAM,MAAM,OAAO,YAAa,cAAe3C,EAAa,CAC7D,IAAK,CAAC,YAAa,WAAW,CAChC,CAAC,EACD2C,EAAG,OAAO,MAAM,MAAM,QAAS,iBAAkBxB,CAAc,EAC/DwB,EAAG,OAAO,MAAM,MAAM,iBAAkB,eAAgBnB,CAAW,EACnEmB,EAAG,KAAK,MAAM,MAAM,SAAU,eAAgBhB,CAAY,CAC5D,E"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mdit/plugin-footnote",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "footnote plugin for MarkdownIt",
5
5
  "keywords": [
6
6
  "footnote",
@@ -44,13 +44,18 @@
44
44
  "clean": "rimraf ./dist"
45
45
  },
46
46
  "dependencies": {
47
- "@mdit/helper": "1.1.1"
47
+ "@mdit/helper": "^1.1.3"
48
48
  },
49
49
  "peerDependencies": {
50
- "markdown-it": "^15.0.1"
50
+ "markdown-it": "^15.0.3"
51
+ },
52
+ "peerDependenciesMeta": {
53
+ "markdown-it": {
54
+ "optional": true
55
+ }
51
56
  },
52
57
  "engines": {
53
58
  "node": ">=22"
54
59
  },
55
- "gitHead": "1b4c236a56b2fd99c6e6da03dd10354f43a8fa05"
60
+ "gitHead": "ec390dd7b2fa465f802ae4064280135092fc3d59"
56
61
  }