Files
website/node_modules/marked-footnote/dist/index.js
2024-05-06 17:15:30 -04:00

124 lines
3.3 KiB
JavaScript

function p(t, l) {
const o = {
type: "footnotes",
raw: l,
rawItems: [],
items: []
};
return {
name: "footnote",
level: "block",
childTokens: ["content"],
tokenizer(r) {
t.hasFootnotes || (this.lexer.tokens.push(o), t.tokens = this.lexer.tokens, t.hasFootnotes = !0, o.rawItems = [], o.items = []);
const e = /^\[\^([^\]\n]+)\]:(?:[ \t]+|[\n]*?|$)([^\n]*?(?:\n|$)(?:\n*?[ ]{4,}[^\n]*)*)/.exec(
r
);
if (e) {
const [n, i, h = ""] = e;
let f = h.split(`
`).reduce((c, s) => c + `
` + s.replace(/^(?:[ ]{4}|[\t])/, ""), "");
const u = f.trimEnd().split(`
`).pop();
f += // add lines after list, blockquote, codefence, and table
u && /^[ \t]*?[>\-\*][ ]|[`]{3,}$|^[ \t]*?[\|].+[\|]$/.test(
u
) ? `
` : "";
const a = {
type: "footnote",
raw: n,
label: i,
refs: [],
content: this.lexer.blockTokens(f)
};
return o.rawItems.push(a), a;
}
},
renderer() {
return "";
}
};
}
function $(t, l = !1) {
let o = 0;
return {
name: "footnoteRef",
level: "inline",
tokenizer(r) {
const e = /^\[\^([^\]\n]+)\]/.exec(r);
if (e) {
const [n, i] = e, h = this.lexer.tokens[0], f = h.rawItems.filter(
(s) => s.label === i
);
if (!f.length)
return;
const u = f[0], a = h.items.filter((s) => s.label === i)[0], c = {
type: "footnoteRef",
raw: n,
id: "",
label: i
};
return a ? (c.id = `${o}:${a.refs.length + 1}`, a.refs.push(c)) : (o++, c.id = String(o), u.refs.push(c), h.items.push(u)), c;
}
},
renderer({ id: r, label: e }) {
o = 0;
const n = encodeURIComponent(e);
return `<sup><a id="${t}ref-${n}" href="#${t + n}" data-${t}ref aria-describedby="${t}label">${l ? `[${r}]` : r}</a></sup>`;
}
};
}
function m(t) {
return {
name: "footnotes",
renderer({ raw: l, items: o = [] }) {
if (o.length === 0)
return "";
const r = o.reduce(
(n, { label: i, content: h, refs: f }) => {
const u = encodeURIComponent(i), a = this.parser.parse(h).trimEnd(), c = a.endsWith("</p>");
let s = `<li id="${t + u}">
`;
return s += c ? a.replace(/<\/p>$/, "") : a, f.forEach((k, d) => {
s += ` <a href="#${t}ref-${u}" data-${t}backref aria-label="Back to reference ${i}">${d > 0 ? `↩<sup>${d + 1}</sup>` : "↩"}</a>`;
}), s += c ? `</p>
` : `
`, s += `</li>
`, n + s;
},
""
);
let e = `<section class="footnotes" data-footnotes>
`;
return e += `<h2 id="${t}label" class="sr-only">${l.trimEnd()}</h2>
`, e += `<ol>
${r}</ol>
`, e += `</section>
`, e;
}
};
}
function b(t = {}) {
const {
prefixId: l = "footnote-",
description: o = "Footnotes",
refMarkers: r
} = t, e = { hasFootnotes: !1, tokens: [] };
return {
extensions: [
p(e, o),
$(l, r),
m(l)
],
walkTokens(n) {
n.type === "footnotes" && e.tokens.indexOf(n) === 0 && n.items.length && (e.tokens[0] = { type: "space", raw: "" }, e.tokens.push(n)), e.hasFootnotes && (e.hasFootnotes = !1);
}
};
}
export {
b as default
};