@mdit/plugin-footnote 0.22.5-cjs.0 → 0.23.1
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.
- package/dist/cdn.umd.js +9 -0
- package/dist/cdn.umd.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/package.json +29 -17
- package/lib/index.d.ts +0 -32
- package/lib/index.js +0 -8
- package/lib/index.js.map +0 -1
package/dist/cdn.umd.js
ADDED
|
@@ -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,eAG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
4
|
+
//#region src/plugin.d.ts
|
|
5
|
+
declare const footnote: PluginSimple;
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/types.d.ts
|
|
8
|
+
interface FootNoteToken extends Token {
|
|
9
|
+
meta: {
|
|
10
|
+
id: number;
|
|
11
|
+
subId: number;
|
|
12
|
+
label: string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
interface FootNoteEnv extends Record<string, any> {
|
|
16
|
+
docId?: string;
|
|
17
|
+
footnotes: {
|
|
18
|
+
label?: string;
|
|
19
|
+
refs?: Record<string, number>;
|
|
20
|
+
list?: {
|
|
21
|
+
label?: string;
|
|
22
|
+
count?: number;
|
|
23
|
+
content?: string;
|
|
24
|
+
tokens?: Token[] | null;
|
|
25
|
+
}[];
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { FootNoteEnv, FootNoteToken, footnote };
|
|
30
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -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,KA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AM,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,32 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdit/plugin-footnote",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.1",
|
|
4
4
|
"description": "footnote plugin for MarkdownIt",
|
|
5
5
|
"keywords": [
|
|
6
|
+
"footnote",
|
|
6
7
|
"markdown-it",
|
|
7
|
-
"markdown-it-plugin"
|
|
8
|
-
"footnote"
|
|
8
|
+
"markdown-it-plugin"
|
|
9
9
|
],
|
|
10
10
|
"homepage": "https://mdit-plugins.github.io/footnote.html",
|
|
11
11
|
"bugs": {
|
|
12
12
|
"url": "https://github.com/mdit-plugins/mdit-plugins/issues"
|
|
13
13
|
},
|
|
14
|
-
"repository": {
|
|
15
|
-
"type": "git",
|
|
16
|
-
"url": "git+https://github.com/mdit-plugins/mdit-plugins.git",
|
|
17
|
-
"directory": "packages/footnote"
|
|
18
|
-
},
|
|
19
14
|
"license": "MIT",
|
|
20
15
|
"author": {
|
|
21
16
|
"name": "Mr.Hope",
|
|
22
17
|
"email": "mister-hope@outlook.com",
|
|
23
18
|
"url": "https://mister-hope.com"
|
|
24
19
|
},
|
|
25
|
-
"
|
|
26
|
-
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/mdit-plugins/mdit-plugins.git",
|
|
23
|
+
"directory": "packages/footnote"
|
|
24
|
+
},
|
|
27
25
|
"files": [
|
|
28
|
-
"
|
|
26
|
+
"dist"
|
|
29
27
|
],
|
|
28
|
+
"type": "module",
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"unpkg": "./dist/cdn.umd.js",
|
|
31
|
+
"jsdelivr": "./dist/cdn.umd.js",
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"default": "./dist/index.js"
|
|
36
|
+
},
|
|
37
|
+
"./package.json": "./package.json"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
30
42
|
"dependencies": {
|
|
31
43
|
"@types/markdown-it": "^14.1.2"
|
|
32
44
|
},
|
|
@@ -34,10 +46,10 @@
|
|
|
34
46
|
"markdown-it": "^14.1.0"
|
|
35
47
|
},
|
|
36
48
|
"engines": {
|
|
37
|
-
"node": ">=
|
|
38
|
-
},
|
|
39
|
-
"publishConfig": {
|
|
40
|
-
"access": "public"
|
|
49
|
+
"node": ">= 20"
|
|
41
50
|
},
|
|
42
|
-
"
|
|
43
|
-
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "tsdown --config-loader unrun",
|
|
53
|
+
"clean": "rimraf ./dist"
|
|
54
|
+
}
|
|
55
|
+
}
|
package/lib/index.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { PluginSimple } from 'markdown-it';
|
|
2
|
-
import Token from 'markdown-it/lib/token.mjs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Forked from https://github.com/markdown-it/markdown-it-footnote/blob/master/index.mjs
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
declare const footnote: PluginSimple;
|
|
9
|
-
|
|
10
|
-
interface FootNoteToken extends Token {
|
|
11
|
-
meta: {
|
|
12
|
-
id: number;
|
|
13
|
-
subId: number;
|
|
14
|
-
label: string;
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
interface FootNoteEnv extends Record<any, any> {
|
|
18
|
-
docId?: string;
|
|
19
|
-
footnotes: {
|
|
20
|
-
label?: string;
|
|
21
|
-
refs?: Record<string, number>;
|
|
22
|
-
list?: {
|
|
23
|
-
label?: string;
|
|
24
|
-
count?: number;
|
|
25
|
-
content?: string;
|
|
26
|
-
tokens?: Token[] | null;
|
|
27
|
-
}[];
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export { footnote };
|
|
32
|
-
export type { FootNoteEnv, FootNoteToken };
|
package/lib/index.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";const d=(e,n)=>e[n].meta.subId>0?`:${e[n].meta.subId}`:"",C=(e,n,r,l)=>`${typeof l.docId=="string"?`-${l.docId}-`:""}${(e[n].meta.id+1).toString()}`,v=(e,n)=>`[${(e[n].meta.id+1).toString()}${d(e,n)}]`,g=(e,n,r,l,o)=>{const s=o.rules.footnote_anchorName(e,n,r,l,o),f=o.rules.footnote_caption(e,n,r,l,o);return`<sup class="footnote-ref"><a href="#footnote${s}">${f}</a><a class="footnote-anchor" id="footnote-ref${s}${d(e,n)}"></a></sup>`},I=(e,n,r)=>`<hr class="footnotes-sep"${r.xhtmlOut?" /":""}>
|
|
2
|
-
<section class="footnotes">
|
|
3
|
-
<ol class="footnotes-list">
|
|
4
|
-
`,T=()=>`</ol>
|
|
5
|
-
</section>
|
|
6
|
-
`,y=(e,n,r,l,o)=>`<li id="footnote${o.rules.footnote_anchorName(e,n,r,l,o)}${d(e,n)}" class="footnote-item">`,A=()=>`</li>
|
|
7
|
-
`,M=(e,n,r,l,o)=>` <a href="#footnote-ref${o.rules.footnote_anchorName(e,n,r,l,o)}${d(e,n)}" class="footnote-backref">↩︎</a>`,w=(e,n,r,l)=>{const o=e.bMarks[n]+e.tShift[n],s=e.eMarks[n];let f;if(o+4>s||e.src.charCodeAt(o)!==91||e.src.charCodeAt(o+1)!==94)return!1;let t=o+2;for(;t<s;){if(f=e.src.charCodeAt(t),f===32)return!1;if(f===93)break;t++}if(t===o+2||t+1>=s||e.src.charCodeAt(++t)!==58)return!1;if(l)return!0;t++,(e.env.footnotes??={}).refs??={};const u=e.src.slice(o+2,t-2);e.env.footnotes.refs[`:${u}`]=-1;const c=e.push("footnote_reference_open","",1);c.meta={label:u},c.level=e.level++;const i=e.bMarks[n],a=e.tShift[n],p=e.sCount[n],k=e.parentType,_=t,b=e.sCount[n]+t-(e.bMarks[n]+e.tShift[n]);let h=b;for(;t<s;){const m=e.src.charCodeAt(t);if(m===9)h+=4-h%4;else if(m===32)h++;else break;t++}e.tShift[n]=t-_,e.sCount[n]=h-b,e.bMarks[n]=_,e.blkIndent+=4,e.parentType="footnote",e.sCount[n]<e.blkIndent&&(e.sCount[n]+=e.blkIndent),e.md.block.tokenize(e,n,r),e.parentType=k,e.blkIndent-=4,e.tShift[n]=a,e.sCount[n]=p,e.bMarks[n]=i;const $=e.push("footnote_reference_close","",-1);return $.level=--e.level,!0},S=(e,n)=>{const r=e.posMax,l=e.pos;if(l+2>=r||e.src.charCodeAt(l)!==94||e.src.charCodeAt(l+1)!==91)return!1;const o=e.md.helpers.parseLinkLabel(e,l+1);if(o<0)return!1;const s=l+2;if(!n){const f=((e.env.footnotes??={}).list??=[]).length,t=[];e.md.inline.parse(e.src.slice(s,o),e.md,e.env,t);const u=e.push("footnote_ref","",0);u.meta={id:f},e.env.footnotes.list[f]={content:e.src.slice(s,o),tokens:t}}return e.pos=o+1,e.posMax=r,!0},N=(e,n)=>{const r=e.pos,l=e.posMax;let o;if(r+3>l||!e.env.footnotes?.refs||e.src.charCodeAt(r)!==91||e.src.charCodeAt(r+1)!==94)return!1;let s=r+2;for(;s<l;){if(o=e.src.charCodeAt(s),o===32||o===10)return!1;if(o===93)break;s++}if(s===r+2||s>=l)return!1;s++;const f=e.src.slice(r+2,s-1);if(typeof e.env.footnotes.refs[`:${f}`]>"u")return!1;if(!n){const t=e.env.footnotes.list??=[],{refs:u}=e.env.footnotes;let c;u[`:${f}`]<0?(c=t.length,t[c]={label:f,count:0},u[`:${f}`]=c):c=u[`:${f}`];const i=t[c].count;t[c].count=t[c].count+1;const a=e.push("footnote_ref","",0);a.meta={id:c,subId:i,label:f}}return e.pos=s,e.posMax=l,!0},x=e=>{const n={};let r,l,o=!1;if(!e.env.footnotes?.list)return e.tokens=e.tokens.filter(t=>t.type==="footnote_reference_open"?(o=!0,!1):t.type==="footnote_reference_close"?(o=!1,!1):!o),!1;const{list:s}=e.env.footnotes;e.tokens=e.tokens.filter(t=>t.type==="footnote_reference_open"?(o=!0,r=[],l=t.meta.label,!1):t.type==="footnote_reference_close"?(o=!1,n[`:${l}`]=r,!1):(o&&r.push(t),!o));const f=new e.Token("footnote_block_open","",1);e.tokens.push(f);for(let t=0,{length:u}=s;t<u;t++){const c=new e.Token("footnote_open","",1);c.meta={id:t,label:s[t].label},e.tokens.push(c);let i;if(s[t].tokens){const a=new e.Token("paragraph_open","p",1);a.block=!0;const p=new e.Token("inline","",0);p.children=s[t].tokens,p.content=s[t].content;const k=new e.Token("paragraph_close","p",-1);k.block=!0,e.tokens.push(a,p,k)}else if(s[t].label){const a=n[`:${s[t].label}`];a&&e.tokens.push(...a)}e.tokens[e.tokens.length-1].type==="paragraph_close"?i=e.tokens.pop()??null:i=null;for(let a=0;a<(Number(s[t].count)>0?s[t].count:1);a++){const p=new e.Token("footnote_anchor","",0);p.meta={id:t,subId:a,label:s[t].label},e.tokens.push(p)}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},L=e=>{e.renderer.rules.footnote_ref=g,e.renderer.rules.footnote_block_open=I,e.renderer.rules.footnote_block_close=T,e.renderer.rules.footnote_open=y,e.renderer.rules.footnote_close=A,e.renderer.rules.footnote_anchor=M,e.renderer.rules.footnote_caption=v,e.renderer.rules.footnote_anchorName=C,e.block.ruler.before("reference","footnoteDef",w,{alt:["paragraph","reference"]}),e.inline.ruler.after("image","footnoteInline",S),e.inline.ruler.after("footnoteInline","footnote_ref",N),e.core.ruler.after("inline","footnoteTail",x)};exports.footnote=L;
|
|
8
|
-
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","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 = (\n tokens: FootNoteToken[],\n index,\n): 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 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const id = self.rules.footnote_anchorName!(tokens, index, options, env, self);\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const caption = self.rules.footnote_caption!(\n tokens,\n index,\n options,\n env,\n self,\n );\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 = (\n _tokens: FootNoteToken[],\n _index,\n options,\n): 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 // eslint-disable-next-line @typescript-eslint/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 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n ` <a href=\"#footnote-ref${self.rules.footnote_anchorName!(\n tokens,\n index,\n options,\n env,\n self,\n )}${\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 = (\n state: FootNoteStateBlock,\n startLine,\n endLine,\n silent,\n) => {\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 if (char === 93 /* ] */) break;\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 pos++;\n\n // eslint-disable-next-line @typescript-eslint/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] +\n pos -\n (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)\n 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 // eslint-disable-next-line @typescript-eslint/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(\n state.src.slice(labelStart, labelEnd),\n state.md,\n state.env,\n tokens,\n );\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 // eslint-disable-next-line @typescript-eslint/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 if (char === 93 /* ] */) break;\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}`] === \"undefined\")\n 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 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const subId = list[footnoteId].count!;\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n list[footnoteId].count = 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 // eslint-disable-next-line @typescript-eslint/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 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n inlineToken.children = list[index].tokens!;\n // eslint-disable-next-line @typescript-eslint/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 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const tokens = refTokens[`:${list[index].label!}`];\n\n // eslint-disable-next-line @typescript-eslint/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 // eslint-disable-next-line @typescript-eslint/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"],"names":["getIDSuffix","tokens","index","renderFootnoteAnchorName","_options","env","renderFootnoteCaption","renderFootnoteRef","options","self","id","caption","renderFootnoteBlockOpen","_tokens","_index","renderFootnoteBlockClose","renderFootnoteOpen","renderFootnoteClose","renderFootnoteAnchor","footnoteDef","state","startLine","endLine","silent","start","max","char","pos","label","referenceOpenToken","oldBMark","oldTShift","oldSCount","oldParentType","posAfterColon","initial","offset","referenceCloseToken","footnoteInline","labelEnd","labelStart","footnoteId","refToken","footnoteRef","list","refs","subId","footnoteTail","refTokens","current","currentLabel","isInsideRef","stateToken","footnoteBlockOpenToken","length","footnoteOpenToken","lastParagraph","paragraphOpenToken","inlineToken","paragraphCloseToken","j","footnoteAnchorToken","footnote","md"],"mappings":"aAgCA,MAAMA,EAAc,CAACC,EAAyBC,IAE5CD,EAAOC,CAAK,EAAE,KAAK,MAAQ,EAAI,IAAID,EAAOC,CAAK,EAAE,KAAK,KAAK,GAAK,GAE5DC,EAAuC,CAC3CF,EACAC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