nizel-plugin-footnotes 0.1.10 → 0.1.11
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/footnotes.iife.js +253 -53
- package/package.json +1 -1
package/dist/footnotes.iife.js
CHANGED
|
@@ -1915,9 +1915,16 @@ var NizelFootnotes = (() => {
|
|
|
1915
1915
|
};
|
|
1916
1916
|
|
|
1917
1917
|
// ../nizel/dist/utils.js
|
|
1918
|
+
var htmlEntities = {
|
|
1919
|
+
"&": "&",
|
|
1920
|
+
"<": "<",
|
|
1921
|
+
">": ">",
|
|
1922
|
+
'"': """
|
|
1923
|
+
};
|
|
1924
|
+
var replaceHtmlEntity = (character) => htmlEntities[character];
|
|
1918
1925
|
var escapeHtml = (value) => {
|
|
1919
1926
|
const text = String(value);
|
|
1920
|
-
return /[&<>"]/.test(text) ? text.
|
|
1927
|
+
return /[&<>"]/.test(text) ? text.replace(/[&<>"]/g, replaceHtmlEntity) : text;
|
|
1921
1928
|
};
|
|
1922
1929
|
var slugify = (value, style = "github") => {
|
|
1923
1930
|
if (style === "classic") {
|
|
@@ -2067,6 +2074,10 @@ var NizelFootnotes = (() => {
|
|
|
2067
2074
|
...left.variables ?? {},
|
|
2068
2075
|
...right.variables ?? {}
|
|
2069
2076
|
},
|
|
2077
|
+
meta: {
|
|
2078
|
+
...left.meta ?? {},
|
|
2079
|
+
...right.meta ?? {}
|
|
2080
|
+
},
|
|
2070
2081
|
elements: {
|
|
2071
2082
|
...left.elements ?? {},
|
|
2072
2083
|
...right.elements ?? {}
|
|
@@ -2575,36 +2586,31 @@ var NizelFootnotes = (() => {
|
|
|
2575
2586
|
// ../nizel/dist/parse/emphasis.js
|
|
2576
2587
|
var resolveRemainingEmphasis = (nodes) => {
|
|
2577
2588
|
const tokens = tokenizeEmphasisDelimiters(nodes);
|
|
2578
|
-
let
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2589
|
+
for (let closeIndex = 0; closeIndex < tokens.length; closeIndex += 1) {
|
|
2590
|
+
const closer = tokens[closeIndex];
|
|
2591
|
+
if (closer.type !== "delimiter" || !closer.close || closer.length === 0)
|
|
2592
|
+
continue;
|
|
2593
|
+
for (let openIndex = closeIndex - 1; openIndex >= 0; openIndex -= 1) {
|
|
2594
|
+
const opener = tokens[openIndex];
|
|
2595
|
+
if (opener.type !== "delimiter" || !opener.open || opener.char !== closer.char || opener.length === 0) {
|
|
2584
2596
|
continue;
|
|
2585
|
-
for (let openIndex = closeIndex - 1; openIndex >= 0; openIndex -= 1) {
|
|
2586
|
-
const opener = tokens[openIndex];
|
|
2587
|
-
if (opener.type !== "delimiter" || !opener.open || opener.char !== closer.char || opener.length === 0) {
|
|
2588
|
-
continue;
|
|
2589
|
-
}
|
|
2590
|
-
if (isForbiddenDelimiterMatch(opener, closer))
|
|
2591
|
-
continue;
|
|
2592
|
-
const size = opener.length >= 2 && closer.length >= 2 ? 2 : 1;
|
|
2593
|
-
const children = inlineTokensToNodes(tokens.slice(openIndex + 1, closeIndex));
|
|
2594
|
-
const wrapped = size === 2 ? { type: "strong", children: resolveRemainingEmphasis(children) } : { type: "emphasis", children: resolveRemainingEmphasis(children) };
|
|
2595
|
-
const replacement = [];
|
|
2596
|
-
if (opener.length > size) {
|
|
2597
|
-
replacement.push({ ...opener, length: opener.length - size });
|
|
2598
|
-
}
|
|
2599
|
-
replacement.push({ type: "node", node: wrapped });
|
|
2600
|
-
if (closer.length > size) {
|
|
2601
|
-
replacement.push({ ...closer, length: closer.length - size });
|
|
2602
|
-
}
|
|
2603
|
-
tokens.splice(openIndex, closeIndex - openIndex + 1, ...replacement);
|
|
2604
|
-
changed = true;
|
|
2605
|
-
closeIndex = -1;
|
|
2606
|
-
break;
|
|
2607
2597
|
}
|
|
2598
|
+
if (isForbiddenDelimiterMatch(opener, closer))
|
|
2599
|
+
continue;
|
|
2600
|
+
const size = opener.length >= 2 && closer.length >= 2 ? 2 : 1;
|
|
2601
|
+
const children = inlineTokensToNodes(tokens.slice(openIndex + 1, closeIndex));
|
|
2602
|
+
const wrapped = size === 2 ? { type: "strong", children: resolveRemainingEmphasis(children) } : { type: "emphasis", children: resolveRemainingEmphasis(children) };
|
|
2603
|
+
const replacement = [];
|
|
2604
|
+
if (opener.length > size) {
|
|
2605
|
+
replacement.push({ ...opener, length: opener.length - size });
|
|
2606
|
+
}
|
|
2607
|
+
replacement.push({ type: "node", node: wrapped });
|
|
2608
|
+
if (closer.length > size) {
|
|
2609
|
+
replacement.push({ ...closer, length: closer.length - size });
|
|
2610
|
+
}
|
|
2611
|
+
tokens.splice(openIndex, closeIndex - openIndex + 1, ...replacement);
|
|
2612
|
+
closeIndex = openIndex - 1;
|
|
2613
|
+
break;
|
|
2608
2614
|
}
|
|
2609
2615
|
}
|
|
2610
2616
|
return inlineTokensToNodes(tokens);
|
|
@@ -2973,12 +2979,19 @@ var NizelFootnotes = (() => {
|
|
|
2973
2979
|
};
|
|
2974
2980
|
|
|
2975
2981
|
// ../nizel/dist/parse/inline.js
|
|
2982
|
+
var inlineTokenPatternWithoutBareEmail = new RegExp("(?<inlineHtml><!-->|<!--->|<!--[\\s\\S]*?-->|<\\?[\\s\\S]*?\\?>|<![A-Z][^>]*>|<!\\[CDATA\\[[\\s\\S]*?\\]\\]>|<\\/?[A-Za-z][A-Za-z0-9-]*(?:\\s+[A-Za-z_:][A-Za-z0-9_.:-]*(?:\\s*=\\s*(?:\"[^\"]*\"|'[^']*'|[^\\s\"'=<>`]+))?)*\\s*\\/?>)|(?<hardSpaces> {2,}\\n)|(?<hardBackslash>\\\\\\n)|(?<softBreak>\\n)|(?<!`)(?<codeTicks>`+)(?!`)(?<codeValue>[\\s\\S]*?)(?<!`)\\k<codeTicks>(?!`)|\\\\(?<escaped>[!\"#$%&'()*+,\\-./:;<=>?@[\\\\\\]^_`{|}~])|&(?<entity>[A-Za-z][A-Za-z0-9]+|#[0-9]+|#[xX][0-9A-Fa-f]+);|!\\[(?<refImageAlt>[^\\]]*)\\]\\[(?<refImageLabel>[^\\]]*)\\]|\\[(?<refLinkText>[^\\]`<\\[]+)\\]\\[(?<refLinkLabel>[^\\]]*)\\]|!\\[(?<inlineImageAlt>[^\\]`<]*)\\]\\([ \\t\\n]*(?<inlineImageHref><[^<>\\n\\\\]*>|(?!<)(?:\\\\.|[^() \\t\\n`\\\\]|\\([^()\\n]*(?:\\([^()\\n]*\\)[^()\\n]*)*\\))*)(?:[ \\t\\n]+(?:\"(?<inlineImageTitle>(?:\\\\.|[^\"`])*)\"|'(?<inlineImageTitleSingle>[^']*)'|\\((?<inlineImageTitleParen>[^)]*)\\)))?[ \\t\\n]*\\)|\\[(?<inlineLinkText>[^\\]`<]*)\\]\\([ \\t\\n]*(?<inlineLinkHref><[^<>\\n\\\\]*>|(?!<)(?:\\\\.|[^() \\t\\n`\\\\]|\\([^()\\n]*(?:\\([^()\\n]*\\)[^()\\n]*)*\\))*)(?:[ \\t\\n]+(?:\"(?<inlineLinkTitle>(?:\\\\.|[^\"`])*)\"|'(?<inlineLinkTitleSingle>[^']*)'|\\((?<inlineLinkTitleParen>[^)]*)\\)))?[ \\t\\n]*\\)|<(?<angleUrl>[A-Za-z][A-Za-z0-9+.-]{1,31}:[^<>\\s]*)>|<(?<angleEmail>[A-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?(?:\\.[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?)*)>|!\\[(?<shortcutImageAlt>(?:\\\\\\]|[^\\]`<\\[])+)\\]|\\[(?<shortcutLinkText>(?:\\\\\\]|[^\\]`<\\[])+)\\]|~~(?<deleteValue>[^~`]+)~~|(?<bareUrl>https?:\\/\\/[^\\s<`]+)", "giu");
|
|
2983
|
+
var bareEmailPattern = /(?<bareEmail>[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,})/giu;
|
|
2984
|
+
var inlineTokenPatternWithBareEmail = new RegExp(inlineTokenPatternWithoutBareEmail.source + "|" + bareEmailPattern.source, inlineTokenPatternWithoutBareEmail.flags);
|
|
2976
2985
|
var parseInline = (source, options = { autolinks: true }) => parseInlineWithState(source, options, { references: /* @__PURE__ */ new Map() });
|
|
2977
2986
|
var parseInlineWithState = (source, options = { autolinks: true }, state, extractNestedLinks = true) => {
|
|
2978
2987
|
const autolinks = options.autolinks !== false && getAutolinkOptions(options.autolinks).enabled !== false;
|
|
2979
2988
|
if (!hasInlineSyntax(source, autolinks)) {
|
|
2980
2989
|
return source ? [{ type: "text", value: source }] : [];
|
|
2981
2990
|
}
|
|
2991
|
+
const hasAtSign = source.includes("@");
|
|
2992
|
+
if (!hasAtSign && !hasNonEmphasisSyntax(source)) {
|
|
2993
|
+
return resolveRemainingEmphasis([{ type: "text", value: source }]);
|
|
2994
|
+
}
|
|
2982
2995
|
if (extractNestedLinks && hasBalancedLinkCandidate(source)) {
|
|
2983
2996
|
const scanned = scanBalancedInlineLinks(source, options, state);
|
|
2984
2997
|
if (scanned)
|
|
@@ -2986,10 +2999,14 @@ var NizelFootnotes = (() => {
|
|
|
2986
2999
|
}
|
|
2987
3000
|
const nodes = [];
|
|
2988
3001
|
const safe = options.safe !== false;
|
|
2989
|
-
const pattern =
|
|
3002
|
+
const pattern = hasAtSign ? inlineTokenPatternWithBareEmail : inlineTokenPatternWithoutBareEmail;
|
|
2990
3003
|
let lastIndex = 0;
|
|
2991
|
-
|
|
2992
|
-
|
|
3004
|
+
while (true) {
|
|
3005
|
+
pattern.lastIndex = lastIndex;
|
|
3006
|
+
const match = pattern.exec(source);
|
|
3007
|
+
if (!match)
|
|
3008
|
+
break;
|
|
3009
|
+
const end = pattern.lastIndex;
|
|
2993
3010
|
if (match.index > lastIndex) {
|
|
2994
3011
|
nodes.push({ type: "text", value: source.slice(lastIndex, match.index) });
|
|
2995
3012
|
}
|
|
@@ -3123,7 +3140,7 @@ var NizelFootnotes = (() => {
|
|
|
3123
3140
|
} else {
|
|
3124
3141
|
nodes.push({ type: "text", value: match[0] });
|
|
3125
3142
|
}
|
|
3126
|
-
lastIndex =
|
|
3143
|
+
lastIndex = end;
|
|
3127
3144
|
}
|
|
3128
3145
|
if (lastIndex < source.length)
|
|
3129
3146
|
nodes.push({ type: "text", value: source.slice(lastIndex) });
|
|
@@ -3136,6 +3153,9 @@ var NizelFootnotes = (() => {
|
|
|
3136
3153
|
return true;
|
|
3137
3154
|
return autolinks && (source.includes("http://") || source.includes("https://") || source.includes("@"));
|
|
3138
3155
|
};
|
|
3156
|
+
var hasNonEmphasisSyntax = (source) => {
|
|
3157
|
+
return /[`<&\n[~\\]|https?:\/\//i.test(source);
|
|
3158
|
+
};
|
|
3139
3159
|
var hasBalancedLinkCandidate = (source) => {
|
|
3140
3160
|
return source.includes("[");
|
|
3141
3161
|
};
|
|
@@ -3562,7 +3582,7 @@ ${line}`) !== null;
|
|
|
3562
3582
|
function parseMarkdown(markdown, options) {
|
|
3563
3583
|
const normalizedMarkdown = markdown.includes("\r") ? markdown.replace(/\r\n?/g, "\n") : markdown;
|
|
3564
3584
|
const lines = normalizedMarkdown.includes(" ") ? expandLeadingTabsToLines(normalizedMarkdown) : normalizedMarkdown.split("\n");
|
|
3565
|
-
const { contentLines, references } = normalizedMarkdown.includes("
|
|
3585
|
+
const { contentLines, references } = normalizedMarkdown.includes("]:") && hasPossibleReferenceDefinitionStart(normalizedMarkdown) ? extractReferenceDefinitions(lines) : { contentLines: lines, references: /* @__PURE__ */ new Map() };
|
|
3566
3586
|
const children = parseBlocks(contentLines, options, /* @__PURE__ */ new Map(), { references });
|
|
3567
3587
|
return { type: "root", children };
|
|
3568
3588
|
}
|
|
@@ -3573,7 +3593,8 @@ ${line}`) !== null;
|
|
|
3573
3593
|
const children = [];
|
|
3574
3594
|
for (let index = 0; index < lines.length; index += 1) {
|
|
3575
3595
|
const line = lines[index];
|
|
3576
|
-
|
|
3596
|
+
const trimmed = line.trim();
|
|
3597
|
+
if (!trimmed)
|
|
3577
3598
|
continue;
|
|
3578
3599
|
if (!options.safe) {
|
|
3579
3600
|
const htmlBlock = readHtmlBlock(lines, index);
|
|
@@ -3583,7 +3604,7 @@ ${line}`) !== null;
|
|
|
3583
3604
|
continue;
|
|
3584
3605
|
}
|
|
3585
3606
|
}
|
|
3586
|
-
const customBlock = /^::([A-Za-z][\w-]*)(?:\s+(.*))?$/.exec(
|
|
3607
|
+
const customBlock = /^::([A-Za-z][\w-]*)(?:\s+(.*))?$/.exec(trimmed);
|
|
3587
3608
|
if (customBlock) {
|
|
3588
3609
|
const parsed = readCustomBlock(lines, index);
|
|
3589
3610
|
const args = splitWords(customBlock[2] ?? "");
|
|
@@ -3668,9 +3689,8 @@ ${line}`) !== null;
|
|
|
3668
3689
|
continue;
|
|
3669
3690
|
}
|
|
3670
3691
|
const setext = lines[index + 1] && isSetextUnderline(lines[index + 1]);
|
|
3671
|
-
if (setext &&
|
|
3672
|
-
const
|
|
3673
|
-
const inlineChildren = parseInlineWithState(source, options, state);
|
|
3692
|
+
if (setext && !isBlockStart(line, options, lines, index)) {
|
|
3693
|
+
const inlineChildren = parseInlineWithState(trimmed, options, state);
|
|
3674
3694
|
const text = stripInlineNodes(inlineChildren);
|
|
3675
3695
|
const node = {
|
|
3676
3696
|
type: "heading",
|
|
@@ -4124,6 +4144,167 @@ ${body}
|
|
|
4124
4144
|
].includes(node.type);
|
|
4125
4145
|
}
|
|
4126
4146
|
|
|
4147
|
+
// ../nizel/dist/markdown.js
|
|
4148
|
+
function renderMarkdown(value, options = {}) {
|
|
4149
|
+
const document = "schema" in value ? value : void 0;
|
|
4150
|
+
const body = renderBlocks((document?.ast ?? value).children, options).trim();
|
|
4151
|
+
if (!document || options.frontmatter === false || Object.keys(document.meta).length === 0)
|
|
4152
|
+
return body;
|
|
4153
|
+
return `---
|
|
4154
|
+
${renderYaml(document.meta)}
|
|
4155
|
+
---${body ? `
|
|
4156
|
+
|
|
4157
|
+
${body}` : ""}`;
|
|
4158
|
+
}
|
|
4159
|
+
function renderBlocks(nodes, options) {
|
|
4160
|
+
return nodes.map((node) => renderBlock2(node, options)).filter(Boolean).join("\n\n");
|
|
4161
|
+
}
|
|
4162
|
+
function renderBlock2(node, options) {
|
|
4163
|
+
if (node.type === "paragraph")
|
|
4164
|
+
return renderInline2(node.children);
|
|
4165
|
+
if (node.type === "heading")
|
|
4166
|
+
return `${"#".repeat(node.depth)} ${renderInline2(node.children)}`;
|
|
4167
|
+
if (node.type === "thematicBreak")
|
|
4168
|
+
return "---";
|
|
4169
|
+
if (node.type === "html")
|
|
4170
|
+
return node.value;
|
|
4171
|
+
if (node.type === "code") {
|
|
4172
|
+
const marker = options.fence ?? "`";
|
|
4173
|
+
const length = Math.max(3, longestRun(node.code, marker) + 1);
|
|
4174
|
+
const fence = marker.repeat(length);
|
|
4175
|
+
const meta = node.meta === node.lang ? void 0 : node.meta;
|
|
4176
|
+
const info = [node.lang, meta].filter(Boolean).join(" ");
|
|
4177
|
+
return `${fence}${info}
|
|
4178
|
+
${node.code.replace(/\n$/, "")}
|
|
4179
|
+
${fence}`;
|
|
4180
|
+
}
|
|
4181
|
+
if (node.type === "blockquote")
|
|
4182
|
+
return prefixLines(renderBlocks(node.children, options), "> ");
|
|
4183
|
+
if (node.type === "list") {
|
|
4184
|
+
return node.children.map((item, index) => renderListItem(item, node.ordered ? `${(node.start ?? 1) + index}.` : options.bullet ?? "-", options)).join("\n");
|
|
4185
|
+
}
|
|
4186
|
+
if (node.type === "table")
|
|
4187
|
+
return renderTable(node.children, node.align);
|
|
4188
|
+
if (node.type === "customBlock") {
|
|
4189
|
+
const custom = options.customBlocks?.[node.name];
|
|
4190
|
+
if (custom)
|
|
4191
|
+
return custom(node, { render: (children2) => renderBlocks(children2, options) });
|
|
4192
|
+
const args = node.args?.length ? ` ${node.args.join(" ")}` : "";
|
|
4193
|
+
const props = node.props && Object.keys(node.props).length ? `
|
|
4194
|
+
${renderYaml(node.props)}
|
|
4195
|
+
::` : "";
|
|
4196
|
+
const children = node.children?.length ? `
|
|
4197
|
+
${renderBlocks(node.children, options)}` : "";
|
|
4198
|
+
return `::${node.name}${args}${props}${children}
|
|
4199
|
+
::`;
|
|
4200
|
+
}
|
|
4201
|
+
return "";
|
|
4202
|
+
}
|
|
4203
|
+
function renderInline2(nodes) {
|
|
4204
|
+
return nodes.map((node) => {
|
|
4205
|
+
if (node.type === "text")
|
|
4206
|
+
return escapeText(node.value);
|
|
4207
|
+
if (node.type === "lineBreak")
|
|
4208
|
+
return node.hard ? " \n" : "\n";
|
|
4209
|
+
if (node.type === "strong")
|
|
4210
|
+
return `**${renderInline2(node.children)}**`;
|
|
4211
|
+
if (node.type === "emphasis")
|
|
4212
|
+
return `*${renderInline2(node.children)}*`;
|
|
4213
|
+
if (node.type === "delete")
|
|
4214
|
+
return `~~${renderInline2(node.children)}~~`;
|
|
4215
|
+
if (node.type === "inlineCode")
|
|
4216
|
+
return renderCodeSpan(node.code);
|
|
4217
|
+
if (node.type === "link")
|
|
4218
|
+
return `[${renderInline2(node.children)}](${escapeDestination(node.href)}${node.title ? ` "${node.title.replaceAll('"', '\\"')}"` : ""})`;
|
|
4219
|
+
if (node.type === "image")
|
|
4220
|
+
return `}${node.title ? ` "${node.title.replaceAll('"', '\\"')}"` : ""})`;
|
|
4221
|
+
if (node.type === "inlineHtml")
|
|
4222
|
+
return node.value;
|
|
4223
|
+
return "";
|
|
4224
|
+
}).join("");
|
|
4225
|
+
}
|
|
4226
|
+
function renderListItem(item, marker, options) {
|
|
4227
|
+
const checkbox = item.checked === void 0 ? "" : `[${item.checked ? "x" : " "}] `;
|
|
4228
|
+
const body = renderBlocks(item.children, options);
|
|
4229
|
+
const lines = body.split("\n");
|
|
4230
|
+
return `${marker} ${checkbox}${lines[0] ?? ""}${lines.slice(1).map((line) => `
|
|
4231
|
+
${" ".repeat(marker.length + 1)}${line}`).join("")}`;
|
|
4232
|
+
}
|
|
4233
|
+
function renderTable(rows, align = []) {
|
|
4234
|
+
if (!rows.length)
|
|
4235
|
+
return "";
|
|
4236
|
+
const width = Math.max(...rows.map((row) => row.children.length));
|
|
4237
|
+
const line = (cells) => `| ${Array.from({ length: width }, (_, index) => escapeTable(renderInline2(cells[index]?.children ?? []))).join(" | ")} |`;
|
|
4238
|
+
const divider = `| ${Array.from({ length: width }, (_, index) => align[index] === "center" ? ":---:" : align[index] === "right" ? "---:" : align[index] === "left" ? ":---" : "---").join(" | ")} |`;
|
|
4239
|
+
return [line(rows[0].children), divider, ...rows.slice(1).map((row) => line(row.children))].join("\n");
|
|
4240
|
+
}
|
|
4241
|
+
function renderYaml(value) {
|
|
4242
|
+
return Object.entries(value).flatMap(([key, item]) => {
|
|
4243
|
+
if (Array.isArray(item))
|
|
4244
|
+
return [`${key}:`, ...item.map((entry) => ` - ${yamlScalar(entry)}`)];
|
|
4245
|
+
return [`${key}: ${yamlScalar(item)}`];
|
|
4246
|
+
}).join("\n");
|
|
4247
|
+
}
|
|
4248
|
+
function yamlScalar(value) {
|
|
4249
|
+
if (value === null)
|
|
4250
|
+
return "null";
|
|
4251
|
+
if (typeof value === "boolean" || typeof value === "number")
|
|
4252
|
+
return String(value);
|
|
4253
|
+
const text = String(value);
|
|
4254
|
+
return text === "" || /^[-?:,[\]{}#&*!|>'"%@`]|[:#]\s|\s$|^(true|false|null|-?\d+(\.\d+)?)$/i.test(text) ? JSON.stringify(text) : text;
|
|
4255
|
+
}
|
|
4256
|
+
function renderCodeSpan(code) {
|
|
4257
|
+
const fence = "`".repeat(Math.max(1, longestRun(code, "`") + 1));
|
|
4258
|
+
const padding = code.startsWith("`") || code.endsWith("`") ? " " : "";
|
|
4259
|
+
return `${fence}${padding}${code}${padding}${fence}`;
|
|
4260
|
+
}
|
|
4261
|
+
function longestRun(value, character) {
|
|
4262
|
+
return Math.max(0, ...Array.from(value.matchAll(new RegExp(`\\${character}+`, "g")), (match) => match[0].length));
|
|
4263
|
+
}
|
|
4264
|
+
function prefixLines(value, prefix) {
|
|
4265
|
+
return value.split("\n").map((line) => line ? `${prefix}${line}` : prefix.trimEnd()).join("\n");
|
|
4266
|
+
}
|
|
4267
|
+
function escapeText(value) {
|
|
4268
|
+
return value.replace(/([\\`*_[\]<>])/g, "\\$1");
|
|
4269
|
+
}
|
|
4270
|
+
function escapeLabel(value) {
|
|
4271
|
+
return value.replace(/([\\\]])/g, "\\$1");
|
|
4272
|
+
}
|
|
4273
|
+
function escapeDestination(value) {
|
|
4274
|
+
return value.replaceAll(" ", "%20").replaceAll(")", "%29");
|
|
4275
|
+
}
|
|
4276
|
+
function escapeTable(value) {
|
|
4277
|
+
return value.replaceAll("|", "\\|").replaceAll("\n", "<br>");
|
|
4278
|
+
}
|
|
4279
|
+
|
|
4280
|
+
// ../nizel/dist/document.js
|
|
4281
|
+
var NIZEL_DOCUMENT_SCHEMA = "nizel/document";
|
|
4282
|
+
var NIZEL_DOCUMENT_VERSION = 1;
|
|
4283
|
+
function createNizelDocument(value, meta) {
|
|
4284
|
+
const ast = isRoot(value) ? value : value.ast;
|
|
4285
|
+
const documentMeta = (isRoot(value) ? meta : value.meta) ?? {};
|
|
4286
|
+
assertJsonValue(ast, "ast");
|
|
4287
|
+
assertJsonValue(documentMeta, "meta");
|
|
4288
|
+
return { schema: NIZEL_DOCUMENT_SCHEMA, version: NIZEL_DOCUMENT_VERSION, ast, meta: documentMeta };
|
|
4289
|
+
}
|
|
4290
|
+
function isRoot(value) {
|
|
4291
|
+
return Boolean(value && typeof value === "object" && value.type === "root" && Array.isArray(value.children));
|
|
4292
|
+
}
|
|
4293
|
+
function assertJsonValue(value, path, seen = /* @__PURE__ */ new Set()) {
|
|
4294
|
+
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
4295
|
+
return;
|
|
4296
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
4297
|
+
return;
|
|
4298
|
+
if (typeof value !== "object")
|
|
4299
|
+
throw new TypeError(`Nizel ${path} is not JSON-serializable.`);
|
|
4300
|
+
if (seen.has(value))
|
|
4301
|
+
throw new TypeError(`Nizel ${path} contains a circular reference.`);
|
|
4302
|
+
seen.add(value);
|
|
4303
|
+
for (const [key, child] of Object.entries(value))
|
|
4304
|
+
assertJsonValue(child, `${path}.${key}`, seen);
|
|
4305
|
+
seen.delete(value);
|
|
4306
|
+
}
|
|
4307
|
+
|
|
4127
4308
|
// ../nizel/dist/template.js
|
|
4128
4309
|
var renderTemplate = (markdown, data, options) => {
|
|
4129
4310
|
const filters = options.filters ?? {};
|
|
@@ -4197,7 +4378,7 @@ ${body}
|
|
|
4197
4378
|
};
|
|
4198
4379
|
|
|
4199
4380
|
// ../nizel/dist/use-nizel.js
|
|
4200
|
-
function createNizel(options = {}) {
|
|
4381
|
+
function createNizel(options = {}, htmlBackend) {
|
|
4201
4382
|
const presetOptions = options.preset ? resolvePreset(options.preset) : {};
|
|
4202
4383
|
const effectiveOptions = { ...presetOptions, ...options, preset: void 0 };
|
|
4203
4384
|
const baseResolved = resolveOptions(effectiveOptions, {});
|
|
@@ -4226,7 +4407,12 @@ ${body}
|
|
|
4226
4407
|
}
|
|
4227
4408
|
const nizel = process;
|
|
4228
4409
|
nizel.html = async (markdown, runtimeOptions) => {
|
|
4229
|
-
const
|
|
4410
|
+
const prepared = prepareMeta(markdown, runtimeOptions);
|
|
4411
|
+
const source = prepareSource(prepared);
|
|
4412
|
+
const accelerated = htmlBackend?.(source, prepared.resolved);
|
|
4413
|
+
if (accelerated !== void 0)
|
|
4414
|
+
return applyAfterRender(accelerated, prepared.resolved);
|
|
4415
|
+
const { ast, resolved } = prepareMarkdown(markdown, runtimeOptions, prepared, source);
|
|
4230
4416
|
return renderPreparedHtml(ast, resolved);
|
|
4231
4417
|
};
|
|
4232
4418
|
nizel.text = async (markdown, runtimeOptions) => {
|
|
@@ -4239,7 +4425,7 @@ ${body}
|
|
|
4239
4425
|
nizel.meta = async (markdown, runtimeOptions) => {
|
|
4240
4426
|
return prepareMeta(markdown, runtimeOptions).meta;
|
|
4241
4427
|
};
|
|
4242
|
-
nizel.preset = (name) => createNizel(resolvePreset(name));
|
|
4428
|
+
nizel.preset = (name) => createNizel(resolvePreset(name), htmlBackend);
|
|
4243
4429
|
nizel.parse = async (markdown, runtimeOptions) => {
|
|
4244
4430
|
const resolved = resolveRuntime(runtimeOptions);
|
|
4245
4431
|
const extracted = resolved.frontmatter === false ? { markdown, frontmatter: {} } : extractFrontmatter(markdown);
|
|
@@ -4263,16 +4449,13 @@ ${body}
|
|
|
4263
4449
|
unwrapStandaloneImages: resolved.unwrapStandaloneImages === true
|
|
4264
4450
|
});
|
|
4265
4451
|
};
|
|
4452
|
+
nizel.markdown = (value, markdownOptions) => renderMarkdown(value, markdownOptions);
|
|
4453
|
+
nizel.document = async (markdown, runtimeOptions) => {
|
|
4454
|
+
const result = await process(markdown, runtimeOptions);
|
|
4455
|
+
return createNizelDocument(result);
|
|
4456
|
+
};
|
|
4266
4457
|
return nizel;
|
|
4267
|
-
function prepareMarkdown(markdown, runtimeOptions = {}) {
|
|
4268
|
-
const preparedMeta = prepareMeta(markdown, runtimeOptions);
|
|
4269
|
-
let preparedMarkdown = preparedMeta.markdown;
|
|
4270
|
-
for (const plugin of preparedMeta.resolved.plugins ?? []) {
|
|
4271
|
-
const nextMarkdown = plugin.hooks?.beforeParse?.(preparedMarkdown, preparedMeta.resolved);
|
|
4272
|
-
if (nextMarkdown !== void 0) {
|
|
4273
|
-
preparedMarkdown = nextMarkdown;
|
|
4274
|
-
}
|
|
4275
|
-
}
|
|
4458
|
+
function prepareMarkdown(markdown, runtimeOptions = {}, preparedMeta = prepareMeta(markdown, runtimeOptions), preparedMarkdown = prepareSource(preparedMeta)) {
|
|
4276
4459
|
let ast = parseMarkdown(preparedMarkdown, {
|
|
4277
4460
|
anchors: preparedMeta.resolved.anchors !== false,
|
|
4278
4461
|
autolinks: preparedMeta.resolved.autolinks,
|
|
@@ -4336,10 +4519,22 @@ ${body}
|
|
|
4336
4519
|
};
|
|
4337
4520
|
}
|
|
4338
4521
|
}
|
|
4522
|
+
function prepareSource(prepared) {
|
|
4523
|
+
let markdown = prepared.markdown;
|
|
4524
|
+
for (const plugin of prepared.resolved.plugins ?? []) {
|
|
4525
|
+
const next = plugin.hooks?.beforeParse?.(markdown, prepared.resolved);
|
|
4526
|
+
if (next !== void 0)
|
|
4527
|
+
markdown = next;
|
|
4528
|
+
}
|
|
4529
|
+
return markdown;
|
|
4530
|
+
}
|
|
4339
4531
|
function renderPreparedHtml(ast, resolved) {
|
|
4340
4532
|
const html = renderHtml(ast, withAutolinkElements(resolved.elements ?? {}, resolved.autolinks), resolved.blocks ?? {}, {
|
|
4341
4533
|
unwrapStandaloneImages: resolved.unwrapStandaloneImages === true
|
|
4342
4534
|
});
|
|
4535
|
+
return applyAfterRender(html, resolved);
|
|
4536
|
+
}
|
|
4537
|
+
function applyAfterRender(html, resolved) {
|
|
4343
4538
|
let finalHtml = html;
|
|
4344
4539
|
for (const plugin of resolved.plugins ?? []) {
|
|
4345
4540
|
const modified = plugin.hooks?.afterRender?.(finalHtml, resolved);
|
|
@@ -4360,8 +4555,13 @@ ${body}
|
|
|
4360
4555
|
function hasRuntimeOptions(runtimeOptions) {
|
|
4361
4556
|
return Boolean(runtimeOptions && Object.keys(runtimeOptions).length > 0);
|
|
4362
4557
|
}
|
|
4363
|
-
|
|
4364
|
-
|
|
4558
|
+
function createNizelFactory(htmlBackend) {
|
|
4559
|
+
const factory = (options) => createNizel(options, htmlBackend);
|
|
4560
|
+
return Object.assign(factory, {
|
|
4561
|
+
preset: (name) => createNizel(resolvePreset(name), htmlBackend)
|
|
4562
|
+
});
|
|
4563
|
+
}
|
|
4564
|
+
var useNizel = createNizelFactory();
|
|
4365
4565
|
function stringMeta(value) {
|
|
4366
4566
|
return typeof value === "string" ? value : void 0;
|
|
4367
4567
|
}
|