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