@mdit/plugin-footnote 0.22.4 → 0.23.0

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.
@@ -0,0 +1,9 @@
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.mdItPluginFootnote={}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let t=(e,t)=>e[t].meta.subId>0?`:${e[t].meta.subId}`:``,n=(e,t,n,r)=>`${typeof r.docId==`string`?`-${r.docId}-`:``}${(e[t].meta.id+1).toString()}`,r=(e,n)=>`[${(e[n].meta.id+1).toString()}${t(e,n)}]`,i=(e,n,r,i,a)=>{let o=a.rules.footnote_anchorName(e,n,r,i,a);return`<sup class="footnote-ref"><a href="#footnote${o}">${a.rules.footnote_caption(e,n,r,i,a)}</a><a class="footnote-anchor" id="footnote-ref${o}${t(e,n)}"></a></sup>`},a=(e,t,n)=>`\
2
+ <hr class="footnotes-sep"${n.xhtmlOut?` /`:``}>
3
+ <section class="footnotes">
4
+ <ol class="footnotes-list">
5
+ `,o=()=>`</ol>
6
+ </section>
7
+ `,s=(e,n,r,i,a)=>`<li id="footnote${a.rules.footnote_anchorName(e,n,r,i,a)}${t(e,n)}" class="footnote-item">`,c=()=>`</li>
8
+ `,l=(e,n,r,i,a)=>` <a href="#footnote-ref${a.rules.footnote_anchorName(e,n,r,i,a)}${t(e,n)}" class="footnote-backref">\u21A9\uFE0E</a>`,u=(e,t,n,r)=>{let i=e.bMarks[t]+e.tShift[t],a=e.eMarks[t],o;if(i+4>a||e.src.charCodeAt(i)!==91||e.src.charCodeAt(i+1)!==94)return!1;let s=i+2;for(;s<a;){if(o=e.src.charCodeAt(s),o===32)return!1;if(o===93)break;s++}if(s===i+2||s+1>=a||e.src.charCodeAt(++s)!==58)return!1;if(r)return!0;s++,(e.env.footnotes??={}).refs??={};let c=e.src.slice(i+2,s-2);e.env.footnotes.refs[`:${c}`]=-1;let l=e.push(`footnote_reference_open`,``,1);l.meta={label:c},l.level=e.level++;let u=e.bMarks[t],d=e.tShift[t],f=e.sCount[t],p=e.parentType,m=s,h=e.sCount[t]+s-(e.bMarks[t]+e.tShift[t]),g=h;for(;s<a;){if(o=e.src.charCodeAt(s),o===9)g+=4-g%4;else if(o===32)g++;else break;s++}e.tShift[t]=s-m,e.sCount[t]=g-h,e.bMarks[t]=m,e.blkIndent+=4,e.parentType=`footnote`,e.sCount[t]<e.blkIndent&&(e.sCount[t]+=e.blkIndent),e.md.block.tokenize(e,t,n),e.parentType=p,e.blkIndent-=4,e.tShift[t]=d,e.sCount[t]=f,e.bMarks[t]=u;let _=e.push(`footnote_reference_close`,``,-1);return _.level=--e.level,!0},d=(e,t)=>{let n=e.posMax,r=e.pos;if(r+2>=n||e.src.charCodeAt(r)!==94||e.src.charCodeAt(r+1)!==91)return!1;let i=e.md.helpers.parseLinkLabel(e,r+1);if(i<0)return!1;let a=r+2;if(!t){let t=((e.env.footnotes??={}).list??=[]).length,n=[];e.md.inline.parse(e.src.slice(a,i),e.md,e.env,n);let r=e.push(`footnote_ref`,``,0);r.meta={id:t},e.env.footnotes.list[t]={content:e.src.slice(a,i),tokens:n}}return e.pos=i+1,e.posMax=n,!0},f=(e,t)=>{let n=e.pos,r=e.posMax;if(n+3>r||!e.env.footnotes?.refs||e.src.charCodeAt(n)!==91||e.src.charCodeAt(n+1)!==94)return!1;let i=n+2,a;for(;i<r;){if(a=e.src.charCodeAt(i),a===32||a===10)return!1;if(a===93)break;i++}if(i===n+2||i>=r)return!1;i++;let o=e.src.slice(n+2,i-1);if(typeof e.env.footnotes.refs[`:${o}`]!=`number`)return!1;if(!t){let t=e.env.footnotes.list??=[],{refs:n}=e.env.footnotes,r;n[`:${o}`]<0?(r=t.length,t[r]={label:o,count:0},n[`:${o}`]=r):r=n[`:${o}`];let i=t[r].count;t[r].count+=1;let a=e.push(`footnote_ref`,``,0);a.meta={id:r,subId:i,label:o}}return e.pos=i,e.posMax=r,!0},p=e=>{let t={},n,r,i=!1;if(!e.env.footnotes?.list)return e.tokens=e.tokens.filter(e=>e.type===`footnote_reference_open`?(i=!0,!1):e.type===`footnote_reference_close`?(i=!1,!1):!i),!1;let{list:a}=e.env.footnotes;e.tokens=e.tokens.filter(e=>e.type===`footnote_reference_open`?(i=!0,n=[],r=e.meta.label,!1):e.type===`footnote_reference_close`?(i=!1,t[`:${r}`]=n,!1):(i&&n.push(e),!i));let o=new e.Token(`footnote_block_open`,``,1);e.tokens.push(o);let s=a.length;for(let n=0;n<s;n++){let r=new e.Token(`footnote_open`,``,1);if(r.meta={id:n,label:a[n].label},e.tokens.push(r),a[n].tokens){let t=new e.Token(`paragraph_open`,`p`,1);t.block=!0;let r=new e.Token(`inline`,``,0);r.children=a[n].tokens,r.content=a[n].content;let i=new e.Token(`paragraph_close`,`p`,-1);i.block=!0,e.tokens.push(t,r,i)}else{let r=t[`:${a[n].label}`];r&&e.tokens.push(...r)}let i=e.tokens[e.tokens.length-1].type===`paragraph_close`?e.tokens.pop():null;for(let t=0;t<(Number(a[n].count)>0?a[n].count:1);t++){let r=new e.Token(`footnote_anchor`,``,0);r.meta={id:n,subId:t,label:a[n].label},e.tokens.push(r)}i&&e.tokens.push(i),e.tokens.push(new e.Token(`footnote_close`,``,-1))}return e.tokens.push(new e.Token(`footnote_block_close`,``,-1)),!0};e.footnote=e=>{e.renderer.rules.footnote_ref=i,e.renderer.rules.footnote_block_open=a,e.renderer.rules.footnote_block_close=o,e.renderer.rules.footnote_open=s,e.renderer.rules.footnote_close=c,e.renderer.rules.footnote_anchor=l,e.renderer.rules.footnote_caption=r,e.renderer.rules.footnote_anchorName=n,e.block.ruler.before(`reference`,`footnoteDef`,u,{alt:[`paragraph`,`reference`]}),e.inline.ruler.after(`image`,`footnoteInline`,d),e.inline.ruler.after(`footnoteInline`,`footnote_ref`,f),e.core.ruler.after(`inline`,`footnoteTail`,p)}});
9
+ //# sourceMappingURL=cdn.umd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cdn.umd.js","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["/**\n * Forked from https://github.com/markdown-it/markdown-it-footnote/blob/master/index.mjs\n */\n\nimport type { PluginSimple } from \"markdown-it\";\nimport type { RuleBlock } from \"markdown-it/lib/parser_block.mjs\";\nimport type { RuleCore } from \"markdown-it/lib/parser_core.mjs\";\nimport type { RuleInline } from \"markdown-it/lib/parser_inline.mjs\";\nimport type { RenderRule } from \"markdown-it/lib/renderer.mjs\";\nimport type { ParentType } from \"markdown-it/lib/rules_block/state_block.mjs\";\nimport type StateBlock from \"markdown-it/lib/rules_block/state_block.mjs\";\nimport type StateCore from \"markdown-it/lib/rules_core/state_core.mjs\";\nimport type StateInline from \"markdown-it/lib/rules_inline/state_inline.mjs\";\nimport type Token from \"markdown-it/lib/token.mjs\";\n\nimport type { FootNoteEnv, FootNoteToken } from \"./types.js\";\n\ninterface FootNoteStateBlock extends StateBlock {\n tokens: FootNoteToken[];\n env: FootNoteEnv;\n}\n\ninterface FootNoteStateInline extends StateInline {\n tokens: FootNoteToken[];\n env: FootNoteEnv;\n}\n\ninterface FootNoteStateCore extends StateCore {\n tokens: FootNoteToken[];\n env: FootNoteEnv;\n}\n\nconst getIDSuffix = (tokens: FootNoteToken[], index: number): string =>\n // add suffix when multiple id was found\n tokens[index].meta.subId > 0 ? `:${tokens[index].meta.subId}` : \"\";\n\nconst renderFootnoteAnchorName: RenderRule = (\n tokens: FootNoteToken[],\n index,\n _options,\n env: FootNoteEnv,\n): string =>\n `${\n // prefix\n typeof env.docId === \"string\" ? `-${env.docId}-` : \"\"\n }${\n // increasing id\n (tokens[index].meta.id + 1).toString()\n }`;\n\nconst renderFootnoteCaption: RenderRule = (tokens: FootNoteToken[], index): string =>\n `[${\n // number\n (tokens[index].meta.id + 1).toString()\n }${getIDSuffix(tokens, index)}]`;\n\nconst renderFootnoteRef: RenderRule = (\n tokens: FootNoteToken[],\n index,\n options,\n env: FootNoteEnv,\n self,\n): string => {\n // oxlint-disable-next-line typescript/no-non-null-assertion\n const id = self.rules.footnote_anchorName!(tokens, index, options, env, self);\n // oxlint-disable-next-line typescript/no-non-null-assertion\n const caption = self.rules.footnote_caption!(tokens, index, options, env, self);\n\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: RenderRule = (_tokens: FootNoteToken[], _index, options): string =>\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: RenderRule = (\n tokens: FootNoteToken[],\n index,\n options,\n env: FootNoteEnv,\n self,\n): string =>\n // oxlint-disable-next-line typescript/no-non-null-assertion\n `<li id=\"footnote${self.rules.footnote_anchorName!(\n tokens,\n index,\n options,\n env,\n self,\n )}${getIDSuffix(tokens, index)}\" class=\"footnote-item\">`;\n\nconst renderFootnoteClose = (): string => \"</li>\\n\";\n\nconst renderFootnoteAnchor: RenderRule = (\n tokens: FootNoteToken[],\n index,\n options,\n env: FootNoteEnv,\n self,\n): string =>\n // oxlint-disable-next-line typescript/no-non-null-assertion\n ` <a href=\"#footnote-ref${self.rules.footnote_anchorName!(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: RuleBlock = (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\" as unknown as ParentType;\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: RuleInline = (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: RuleInline = (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: RuleCore = (state: FootNoteStateCore): boolean => {\n const refTokens: Record<string, Token[]> = {};\n\n let current: Token[];\n let 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 false;\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.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 return true;\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_anchorName = 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":"0RAgCA,IAAM,GAAe,EAAyB,IAE5C,EAAO,GAAO,KAAK,MAAQ,EAAI,IAAI,EAAO,GAAO,KAAK,QAAU,GAE5D,GACJ,EACA,EACA,EACA,IAEA,GAEE,OAAO,EAAI,OAAU,SAAW,IAAI,EAAI,MAAM,GAAK,MAGlD,EAAO,GAAO,KAAK,GAAK,GAAG,UAAU,GAGpC,GAAqC,EAAyB,IAClE,KAEG,EAAO,GAAO,KAAK,GAAK,GAAG,UAAU,GACrC,EAAY,EAAQ,EAAM,CAAC,GAE1B,GACJ,EACA,EACA,EACA,EACA,IACW,CAEX,IAAM,EAAK,EAAK,MAAM,oBAAqB,EAAQ,EAAO,EAAS,EAAK,EAAK,CAI7E,MAAO,+CAA+C,EAAG,IAFzC,EAAK,MAAM,iBAAkB,EAAQ,EAAO,EAAS,EAAK,EAAK,CAEV,iDAAiD,IAAK,EACzH,EACA,EACD,CAAC,eAGE,GAAuC,EAA0B,EAAQ,IAC7E;2BACyB,EAAQ,SAAW,KAAO,GAAG;;;EAKlD,MAAyC;;EAKzC,GACJ,EACA,EACA,EACA,EACA,IAGA,mBAAmB,EAAK,MAAM,oBAC5B,EACA,EACA,EACA,EACA,EACD,GAAG,EAAY,EAAQ,EAAM,CAAC,0BAE3B,MAAoC;EAEpC,GACJ,EACA,EACA,EACA,EACA,IAGA,0BAA0B,EAAK,MAAM,oBAAqB,EAAQ,EAAO,EAAS,EAAK,EAAK,GAC1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ACJ,MAAO,EACP,MAAO,EAAK,GAAO,MACpB,CACD,EAAM,OAAO,KAAK,EAAoB,CAGpC,GAAe,EAAM,OAAO,KAAK,EAAc,CAEnD,EAAM,OAAO,KAAK,IAAI,EAAM,MAAM,iBAAkB,GAAI,GAAG,CAAC,CAK9D,OAFA,EAAM,OAAO,KAAK,IAAI,EAAM,MAAM,uBAAwB,GAAI,GAAG,CAAC,CAE3D,eAG8B,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,oBAAsB,EAExC,EAAG,MAAM,MAAM,OAAO,YAAa,cAAe,EAAa,CAC7D,IAAK,CAAC,YAAa,YAAY,CAChC,CAAC,CACF,EAAG,OAAO,MAAM,MAAM,QAAS,iBAAkB,EAAe,CAChE,EAAG,OAAO,MAAM,MAAM,iBAAkB,eAAgB,EAAY,CACpE,EAAG,KAAK,MAAM,MAAM,SAAU,eAAgB,EAAa"}
@@ -12,7 +12,7 @@ interface FootNoteToken extends Token {
12
12
  label: string;
13
13
  };
14
14
  }
15
- interface FootNoteEnv extends Record<any, any> {
15
+ interface FootNoteEnv extends Record<string, any> {
16
16
  docId?: string;
17
17
  footnotes: {
18
18
  label?: string;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/plugin.ts","../src/types.ts"],"mappings":";;;;cAuba,QAAA,EAAU,YAAA;;;UCrbN,aAAA,SAAsB,KAAA;EACrC,IAAA;IACE,EAAA;IACA,KAAA;IACA,KAAA;EAAA;AAAA;AAAA,UAKa,WAAA,SAAoB,MAAA;EACnC,KAAA;EACA,SAAA;IACE,KAAA;IACA,IAAA,GAAO,MAAA;IACP,IAAA;MACE,KAAA;MACA,KAAA;MACA,OAAA;MACA,MAAA,GAAS,KAAA;IAAA;EAAA;AAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ const e=(e,t)=>e[t].meta.subId>0?`:${e[t].meta.subId}`:``,t=(e,t,n,r)=>`${typeof r.docId==`string`?`-${r.docId}-`:``}${(e[t].meta.id+1).toString()}`,n=(t,n)=>`[${(t[n].meta.id+1).toString()}${e(t,n)}]`,r=(t,n,r,i,a)=>{let o=a.rules.footnote_anchorName(t,n,r,i,a);return`<sup class="footnote-ref"><a href="#footnote${o}">${a.rules.footnote_caption(t,n,r,i,a)}</a><a class="footnote-anchor" id="footnote-ref${o}${e(t,n)}"></a></sup>`},i=(e,t,n)=>`\
2
+ <hr class="footnotes-sep"${n.xhtmlOut?` /`:``}>
3
+ <section class="footnotes">
4
+ <ol class="footnotes-list">
5
+ `,a=()=>`</ol>
6
+ </section>
7
+ `,o=(t,n,r,i,a)=>`<li id="footnote${a.rules.footnote_anchorName(t,n,r,i,a)}${e(t,n)}" class="footnote-item">`,s=()=>`</li>
8
+ `,c=(t,n,r,i,a)=>` <a href="#footnote-ref${a.rules.footnote_anchorName(t,n,r,i,a)}${e(t,n)}" class="footnote-backref">\u21A9\uFE0E</a>`,l=(e,t,n,r)=>{let i=e.bMarks[t]+e.tShift[t],a=e.eMarks[t],o;if(i+4>a||e.src.charCodeAt(i)!==91||e.src.charCodeAt(i+1)!==94)return!1;let s=i+2;for(;s<a;){if(o=e.src.charCodeAt(s),o===32)return!1;if(o===93)break;s++}if(s===i+2||s+1>=a||e.src.charCodeAt(++s)!==58)return!1;if(r)return!0;s++,(e.env.footnotes??={}).refs??={};let c=e.src.slice(i+2,s-2);e.env.footnotes.refs[`:${c}`]=-1;let l=e.push(`footnote_reference_open`,``,1);l.meta={label:c},l.level=e.level++;let u=e.bMarks[t],d=e.tShift[t],f=e.sCount[t],p=e.parentType,m=s,h=e.sCount[t]+s-(e.bMarks[t]+e.tShift[t]),g=h;for(;s<a;){if(o=e.src.charCodeAt(s),o===9)g+=4-g%4;else if(o===32)g++;else break;s++}e.tShift[t]=s-m,e.sCount[t]=g-h,e.bMarks[t]=m,e.blkIndent+=4,e.parentType=`footnote`,e.sCount[t]<e.blkIndent&&(e.sCount[t]+=e.blkIndent),e.md.block.tokenize(e,t,n),e.parentType=p,e.blkIndent-=4,e.tShift[t]=d,e.sCount[t]=f,e.bMarks[t]=u;let _=e.push(`footnote_reference_close`,``,-1);return _.level=--e.level,!0},u=(e,t)=>{let n=e.posMax,r=e.pos;if(r+2>=n||e.src.charCodeAt(r)!==94||e.src.charCodeAt(r+1)!==91)return!1;let i=e.md.helpers.parseLinkLabel(e,r+1);if(i<0)return!1;let a=r+2;if(!t){let t=((e.env.footnotes??={}).list??=[]).length,n=[];e.md.inline.parse(e.src.slice(a,i),e.md,e.env,n);let r=e.push(`footnote_ref`,``,0);r.meta={id:t},e.env.footnotes.list[t]={content:e.src.slice(a,i),tokens:n}}return e.pos=i+1,e.posMax=n,!0},d=(e,t)=>{let n=e.pos,r=e.posMax;if(n+3>r||!e.env.footnotes?.refs||e.src.charCodeAt(n)!==91||e.src.charCodeAt(n+1)!==94)return!1;let i=n+2,a;for(;i<r;){if(a=e.src.charCodeAt(i),a===32||a===10)return!1;if(a===93)break;i++}if(i===n+2||i>=r)return!1;i++;let o=e.src.slice(n+2,i-1);if(typeof e.env.footnotes.refs[`:${o}`]!=`number`)return!1;if(!t){let t=e.env.footnotes.list??=[],{refs:n}=e.env.footnotes,r;n[`:${o}`]<0?(r=t.length,t[r]={label:o,count:0},n[`:${o}`]=r):r=n[`:${o}`];let i=t[r].count;t[r].count+=1;let a=e.push(`footnote_ref`,``,0);a.meta={id:r,subId:i,label:o}}return e.pos=i,e.posMax=r,!0},f=e=>{let t={},n,r,i=!1;if(!e.env.footnotes?.list)return e.tokens=e.tokens.filter(e=>e.type===`footnote_reference_open`?(i=!0,!1):e.type===`footnote_reference_close`?(i=!1,!1):!i),!1;let{list:a}=e.env.footnotes;e.tokens=e.tokens.filter(e=>e.type===`footnote_reference_open`?(i=!0,n=[],r=e.meta.label,!1):e.type===`footnote_reference_close`?(i=!1,t[`:${r}`]=n,!1):(i&&n.push(e),!i));let o=new e.Token(`footnote_block_open`,``,1);e.tokens.push(o);let s=a.length;for(let n=0;n<s;n++){let r=new e.Token(`footnote_open`,``,1);if(r.meta={id:n,label:a[n].label},e.tokens.push(r),a[n].tokens){let t=new e.Token(`paragraph_open`,`p`,1);t.block=!0;let r=new e.Token(`inline`,``,0);r.children=a[n].tokens,r.content=a[n].content;let i=new e.Token(`paragraph_close`,`p`,-1);i.block=!0,e.tokens.push(t,r,i)}else{let r=t[`:${a[n].label}`];r&&e.tokens.push(...r)}let i=e.tokens[e.tokens.length-1].type===`paragraph_close`?e.tokens.pop():null;for(let t=0;t<(Number(a[n].count)>0?a[n].count:1);t++){let r=new e.Token(`footnote_anchor`,``,0);r.meta={id:n,subId:t,label:a[n].label},e.tokens.push(r)}i&&e.tokens.push(i),e.tokens.push(new e.Token(`footnote_close`,``,-1))}return e.tokens.push(new e.Token(`footnote_block_close`,``,-1)),!0},p=e=>{e.renderer.rules.footnote_ref=r,e.renderer.rules.footnote_block_open=i,e.renderer.rules.footnote_block_close=a,e.renderer.rules.footnote_open=o,e.renderer.rules.footnote_close=s,e.renderer.rules.footnote_anchor=c,e.renderer.rules.footnote_caption=n,e.renderer.rules.footnote_anchorName=t,e.block.ruler.before(`reference`,`footnoteDef`,l,{alt:[`paragraph`,`reference`]}),e.inline.ruler.after(`image`,`footnoteInline`,u),e.inline.ruler.after(`footnoteInline`,`footnote_ref`,d),e.core.ruler.after(`inline`,`footnoteTail`,f)};export{p as footnote};
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["/**\n * Forked from https://github.com/markdown-it/markdown-it-footnote/blob/master/index.mjs\n */\n\nimport type { PluginSimple } from \"markdown-it\";\nimport type { RuleBlock } from \"markdown-it/lib/parser_block.mjs\";\nimport type { RuleCore } from \"markdown-it/lib/parser_core.mjs\";\nimport type { RuleInline } from \"markdown-it/lib/parser_inline.mjs\";\nimport type { RenderRule } from \"markdown-it/lib/renderer.mjs\";\nimport type { ParentType } from \"markdown-it/lib/rules_block/state_block.mjs\";\nimport type StateBlock from \"markdown-it/lib/rules_block/state_block.mjs\";\nimport type StateCore from \"markdown-it/lib/rules_core/state_core.mjs\";\nimport type StateInline from \"markdown-it/lib/rules_inline/state_inline.mjs\";\nimport type Token from \"markdown-it/lib/token.mjs\";\n\nimport type { FootNoteEnv, FootNoteToken } from \"./types.js\";\n\ninterface FootNoteStateBlock extends StateBlock {\n tokens: FootNoteToken[];\n env: FootNoteEnv;\n}\n\ninterface FootNoteStateInline extends StateInline {\n tokens: FootNoteToken[];\n env: FootNoteEnv;\n}\n\ninterface FootNoteStateCore extends StateCore {\n tokens: FootNoteToken[];\n env: FootNoteEnv;\n}\n\nconst getIDSuffix = (tokens: FootNoteToken[], index: number): string =>\n // add suffix when multiple id was found\n tokens[index].meta.subId > 0 ? `:${tokens[index].meta.subId}` : \"\";\n\nconst renderFootnoteAnchorName: RenderRule = (\n tokens: FootNoteToken[],\n index,\n _options,\n env: FootNoteEnv,\n): string =>\n `${\n // prefix\n typeof env.docId === \"string\" ? `-${env.docId}-` : \"\"\n }${\n // increasing id\n (tokens[index].meta.id + 1).toString()\n }`;\n\nconst renderFootnoteCaption: RenderRule = (tokens: FootNoteToken[], index): string =>\n `[${\n // number\n (tokens[index].meta.id + 1).toString()\n }${getIDSuffix(tokens, index)}]`;\n\nconst renderFootnoteRef: RenderRule = (\n tokens: FootNoteToken[],\n index,\n options,\n env: FootNoteEnv,\n self,\n): string => {\n // oxlint-disable-next-line typescript/no-non-null-assertion\n const id = self.rules.footnote_anchorName!(tokens, index, options, env, self);\n // oxlint-disable-next-line typescript/no-non-null-assertion\n const caption = self.rules.footnote_caption!(tokens, index, options, env, self);\n\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: RenderRule = (_tokens: FootNoteToken[], _index, options): string =>\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: RenderRule = (\n tokens: FootNoteToken[],\n index,\n options,\n env: FootNoteEnv,\n self,\n): string =>\n // oxlint-disable-next-line typescript/no-non-null-assertion\n `<li id=\"footnote${self.rules.footnote_anchorName!(\n tokens,\n index,\n options,\n env,\n self,\n )}${getIDSuffix(tokens, index)}\" class=\"footnote-item\">`;\n\nconst renderFootnoteClose = (): string => \"</li>\\n\";\n\nconst renderFootnoteAnchor: RenderRule = (\n tokens: FootNoteToken[],\n index,\n options,\n env: FootNoteEnv,\n self,\n): string =>\n // oxlint-disable-next-line typescript/no-non-null-assertion\n ` <a href=\"#footnote-ref${self.rules.footnote_anchorName!(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: RuleBlock = (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\" as unknown as ParentType;\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: RuleInline = (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: RuleInline = (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: RuleCore = (state: FootNoteStateCore): boolean => {\n const refTokens: Record<string, Token[]> = {};\n\n let current: Token[];\n let 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 false;\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.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 return true;\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_anchorName = 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":"AAgCA,MAAM,GAAe,EAAyB,IAE5C,EAAO,GAAO,KAAK,MAAQ,EAAI,IAAI,EAAO,GAAO,KAAK,QAAU,GAE5D,GACJ,EACA,EACA,EACA,IAEA,GAEE,OAAO,EAAI,OAAU,SAAW,IAAI,EAAI,MAAM,GAAK,MAGlD,EAAO,GAAO,KAAK,GAAK,GAAG,UAAU,GAGpC,GAAqC,EAAyB,IAClE,KAEG,EAAO,GAAO,KAAK,GAAK,GAAG,UAAU,GACrC,EAAY,EAAQ,EAAM,CAAC,GAE1B,GACJ,EACA,EACA,EACA,EACA,IACW,CAEX,IAAM,EAAK,EAAK,MAAM,oBAAqB,EAAQ,EAAO,EAAS,EAAK,EAAK,CAI7E,MAAO,+CAA+C,EAAG,IAFzC,EAAK,MAAM,iBAAkB,EAAQ,EAAO,EAAS,EAAK,EAAK,CAEV,iDAAiD,IAAK,EACzH,EACA,EACD,CAAC,eAGE,GAAuC,EAA0B,EAAQ,IAC7E;2BACyB,EAAQ,SAAW,KAAO,GAAG;;;EAKlD,MAAyC;;EAKzC,GACJ,EACA,EACA,EACA,EACA,IAGA,mBAAmB,EAAK,MAAM,oBAC5B,EACA,EACA,EACA,EACA,EACD,GAAG,EAAY,EAAQ,EAAM,CAAC,0BAE3B,MAAoC;EAEpC,GACJ,EACA,EACA,EACA,EACA,IAGA,0BAA0B,EAAK,MAAM,oBAAqB,EAAQ,EAAO,EAAS,EAAK,EAAK,GAC1F,EAAY,EAAQ,EAAM,CAE3B,6CAGG,GAA0B,EAA2B,EAAW,EAAS,IAAW,CACxF,IAAM,EAAQ,EAAM,OAAO,GAAa,EAAM,OAAO,GAC/C,EAAM,EAAM,OAAO,GACrB,EAEJ,GAEE,EAAQ,EAAI,GACZ,EAAM,IAA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AAM,OAAO,KAAK,IAAI,EAAM,MAAM,uBAAwB,GAAI,GAAG,CAAC,CAE3D,IAGI,EAA0B,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,oBAAsB,EAExC,EAAG,MAAM,MAAM,OAAO,YAAa,cAAe,EAAa,CAC7D,IAAK,CAAC,YAAa,YAAY,CAChC,CAAC,CACF,EAAG,OAAO,MAAM,MAAM,QAAS,iBAAkB,EAAe,CAChE,EAAG,OAAO,MAAM,MAAM,iBAAkB,eAAgB,EAAY,CACpE,EAAG,KAAK,MAAM,MAAM,SAAU,eAAgB,EAAa"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mdit/plugin-footnote",
3
- "version": "0.22.4",
3
+ "version": "0.23.0",
4
4
  "description": "footnote plugin for MarkdownIt",
5
5
  "keywords": [
6
6
  "footnote",
@@ -23,15 +23,15 @@
23
23
  "directory": "packages/footnote"
24
24
  },
25
25
  "files": [
26
- "lib"
26
+ "dist"
27
27
  ],
28
28
  "type": "module",
29
- "main": "./lib/index.js",
30
- "types": "./lib/index.d.ts",
29
+ "unpkg": "./dist/cdn.umd.js",
30
+ "jsdelivr": "./dist/cdn.umd.js",
31
31
  "exports": {
32
32
  ".": {
33
- "type": "./lib/index.d.ts",
34
- "default": "./lib/index.js"
33
+ "types": "./dist/index.d.ts",
34
+ "default": "./dist/index.js"
35
35
  },
36
36
  "./package.json": "./package.json"
37
37
  },
@@ -45,10 +45,10 @@
45
45
  "markdown-it": "^14.1.0"
46
46
  },
47
47
  "engines": {
48
- "node": ">= 18"
48
+ "node": ">= 20"
49
49
  },
50
50
  "scripts": {
51
51
  "build": "tsdown --config-loader unrun",
52
- "clean": "rimraf ./lib"
52
+ "clean": "rimraf ./dist"
53
53
  }
54
54
  }
package/lib/index.js DELETED
@@ -1,9 +0,0 @@
1
- const e=(e,t)=>e[t].meta.subId>0?`:${e[t].meta.subId}`:``,t=(e,t,n,r)=>`${typeof r.docId==`string`?`-${r.docId}-`:``}${(e[t].meta.id+1).toString()}`,n=(t,n)=>`[${(t[n].meta.id+1).toString()}${e(t,n)}]`,r=(t,n,r,i,a)=>{let o=a.rules.footnote_anchorName(t,n,r,i,a);return`<sup class="footnote-ref"><a href="#footnote${o}">${a.rules.footnote_caption(t,n,r,i,a)}</a><a class="footnote-anchor" id="footnote-ref${o}${e(t,n)}"></a></sup>`},i=(e,t,n)=>`\
2
- <hr class="footnotes-sep"${n.xhtmlOut?` /`:``}>
3
- <section class="footnotes">
4
- <ol class="footnotes-list">
5
- `,a=()=>`</ol>
6
- </section>
7
- `,o=(t,n,r,i,a)=>`<li id="footnote${a.rules.footnote_anchorName(t,n,r,i,a)}${e(t,n)}" class="footnote-item">`,s=()=>`</li>
8
- `,c=(t,n,r,i,a)=>` <a href="#footnote-ref${a.rules.footnote_anchorName(t,n,r,i,a)}${e(t,n)}" class="footnote-backref">\u21A9\uFE0E</a>`,l=(e,t,n,r)=>{let i=e.bMarks[t]+e.tShift[t],a=e.eMarks[t],o;if(i+4>a||e.src.charCodeAt(i)!==91||e.src.charCodeAt(i+1)!==94)return!1;let s=i+2;for(;s<a;){if(o=e.src.charCodeAt(s),o===32)return!1;if(o===93)break;s++}if(s===i+2||s+1>=a||e.src.charCodeAt(++s)!==58)return!1;if(r)return!0;s++,(e.env.footnotes??={}).refs??={};let c=e.src.slice(i+2,s-2);e.env.footnotes.refs[`:${c}`]=-1;let l=e.push(`footnote_reference_open`,``,1);l.meta={label:c},l.level=e.level++;let u=e.bMarks[t],d=e.tShift[t],f=e.sCount[t],p=e.parentType,m=s,h=e.sCount[t]+s-(e.bMarks[t]+e.tShift[t]),g=h;for(;s<a;){let t=e.src.charCodeAt(s);if(t===9)g+=4-g%4;else if(t===32)g++;else break;s++}e.tShift[t]=s-m,e.sCount[t]=g-h,e.bMarks[t]=m,e.blkIndent+=4,e.parentType=`footnote`,e.sCount[t]<e.blkIndent&&(e.sCount[t]+=e.blkIndent),e.md.block.tokenize(e,t,n),e.parentType=p,e.blkIndent-=4,e.tShift[t]=d,e.sCount[t]=f,e.bMarks[t]=u;let _=e.push(`footnote_reference_close`,``,-1);return _.level=--e.level,!0},u=(e,t)=>{let n=e.posMax,r=e.pos;if(r+2>=n||e.src.charCodeAt(r)!==94||e.src.charCodeAt(r+1)!==91)return!1;let i=e.md.helpers.parseLinkLabel(e,r+1);if(i<0)return!1;let a=r+2;if(!t){let t=((e.env.footnotes??={}).list??=[]).length,n=[];e.md.inline.parse(e.src.slice(a,i),e.md,e.env,n);let r=e.push(`footnote_ref`,``,0);r.meta={id:t},e.env.footnotes.list[t]={content:e.src.slice(a,i),tokens:n}}return e.pos=i+1,e.posMax=n,!0},d=(e,t)=>{let n=e.pos,r=e.posMax,i;if(n+3>r||!e.env.footnotes?.refs||e.src.charCodeAt(n)!==91||e.src.charCodeAt(n+1)!==94)return!1;let a=n+2;for(;a<r;){if(i=e.src.charCodeAt(a),i===32||i===10)return!1;if(i===93)break;a++}if(a===n+2||a>=r)return!1;a++;let o=e.src.slice(n+2,a-1);if(e.env.footnotes.refs[`:${o}`]===void 0)return!1;if(!t){let t=e.env.footnotes.list??=[],{refs:n}=e.env.footnotes,r;n[`:${o}`]<0?(r=t.length,t[r]={label:o,count:0},n[`:${o}`]=r):r=n[`:${o}`];let i=t[r].count;t[r].count+=1;let a=e.push(`footnote_ref`,``,0);a.meta={id:r,subId:i,label:o}}return e.pos=a,e.posMax=r,!0},f=e=>{let t={},n,r,i=!1;if(!e.env.footnotes?.list)return e.tokens=e.tokens.filter(e=>e.type===`footnote_reference_open`?(i=!0,!1):e.type===`footnote_reference_close`?(i=!1,!1):!i),!1;let{list:a}=e.env.footnotes;e.tokens=e.tokens.filter(e=>e.type===`footnote_reference_open`?(i=!0,n=[],r=e.meta.label,!1):e.type===`footnote_reference_close`?(i=!1,t[`:${r}`]=n,!1):(i&&n.push(e),!i));let o=new e.Token(`footnote_block_open`,``,1);e.tokens.push(o);for(let n=0,{length:r}=a;n<r;n++){let r=new e.Token(`footnote_open`,``,1);r.meta={id:n,label:a[n].label},e.tokens.push(r);let i;if(a[n].tokens){let t=new e.Token(`paragraph_open`,`p`,1);t.block=!0;let r=new e.Token(`inline`,``,0);r.children=a[n].tokens,r.content=a[n].content;let i=new e.Token(`paragraph_close`,`p`,-1);i.block=!0,e.tokens.push(t,r,i)}else if(a[n].label){let r=t[`:${a[n].label}`];r&&e.tokens.push(...r)}i=e.tokens[e.tokens.length-1].type===`paragraph_close`?e.tokens.pop()??null:null;for(let t=0;t<(Number(a[n].count)>0?a[n].count:1);t++){let r=new e.Token(`footnote_anchor`,``,0);r.meta={id:n,subId:t,label:a[n].label},e.tokens.push(r)}i&&e.tokens.push(i),e.tokens.push(new e.Token(`footnote_close`,``,-1))}return e.tokens.push(new e.Token(`footnote_block_close`,``,-1)),!0},p=e=>{e.renderer.rules.footnote_ref=r,e.renderer.rules.footnote_block_open=i,e.renderer.rules.footnote_block_close=a,e.renderer.rules.footnote_open=o,e.renderer.rules.footnote_close=s,e.renderer.rules.footnote_anchor=c,e.renderer.rules.footnote_caption=n,e.renderer.rules.footnote_anchorName=t,e.block.ruler.before(`reference`,`footnoteDef`,l,{alt:[`paragraph`,`reference`]}),e.inline.ruler.after(`image`,`footnoteInline`,u),e.inline.ruler.after(`footnoteInline`,`footnote_ref`,d),e.core.ruler.after(`inline`,`footnoteTail`,f)};export{p as footnote};
9
- //# sourceMappingURL=index.js.map
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["/**\n * Forked from https://github.com/markdown-it/markdown-it-footnote/blob/master/index.mjs\n */\n\nimport type { PluginSimple } from \"markdown-it\";\nimport type { RuleBlock } from \"markdown-it/lib/parser_block.mjs\";\nimport type { RuleCore } from \"markdown-it/lib/parser_core.mjs\";\nimport type { RuleInline } from \"markdown-it/lib/parser_inline.mjs\";\nimport type { RenderRule } from \"markdown-it/lib/renderer.mjs\";\nimport type { ParentType } from \"markdown-it/lib/rules_block/state_block.mjs\";\nimport type StateBlock from \"markdown-it/lib/rules_block/state_block.mjs\";\nimport type StateCore from \"markdown-it/lib/rules_core/state_core.mjs\";\nimport type StateInline from \"markdown-it/lib/rules_inline/state_inline.mjs\";\nimport type Token from \"markdown-it/lib/token.mjs\";\n\nimport type { FootNoteEnv, FootNoteToken } from \"./types.js\";\n\ninterface FootNoteStateBlock extends StateBlock {\n tokens: FootNoteToken[];\n env: FootNoteEnv;\n}\n\ninterface FootNoteStateInline extends StateInline {\n tokens: FootNoteToken[];\n env: FootNoteEnv;\n}\n\ninterface FootNoteStateCore extends StateCore {\n tokens: FootNoteToken[];\n env: FootNoteEnv;\n}\n\nconst getIDSuffix = (tokens: FootNoteToken[], index: number): string =>\n // add suffix when multiple id was found\n tokens[index].meta.subId > 0 ? `:${tokens[index].meta.subId}` : \"\";\n\nconst renderFootnoteAnchorName: RenderRule = (\n tokens: FootNoteToken[],\n index,\n _options,\n env: FootNoteEnv,\n): string =>\n `${\n // prefix\n typeof env.docId === \"string\" ? `-${env.docId}-` : \"\"\n }${\n // increasing id\n (tokens[index].meta.id + 1).toString()\n }`;\n\nconst renderFootnoteCaption: RenderRule = (tokens: FootNoteToken[], index): string =>\n `[${\n // number\n (tokens[index].meta.id + 1).toString()\n }${getIDSuffix(tokens, index)}]`;\n\nconst renderFootnoteRef: RenderRule = (\n tokens: FootNoteToken[],\n index,\n options,\n env: FootNoteEnv,\n self,\n): string => {\n // oxlint-disable-next-line typescript/no-non-null-assertion\n const id = self.rules.footnote_anchorName!(tokens, index, options, env, self);\n // oxlint-disable-next-line typescript/no-non-null-assertion\n const caption = self.rules.footnote_caption!(tokens, index, options, env, self);\n\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: RenderRule = (_tokens: FootNoteToken[], _index, options): string =>\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: RenderRule = (\n tokens: FootNoteToken[],\n index,\n options,\n env: FootNoteEnv,\n self,\n): string =>\n // oxlint-disable-next-line typescript/no-non-null-assertion\n `<li id=\"footnote${self.rules.footnote_anchorName!(\n tokens,\n index,\n options,\n env,\n self,\n )}${getIDSuffix(tokens, index)}\" class=\"footnote-item\">`;\n\nconst renderFootnoteClose = (): string => \"</li>\\n\";\n\nconst renderFootnoteAnchor: RenderRule = (\n tokens: FootNoteToken[],\n index,\n options,\n env: FootNoteEnv,\n self,\n): string =>\n // oxlint-disable-next-line typescript/no-non-null-assertion\n ` <a href=\"#footnote-ref${self.rules.footnote_anchorName!(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: RuleBlock = (state: FootNoteStateBlock, startLine, endLine, silent) => {\n const start = state.bMarks[startLine] + state.tShift[startLine];\n const max = state.eMarks[startLine];\n let char: 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 char = state.src.charCodeAt(pos);\n if (char === 32 /* space */) return false;\n\n if (char === 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 // oxlint-disable-next-line typescript/no-unnecessary-condition\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 const char = state.src.charCodeAt(pos);\n\n if (char === 9 /* \\t */) offset += 4 - (offset % 4);\n else if (char === 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\" as unknown as ParentType;\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: RuleInline = (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 if (!silent) {\n // oxlint-disable-next-line typescript/no-unnecessary-condition\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: RuleInline = (state: FootNoteStateInline, silent) => {\n const start = state.pos;\n const max = state.posMax;\n let char: number;\n\n if (\n // should be at least 4 chars - \"[^x]\"\n start + 3 > max ||\n // oxlint-disable-next-line typescript/no-unnecessary-condition\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\n while (pos < max) {\n char = state.src.charCodeAt(pos);\n if (char === 32 /* space */ || char === 10 /* \\n */) return false;\n\n if (char === 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 (state.env.footnotes.refs[`:${label}`] === undefined) return false;\n\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: RuleCore = (state: FootNoteStateCore): boolean => {\n const refTokens: Record<string, Token[]> = {};\n\n let current: Token[];\n let currentLabel: string;\n let isInsideRef = false;\n\n // oxlint-disable-next-line typescript/no-unnecessary-condition\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 false;\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.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 for (let index = 0, { length } = list; index < length; 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 let lastParagraph: FootNoteToken | null;\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 if (list[index].label) {\n // oxlint-disable-next-line typescript/no-non-null-assertion\n const tokens = refTokens[`:${list[index].label!}`];\n\n // oxlint-disable-next-line typescript/no-unnecessary-condition\n if (tokens) state.tokens.push(...tokens);\n }\n\n if (state.tokens[state.tokens.length - 1].type === \"paragraph_close\")\n lastParagraph = state.tokens.pop() ?? null;\n else lastParagraph = null;\n\n for (\n let j = 0;\n // oxlint-disable-next-line typescript/no-non-null-assertion\n j < (Number(list[index].count) > 0 ? list[index].count! : 1);\n j++\n ) {\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 return true;\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_anchorName = 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":"AAgCA,MAAM,GAAe,EAAyB,IAE5C,EAAO,GAAO,KAAK,MAAQ,EAAI,IAAI,EAAO,GAAO,KAAK,QAAU,GAE5D,GACJ,EACA,EACA,EACA,IAEA,GAEE,OAAO,EAAI,OAAU,SAAW,IAAI,EAAI,MAAM,GAAK,MAGlD,EAAO,GAAO,KAAK,GAAK,GAAG,UAAU,GAGpC,GAAqC,EAAyB,IAClE,KAEG,EAAO,GAAO,KAAK,GAAK,GAAG,UAAU,GACrC,EAAY,EAAQ,EAAM,CAAC,GAE1B,GACJ,EACA,EACA,EACA,EACA,IACW,CAEX,IAAM,EAAK,EAAK,MAAM,oBAAqB,EAAQ,EAAO,EAAS,EAAK,EAAK,CAI7E,MAAO,+CAA+C,EAAG,IAFzC,EAAK,MAAM,iBAAkB,EAAQ,EAAO,EAAS,EAAK,EAAK,CAEV,iDAAiD,IAAK,EACzH,EACA,EACD,CAAC,eAGE,GAAuC,EAA0B,EAAQ,IAC7E;2BACyB,EAAQ,SAAW,KAAO,GAAG;;;EAKlD,MAAyC;;EAKzC,GACJ,EACA,EACA,EACA,EACA,IAGA,mBAAmB,EAAK,MAAM,oBAC5B,EACA,EACA,EACA,EACA,EACD,GAAG,EAAY,EAAQ,EAAM,CAAC,0BAE3B,MAAoC;EAEpC,GACJ,EACA,EACA,EACA,EACA,IAGA,0BAA0B,EAAK,MAAM,oBAAqB,EAAQ,EAAO,EAAS,EAAK,EAAK,GAC1F,EAAY,EAAQ,EAAM,CAE3B,6CAGG,GAA0B,EAA2B,EAAW,EAAS,IAAW,CACxF,IAAM,EAAQ,EAAM,OAAO,GAAa,EAAM,OAAO,GAC/C,EAAM,EAAM,OAAO,GACrB,EAE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