@mdit/plugin-footnote 0.16.6-cjs.0 → 0.16.8
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/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/package.json +2 -1
package/lib/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
const b=(e,t)=>e[t].meta.subId>0?`:${e[t].meta.subId}`:"",$=(e,t,l,f)=>`${typeof f.docId=="string"?`-${f.docId}-`:""}${(e[t].meta.id+1).toString()}`,v=(e,t)=>`[${(e[t].meta.id+1).toString()}${b(e,t)}]`,g=(e,t,l,f,n)=>{const s=n.rules.footnote_anchorName(e,t,l,f,n),r=n.rules.footnote_caption(e,t,l,f,n);return`<sup class="footnote-ref"><a href="#footnote${s}">${r}</a><a class="footnote-anchor" id="footnote-ref${s}${b(e,t)}"></a></sup>`},A=(e,t,l)=>`<hr class="footnotes-sep"${l.xhtmlOut?" /":""}>
|
|
2
2
|
<section class="footnotes">
|
|
3
3
|
<ol class="footnotes-list">
|
|
4
4
|
`,I=()=>`</ol>
|
|
5
5
|
</section>
|
|
6
6
|
`,T=(e,t,l,f,n)=>`<li id="footnote${n.rules.footnote_anchorName(e,t,l,f,n)}${b(e,t)}" class="footnote-item">`,M=()=>`</li>
|
|
7
7
|
`,w=(e,t,l,f,n)=>` <a href="#footnote-ref${n.rules.footnote_anchorName(e,t,l,f,n)}${b(e,t)}" class="footnote-backref">↩︎</a>`,y=(e,t,l,f)=>{const n=e.bMarks[t]+e.tShift[t],s=e.eMarks[t];if(n+4>s||e.src.charAt(n)!=="["||e.src.charAt(n+1)!=="^")return!1;let r=n+2;for(;r<s;){if(e.src.charAt(r)===" ")return!1;if(e.src.charAt(r)==="]")break;r++}if(r===n+2||r+1>=s||e.src.charAt(++r)!==":")return!1;if(f)return!0;r++,(e.env.footnotes??={}).refs??={};const o=e.src.slice(n+2,r-2);e.env.footnotes.refs[`:${o}`]=-1;const c=e.push("footnote_reference_open","",1);c.meta={label:o},c.level=e.level++;const p=e.bMarks[t],u=e.tShift[t],a=e.sCount[t],i=e.parentType,h=r,d=e.sCount[t]+r-(e.bMarks[t]+e.tShift[t]);let k=e.sCount[t]+r-(e.bMarks[t]+e.tShift[t]);for(;r<s;){const _=e.src.charAt(r);if(_===" ")k+=4-k%4;else if(_===" ")k++;else break;r++}e.tShift[t]=r-h,e.sCount[t]=k-d,e.bMarks[t]=h,e.blkIndent+=4,e.parentType="footnote",e.sCount[t]<e.blkIndent&&(e.sCount[t]+=e.blkIndent),e.md.block.tokenize(e,t,l),e.parentType=i,e.blkIndent-=4,e.tShift[t]=u,e.sCount[t]=a,e.bMarks[t]=p;const m=e.push("footnote_reference_close","",-1);return m.level=--e.level,!0},S=(e,t)=>{const l=e.posMax,f=e.pos;if(f+2>=l||e.src.charAt(f)!=="^"||e.src.charAt(f+1)!=="[")return!1;const n=e.md.helpers.parseLinkLabel(e,f+1);if(n<0)return!1;const s=f+2;if(!t){const r=((e.env.footnotes??={}).list??=[]).length,o=[];e.md.inline.parse(e.src.slice(s,n),e.md,e.env,o);const c=e.push("footnote_ref","",0);c.meta={id:r},e.env.footnotes.list[r]={content:e.src.slice(s,n),tokens:o}}return e.pos=n+1,e.posMax=l,!0},C=(e,t)=>{const l=e.pos,f=e.posMax;if(l+3>f||!e.env.footnotes?.refs||e.src.charAt(l)!=="["||e.src.charAt(l+1)!=="^")return!1;let n=l+2;for(;n<f;){if(e.src.charAt(n)===" "||e.src.charAt(n)===`
|
|
8
|
-
`)return!1;if(e.src.charAt(n)==="]")break;n++}if(n===l+2||n>=f)return!1;n++;const s=e.src.slice(l+2,n-1);if(typeof e.env.footnotes.refs[`:${s}`]>"u")return!1;if(!t){const r=e.env.footnotes.list??=[],{refs:o}=e.env.footnotes;let c;o[`:${s}`]<0?(c=r.length,r[c]={label:s,count:0},o[`:${s}`]=c):c=o[`:${s}`];const p=r[c].count;r[c].count=r[c].count+1;const u=e.push("footnote_ref","",0);u.meta={id:c,subId:p,label:s}}return e.pos=n,e.posMax=f,!0},
|
|
8
|
+
`)return!1;if(e.src.charAt(n)==="]")break;n++}if(n===l+2||n>=f)return!1;n++;const s=e.src.slice(l+2,n-1);if(typeof e.env.footnotes.refs[`:${s}`]>"u")return!1;if(!t){const r=e.env.footnotes.list??=[],{refs:o}=e.env.footnotes;let c;o[`:${s}`]<0?(c=r.length,r[c]={label:s,count:0},o[`:${s}`]=c):c=o[`:${s}`];const p=r[c].count;r[c].count=r[c].count+1;const u=e.push("footnote_ref","",0);u.meta={id:c,subId:p,label:s}}return e.pos=n,e.posMax=f,!0},x=e=>{const t={};let l,f,n=!1;if(!e.env.footnotes?.list)return!1;const{list:s}=e.env.footnotes;e.tokens=e.tokens.filter(o=>o.type==="footnote_reference_open"?(n=!0,l=[],f=o.meta.label,!1):o.type==="footnote_reference_close"?(n=!1,t[`:${f}`]=l,!1):(n&&l.push(o),!n));const r=new e.Token("footnote_block_open","",1);e.tokens.push(r);for(let o=0,{length:c}=s;o<c;o++){const p=new e.Token("footnote_open","",1);p.meta={id:o,label:s[o].label},e.tokens.push(p);let u;if(s[o].tokens){const a=new e.Token("paragraph_open","p",1);a.block=!0;const i=new e.Token("inline","",0);i.children=s[o].tokens,i.content=s[o].content;const h=new e.Token("paragraph_close","p",-1);h.block=!0,e.tokens.push(a,i,h)}else if(s[o].label){const a=t[`:${s[o].label}`];a&&e.tokens.push(...a)}e.tokens[e.tokens.length-1].type==="paragraph_close"?u=e.tokens.pop()??null:u=null;for(let a=0;a<(Number(s[o].count)>0?s[o].count:1);a++){const i=new e.Token("footnote_anchor","",0);i.meta={id:o,subId:a,label:s[o].label},e.tokens.push(i)}u&&e.tokens.push(u),e.tokens.push(new e.Token("footnote_close","",-1))}return e.tokens.push(new e.Token("footnote_block_close","",-1)),!0},N=e=>{e.renderer.rules.footnote_ref=g,e.renderer.rules.footnote_block_open=A,e.renderer.rules.footnote_block_close=I,e.renderer.rules.footnote_open=T,e.renderer.rules.footnote_close=M,e.renderer.rules.footnote_anchor=w,e.renderer.rules.footnote_caption=v,e.renderer.rules.footnote_anchorName=$,e.block.ruler.before("reference","footnoteDef",y,{alt:["paragraph","reference"]}),e.inline.ruler.after("image","footnoteInline",S),e.inline.ruler.after("footnoteInline","footnote_ref",C),e.core.ruler.after("inline","footnoteTail",x)};export{N as footnote};
|
|
9
9
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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 )}\" /></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\n if (\n // line should be at least 5 chars - \"[^x]:\"\n start + 4 > max ||\n state.src.charAt(start) !== \"[\" ||\n state.src.charAt(start + 1) !== \"^\"\n )\n return false;\n\n let pos = start + 2;\n\n while (pos < max) {\n if (state.src.charAt(pos) === \" \") return false;\n if (state.src.charAt(pos) === \"]\") break;\n pos++;\n }\n\n if (\n // empty footnote label\n pos === start + 2 ||\n pos + 1 >= max ||\n state.src.charAt(++pos) !== \":\"\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 =\n state.sCount[startLine] +\n pos -\n (state.bMarks[startLine] + state.tShift[startLine]);\n\n while (pos < max) {\n const char = state.src.charAt(pos);\n\n if (char === \"\\t\") offset += 4 - (offset % 4);\n else if (char === \" \") offset++;\n else break;\n\n pos++;\n }\n\n state.tShift[startLine] = pos - posAfterColon;\n state.sCount[startLine] = offset - initial;\n\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.charAt(start) !== \"^\" ||\n state.src.charAt(start + 1) !== \"[\"\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\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.charAt(start) !== \"[\" ||\n state.src.charAt(start + 1) !== \"^\"\n )\n return false;\n\n let pos = start + 2;\n\n while (pos < max) {\n if (state.src.charAt(pos) === \" \" || state.src.charAt(pos) === \"\\n\")\n return false;\n if (state.src.charAt(pos) === \"]\") break;\n pos++;\n }\n\n if (\n // empty footnote labels\n pos === start + 2 ||\n pos >= max\n )\n 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 insideRef = false;\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!state.env.footnotes?.list) return false;\n\n const { list } = state.env.footnotes;\n\n state.tokens = state.tokens.filter((stateToken) => {\n if (stateToken.type === \"footnote_reference_open\") {\n insideRef = true;\n current = [];\n currentLabel = stateToken.meta.label;\n\n return false;\n }\n\n if (stateToken.type === \"footnote_reference_close\") {\n insideRef = false;\n // prepend ':' to avoid conflict with Object.prototype members\n refTokens[`:${currentLabel}`] = current;\n\n return false;\n }\n if (insideRef) current.push(stateToken);\n\n return !insideRef;\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","pos","label","referenceOpenToken","oldBMark","oldTShift","oldSCount","oldParentType","posAfterColon","initial","offset","char","referenceCloseToken","footnoteInline","labelEnd","labelStart","footnoteId","refToken","footnoteRef","list","refs","subId","footnoteTail","refTokens","current","currentLabel","insideRef","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,EACAE,EACAC,IAEA,GAEE,OAAOA,EAAI,OAAU,SAAW,IAAIA,EAAI,KAAK,IAAM,EACrD,IAEGJ,EAA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K,CAAC,YAAa,WAAW,CAChC,CAAC,EACD4C,EAAG,OAAO,MAAM,MAAM,QAAS,iBAAkBzB,CAAc,EAC/DyB,EAAG,OAAO,MAAM,MAAM,iBAAkB,eAAgBpB,CAAW,EACnEoB,EAAG,KAAK,MAAM,MAAM,SAAU,eAAgBhB,CAAY,CAC5D"}
|
|
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\n if (\n // line should be at least 5 chars - \"[^x]:\"\n start + 4 > max ||\n state.src.charAt(start) !== \"[\" ||\n state.src.charAt(start + 1) !== \"^\"\n )\n return false;\n\n let pos = start + 2;\n\n while (pos < max) {\n if (state.src.charAt(pos) === \" \") return false;\n if (state.src.charAt(pos) === \"]\") break;\n pos++;\n }\n\n if (\n // empty footnote label\n pos === start + 2 ||\n pos + 1 >= max ||\n state.src.charAt(++pos) !== \":\"\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 =\n state.sCount[startLine] +\n pos -\n (state.bMarks[startLine] + state.tShift[startLine]);\n\n while (pos < max) {\n const char = state.src.charAt(pos);\n\n if (char === \"\\t\") offset += 4 - (offset % 4);\n else if (char === \" \") offset++;\n else break;\n\n pos++;\n }\n\n state.tShift[startLine] = pos - posAfterColon;\n state.sCount[startLine] = offset - initial;\n\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.charAt(start) !== \"^\" ||\n state.src.charAt(start + 1) !== \"[\"\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\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.charAt(start) !== \"[\" ||\n state.src.charAt(start + 1) !== \"^\"\n )\n return false;\n\n let pos = start + 2;\n\n while (pos < max) {\n if (state.src.charAt(pos) === \" \" || state.src.charAt(pos) === \"\\n\")\n return false;\n if (state.src.charAt(pos) === \"]\") break;\n pos++;\n }\n\n if (\n // empty footnote labels\n pos === start + 2 ||\n pos >= max\n )\n 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 insideRef = false;\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!state.env.footnotes?.list) return false;\n\n const { list } = state.env.footnotes;\n\n state.tokens = state.tokens.filter((stateToken) => {\n if (stateToken.type === \"footnote_reference_open\") {\n insideRef = true;\n current = [];\n currentLabel = stateToken.meta.label;\n\n return false;\n }\n\n if (stateToken.type === \"footnote_reference_close\") {\n insideRef = false;\n // prepend ':' to avoid conflict with Object.prototype members\n refTokens[`:${currentLabel}`] = current;\n\n return false;\n }\n if (insideRef) current.push(stateToken);\n\n return !insideRef;\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","pos","label","referenceOpenToken","oldBMark","oldTShift","oldSCount","oldParentType","posAfterColon","initial","offset","char","referenceCloseToken","footnoteInline","labelEnd","labelStart","footnoteId","refToken","footnoteRef","list","refs","subId","footnoteTail","refTokens","current","currentLabel","insideRef","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,EACAE,EACAC,IAEA,GAEE,OAAOA,EAAI,OAAU,SAAW,IAAIA,EAAI,KAAK,IAAM,EACrD,IAEGJ,EAAOC,CAAK,EAAE,KAAK,GAAK,GAAG,SAAA,CAC9B,GAEII,EAAoC,CACxCL,EACAC,IAEA,KAEGD,EAAOC,CAAK,EAAE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AO,MAAM,MAAM,iBAAkB,eAAgBpB,CAAW,EACnEoB,EAAG,KAAK,MAAM,MAAM,SAAU,eAAgBhB,CAAY,CAC5D"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdit/plugin-footnote",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.8",
|
|
4
4
|
"description": "footnote plugin for MarkdownIt",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown-it",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"email": "mister-hope@outlook.com",
|
|
23
23
|
"url": "https://mister-hope.com"
|
|
24
24
|
},
|
|
25
|
+
"type": "module",
|
|
25
26
|
"exports": {
|
|
26
27
|
".": {
|
|
27
28
|
"type": "./lib/index.ts",
|