nizel-plugin-gfm 0.1.10 → 0.1.12

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.
Files changed (2) hide show
  1. package/dist/gfm.iife.js +259 -55
  2. package/package.json +1 -1
package/dist/gfm.iife.js CHANGED
@@ -1913,9 +1913,16 @@ var NizelGfm = (() => {
1913
1913
  };
1914
1914
 
1915
1915
  // ../nizel/dist/utils.js
1916
+ var htmlEntities = {
1917
+ "&": "&",
1918
+ "<": "&lt;",
1919
+ ">": "&gt;",
1920
+ '"': "&quot;"
1921
+ };
1922
+ var replaceHtmlEntity = (character) => htmlEntities[character];
1916
1923
  var escapeHtml = (value) => {
1917
1924
  const text = String(value);
1918
- return /[&<>"]/.test(text) ? text.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;") : text;
1925
+ return /[&<>"]/.test(text) ? text.replace(/[&<>"]/g, replaceHtmlEntity) : text;
1919
1926
  };
1920
1927
  var slugify = (value, style = "github") => {
1921
1928
  if (style === "classic") {
@@ -2065,6 +2072,10 @@ var NizelGfm = (() => {
2065
2072
  ...left.variables ?? {},
2066
2073
  ...right.variables ?? {}
2067
2074
  },
2075
+ meta: {
2076
+ ...left.meta ?? {},
2077
+ ...right.meta ?? {}
2078
+ },
2068
2079
  elements: {
2069
2080
  ...left.elements ?? {},
2070
2081
  ...right.elements ?? {}
@@ -2573,36 +2584,31 @@ var NizelGfm = (() => {
2573
2584
  // ../nizel/dist/parse/emphasis.js
2574
2585
  var resolveRemainingEmphasis = (nodes) => {
2575
2586
  const tokens = tokenizeEmphasisDelimiters(nodes);
2576
- let changed = true;
2577
- while (changed) {
2578
- changed = false;
2579
- for (let closeIndex = 0; closeIndex < tokens.length; closeIndex += 1) {
2580
- const closer = tokens[closeIndex];
2581
- if (closer.type !== "delimiter" || !closer.close || closer.length === 0)
2587
+ for (let closeIndex = 0; closeIndex < tokens.length; closeIndex += 1) {
2588
+ const closer = tokens[closeIndex];
2589
+ if (closer.type !== "delimiter" || !closer.close || closer.length === 0)
2590
+ continue;
2591
+ for (let openIndex = closeIndex - 1; openIndex >= 0; openIndex -= 1) {
2592
+ const opener = tokens[openIndex];
2593
+ if (opener.type !== "delimiter" || !opener.open || opener.char !== closer.char || opener.length === 0) {
2582
2594
  continue;
2583
- for (let openIndex = closeIndex - 1; openIndex >= 0; openIndex -= 1) {
2584
- const opener = tokens[openIndex];
2585
- if (opener.type !== "delimiter" || !opener.open || opener.char !== closer.char || opener.length === 0) {
2586
- continue;
2587
- }
2588
- if (isForbiddenDelimiterMatch(opener, closer))
2589
- continue;
2590
- const size = opener.length >= 2 && closer.length >= 2 ? 2 : 1;
2591
- const children = inlineTokensToNodes(tokens.slice(openIndex + 1, closeIndex));
2592
- const wrapped = size === 2 ? { type: "strong", children: resolveRemainingEmphasis(children) } : { type: "emphasis", children: resolveRemainingEmphasis(children) };
2593
- const replacement = [];
2594
- if (opener.length > size) {
2595
- replacement.push({ ...opener, length: opener.length - size });
2596
- }
2597
- replacement.push({ type: "node", node: wrapped });
2598
- if (closer.length > size) {
2599
- replacement.push({ ...closer, length: closer.length - size });
2600
- }
2601
- tokens.splice(openIndex, closeIndex - openIndex + 1, ...replacement);
2602
- changed = true;
2603
- closeIndex = -1;
2604
- break;
2605
2595
  }
2596
+ if (isForbiddenDelimiterMatch(opener, closer))
2597
+ continue;
2598
+ const size = opener.length >= 2 && closer.length >= 2 ? 2 : 1;
2599
+ const children = inlineTokensToNodes(tokens.slice(openIndex + 1, closeIndex));
2600
+ const wrapped = size === 2 ? { type: "strong", children: resolveRemainingEmphasis(children) } : { type: "emphasis", children: resolveRemainingEmphasis(children) };
2601
+ const replacement = [];
2602
+ if (opener.length > size) {
2603
+ replacement.push({ ...opener, length: opener.length - size });
2604
+ }
2605
+ replacement.push({ type: "node", node: wrapped });
2606
+ if (closer.length > size) {
2607
+ replacement.push({ ...closer, length: closer.length - size });
2608
+ }
2609
+ tokens.splice(openIndex, closeIndex - openIndex + 1, ...replacement);
2610
+ closeIndex = openIndex - 1;
2611
+ break;
2606
2612
  }
2607
2613
  }
2608
2614
  return inlineTokensToNodes(tokens);
@@ -2971,12 +2977,19 @@ var NizelGfm = (() => {
2971
2977
  };
2972
2978
 
2973
2979
  // ../nizel/dist/parse/inline.js
2980
+ 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");
2981
+ var bareEmailPattern = /(?<bareEmail>[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,})/giu;
2982
+ var inlineTokenPatternWithBareEmail = new RegExp(inlineTokenPatternWithoutBareEmail.source + "|" + bareEmailPattern.source, inlineTokenPatternWithoutBareEmail.flags);
2974
2983
  var parseInline = (source, options = { autolinks: true }) => parseInlineWithState(source, options, { references: /* @__PURE__ */ new Map() });
2975
2984
  var parseInlineWithState = (source, options = { autolinks: true }, state, extractNestedLinks = true) => {
2976
2985
  const autolinks = options.autolinks !== false && getAutolinkOptions(options.autolinks).enabled !== false;
2977
2986
  if (!hasInlineSyntax(source, autolinks)) {
2978
2987
  return source ? [{ type: "text", value: source }] : [];
2979
2988
  }
2989
+ const hasAtSign = source.includes("@");
2990
+ if (!hasAtSign && !hasNonEmphasisSyntax(source)) {
2991
+ return resolveRemainingEmphasis([{ type: "text", value: source }]);
2992
+ }
2980
2993
  if (extractNestedLinks && hasBalancedLinkCandidate(source)) {
2981
2994
  const scanned = scanBalancedInlineLinks(source, options, state);
2982
2995
  if (scanned)
@@ -2984,10 +2997,14 @@ var NizelGfm = (() => {
2984
2997
  }
2985
2998
  const nodes = [];
2986
2999
  const safe = options.safe !== false;
2987
- const pattern = 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<`]+)|(?<bareEmail>[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,})", "giu");
3000
+ const pattern = hasAtSign ? inlineTokenPatternWithBareEmail : inlineTokenPatternWithoutBareEmail;
2988
3001
  let lastIndex = 0;
2989
- let match;
2990
- while (match = pattern.exec(source)) {
3002
+ while (true) {
3003
+ pattern.lastIndex = lastIndex;
3004
+ const match = pattern.exec(source);
3005
+ if (!match)
3006
+ break;
3007
+ const end = pattern.lastIndex;
2991
3008
  if (match.index > lastIndex) {
2992
3009
  nodes.push({ type: "text", value: source.slice(lastIndex, match.index) });
2993
3010
  }
@@ -3121,7 +3138,7 @@ var NizelGfm = (() => {
3121
3138
  } else {
3122
3139
  nodes.push({ type: "text", value: match[0] });
3123
3140
  }
3124
- lastIndex = pattern.lastIndex;
3141
+ lastIndex = end;
3125
3142
  }
3126
3143
  if (lastIndex < source.length)
3127
3144
  nodes.push({ type: "text", value: source.slice(lastIndex) });
@@ -3134,6 +3151,9 @@ var NizelGfm = (() => {
3134
3151
  return true;
3135
3152
  return autolinks && (source.includes("http://") || source.includes("https://") || source.includes("@"));
3136
3153
  };
3154
+ var hasNonEmphasisSyntax = (source) => {
3155
+ return /[`<&\n[~\\]|https?:\/\//i.test(source);
3156
+ };
3137
3157
  var hasBalancedLinkCandidate = (source) => {
3138
3158
  return source.includes("[");
3139
3159
  };
@@ -3560,7 +3580,7 @@ ${line}`) !== null;
3560
3580
  function parseMarkdown(markdown, options) {
3561
3581
  const normalizedMarkdown = markdown.includes("\r") ? markdown.replace(/\r\n?/g, "\n") : markdown;
3562
3582
  const lines = normalizedMarkdown.includes(" ") ? expandLeadingTabsToLines(normalizedMarkdown) : normalizedMarkdown.split("\n");
3563
- const { contentLines, references } = normalizedMarkdown.includes("[") && hasPossibleReferenceDefinitionStart(normalizedMarkdown) ? extractReferenceDefinitions(lines) : { contentLines: lines, references: /* @__PURE__ */ new Map() };
3583
+ const { contentLines, references } = normalizedMarkdown.includes("]:") && hasPossibleReferenceDefinitionStart(normalizedMarkdown) ? extractReferenceDefinitions(lines) : { contentLines: lines, references: /* @__PURE__ */ new Map() };
3564
3584
  const children = parseBlocks(contentLines, options, /* @__PURE__ */ new Map(), { references });
3565
3585
  return { type: "root", children };
3566
3586
  }
@@ -3571,7 +3591,8 @@ ${line}`) !== null;
3571
3591
  const children = [];
3572
3592
  for (let index = 0; index < lines.length; index += 1) {
3573
3593
  const line = lines[index];
3574
- if (!line.trim())
3594
+ const trimmed = line.trim();
3595
+ if (!trimmed)
3575
3596
  continue;
3576
3597
  if (!options.safe) {
3577
3598
  const htmlBlock = readHtmlBlock(lines, index);
@@ -3581,7 +3602,7 @@ ${line}`) !== null;
3581
3602
  continue;
3582
3603
  }
3583
3604
  }
3584
- const customBlock = /^::([A-Za-z][\w-]*)(?:\s+(.*))?$/.exec(line.trim());
3605
+ const customBlock = /^::([A-Za-z][\w-]*)(?:\s+(.*))?$/.exec(trimmed);
3585
3606
  if (customBlock) {
3586
3607
  const parsed = readCustomBlock(lines, index);
3587
3608
  const args = splitWords(customBlock[2] ?? "");
@@ -3666,9 +3687,8 @@ ${line}`) !== null;
3666
3687
  continue;
3667
3688
  }
3668
3689
  const setext = lines[index + 1] && isSetextUnderline(lines[index + 1]);
3669
- if (setext && line.trim() && !isBlockStart(line, options, lines, index)) {
3670
- const source = line.trim();
3671
- const inlineChildren = parseInlineWithState(source, options, state);
3690
+ if (setext && !isBlockStart(line, options, lines, index)) {
3691
+ const inlineChildren = parseInlineWithState(trimmed, options, state);
3672
3692
  const text = stripInlineNodes(inlineChildren);
3673
3693
  const node = {
3674
3694
  type: "heading",
@@ -4122,6 +4142,167 @@ ${body}
4122
4142
  ].includes(node.type);
4123
4143
  }
4124
4144
 
4145
+ // ../nizel/dist/markdown.js
4146
+ function renderMarkdown(value, options = {}) {
4147
+ const document = "schema" in value ? value : void 0;
4148
+ const body = renderBlocks((document?.ast ?? value).children, options).trim();
4149
+ if (!document || options.frontmatter === false || Object.keys(document.meta).length === 0)
4150
+ return body;
4151
+ return `---
4152
+ ${renderYaml(document.meta)}
4153
+ ---${body ? `
4154
+
4155
+ ${body}` : ""}`;
4156
+ }
4157
+ function renderBlocks(nodes, options) {
4158
+ return nodes.map((node) => renderBlock2(node, options)).filter(Boolean).join("\n\n");
4159
+ }
4160
+ function renderBlock2(node, options) {
4161
+ if (node.type === "paragraph")
4162
+ return renderInline2(node.children);
4163
+ if (node.type === "heading")
4164
+ return `${"#".repeat(node.depth)} ${renderInline2(node.children)}`;
4165
+ if (node.type === "thematicBreak")
4166
+ return "---";
4167
+ if (node.type === "html")
4168
+ return node.value;
4169
+ if (node.type === "code") {
4170
+ const marker = options.fence ?? "`";
4171
+ const length = Math.max(3, longestRun(node.code, marker) + 1);
4172
+ const fence = marker.repeat(length);
4173
+ const meta = node.meta === node.lang ? void 0 : node.meta;
4174
+ const info = [node.lang, meta].filter(Boolean).join(" ");
4175
+ return `${fence}${info}
4176
+ ${node.code.replace(/\n$/, "")}
4177
+ ${fence}`;
4178
+ }
4179
+ if (node.type === "blockquote")
4180
+ return prefixLines(renderBlocks(node.children, options), "> ");
4181
+ if (node.type === "list") {
4182
+ return node.children.map((item, index) => renderListItem(item, node.ordered ? `${(node.start ?? 1) + index}.` : options.bullet ?? "-", options)).join("\n");
4183
+ }
4184
+ if (node.type === "table")
4185
+ return renderTable(node.children, node.align);
4186
+ if (node.type === "customBlock") {
4187
+ const custom = options.customBlocks?.[node.name];
4188
+ if (custom)
4189
+ return custom(node, { render: (children2) => renderBlocks(children2, options) });
4190
+ const args = node.args?.length ? ` ${node.args.join(" ")}` : "";
4191
+ const props = node.props && Object.keys(node.props).length ? `
4192
+ ${renderYaml(node.props)}
4193
+ ::` : "";
4194
+ const children = node.children?.length ? `
4195
+ ${renderBlocks(node.children, options)}` : "";
4196
+ return `::${node.name}${args}${props}${children}
4197
+ ::`;
4198
+ }
4199
+ return "";
4200
+ }
4201
+ function renderInline2(nodes) {
4202
+ return nodes.map((node) => {
4203
+ if (node.type === "text")
4204
+ return escapeText(node.value);
4205
+ if (node.type === "lineBreak")
4206
+ return node.hard ? " \n" : "\n";
4207
+ if (node.type === "strong")
4208
+ return `**${renderInline2(node.children)}**`;
4209
+ if (node.type === "emphasis")
4210
+ return `*${renderInline2(node.children)}*`;
4211
+ if (node.type === "delete")
4212
+ return `~~${renderInline2(node.children)}~~`;
4213
+ if (node.type === "inlineCode")
4214
+ return renderCodeSpan(node.code);
4215
+ if (node.type === "link")
4216
+ return `[${renderInline2(node.children)}](${escapeDestination(node.href)}${node.title ? ` "${node.title.replaceAll('"', '\\"')}"` : ""})`;
4217
+ if (node.type === "image")
4218
+ return `![${escapeLabel(node.alt ?? "")}](${escapeDestination(node.src)}${node.title ? ` "${node.title.replaceAll('"', '\\"')}"` : ""})`;
4219
+ if (node.type === "inlineHtml")
4220
+ return node.value;
4221
+ return "";
4222
+ }).join("");
4223
+ }
4224
+ function renderListItem(item, marker, options) {
4225
+ const checkbox = item.checked === void 0 ? "" : `[${item.checked ? "x" : " "}] `;
4226
+ const body = renderBlocks(item.children, options);
4227
+ const lines = body.split("\n");
4228
+ return `${marker} ${checkbox}${lines[0] ?? ""}${lines.slice(1).map((line) => `
4229
+ ${" ".repeat(marker.length + 1)}${line}`).join("")}`;
4230
+ }
4231
+ function renderTable(rows, align = []) {
4232
+ if (!rows.length)
4233
+ return "";
4234
+ const width = Math.max(...rows.map((row) => row.children.length));
4235
+ const line = (cells) => `| ${Array.from({ length: width }, (_, index) => escapeTable(renderInline2(cells[index]?.children ?? []))).join(" | ")} |`;
4236
+ const divider = `| ${Array.from({ length: width }, (_, index) => align[index] === "center" ? ":---:" : align[index] === "right" ? "---:" : align[index] === "left" ? ":---" : "---").join(" | ")} |`;
4237
+ return [line(rows[0].children), divider, ...rows.slice(1).map((row) => line(row.children))].join("\n");
4238
+ }
4239
+ function renderYaml(value) {
4240
+ return Object.entries(value).flatMap(([key, item]) => {
4241
+ if (Array.isArray(item))
4242
+ return [`${key}:`, ...item.map((entry) => ` - ${yamlScalar(entry)}`)];
4243
+ return [`${key}: ${yamlScalar(item)}`];
4244
+ }).join("\n");
4245
+ }
4246
+ function yamlScalar(value) {
4247
+ if (value === null)
4248
+ return "null";
4249
+ if (typeof value === "boolean" || typeof value === "number")
4250
+ return String(value);
4251
+ const text = String(value);
4252
+ return text === "" || /^[-?:,[\]{}#&*!|>'"%@`]|[:#]\s|\s$|^(true|false|null|-?\d+(\.\d+)?)$/i.test(text) ? JSON.stringify(text) : text;
4253
+ }
4254
+ function renderCodeSpan(code) {
4255
+ const fence = "`".repeat(Math.max(1, longestRun(code, "`") + 1));
4256
+ const padding = code.startsWith("`") || code.endsWith("`") ? " " : "";
4257
+ return `${fence}${padding}${code}${padding}${fence}`;
4258
+ }
4259
+ function longestRun(value, character) {
4260
+ return Math.max(0, ...Array.from(value.matchAll(new RegExp(`\\${character}+`, "g")), (match) => match[0].length));
4261
+ }
4262
+ function prefixLines(value, prefix) {
4263
+ return value.split("\n").map((line) => line ? `${prefix}${line}` : prefix.trimEnd()).join("\n");
4264
+ }
4265
+ function escapeText(value) {
4266
+ return value.replace(/([\\`*_[\]<>])/g, "\\$1");
4267
+ }
4268
+ function escapeLabel(value) {
4269
+ return value.replace(/([\\\]])/g, "\\$1");
4270
+ }
4271
+ function escapeDestination(value) {
4272
+ return value.replaceAll(" ", "%20").replaceAll(")", "%29");
4273
+ }
4274
+ function escapeTable(value) {
4275
+ return value.replaceAll("|", "\\|").replaceAll("\n", "<br>");
4276
+ }
4277
+
4278
+ // ../nizel/dist/document.js
4279
+ var NIZEL_DOCUMENT_SCHEMA = "nizel/document";
4280
+ var NIZEL_DOCUMENT_VERSION = 1;
4281
+ function createNizelDocument(value, meta) {
4282
+ const ast = isRoot(value) ? value : value.ast;
4283
+ const documentMeta = (isRoot(value) ? meta : value.meta) ?? {};
4284
+ assertJsonValue(ast, "ast");
4285
+ assertJsonValue(documentMeta, "meta");
4286
+ return { schema: NIZEL_DOCUMENT_SCHEMA, version: NIZEL_DOCUMENT_VERSION, ast, meta: documentMeta };
4287
+ }
4288
+ function isRoot(value) {
4289
+ return Boolean(value && typeof value === "object" && value.type === "root" && Array.isArray(value.children));
4290
+ }
4291
+ function assertJsonValue(value, path, seen = /* @__PURE__ */ new Set()) {
4292
+ if (value === null || typeof value === "string" || typeof value === "boolean")
4293
+ return;
4294
+ if (typeof value === "number" && Number.isFinite(value))
4295
+ return;
4296
+ if (typeof value !== "object")
4297
+ throw new TypeError(`Nizel ${path} is not JSON-serializable.`);
4298
+ if (seen.has(value))
4299
+ throw new TypeError(`Nizel ${path} contains a circular reference.`);
4300
+ seen.add(value);
4301
+ for (const [key, child] of Object.entries(value))
4302
+ assertJsonValue(child, `${path}.${key}`, seen);
4303
+ seen.delete(value);
4304
+ }
4305
+
4125
4306
  // ../nizel/dist/template.js
4126
4307
  var renderTemplate = (markdown, data, options) => {
4127
4308
  const filters = options.filters ?? {};
@@ -4195,7 +4376,7 @@ ${body}
4195
4376
  };
4196
4377
 
4197
4378
  // ../nizel/dist/use-nizel.js
4198
- function createNizel(options = {}) {
4379
+ function createNizel(options = {}, htmlBackend) {
4199
4380
  const presetOptions = options.preset ? resolvePreset(options.preset) : {};
4200
4381
  const effectiveOptions = { ...presetOptions, ...options, preset: void 0 };
4201
4382
  const baseResolved = resolveOptions(effectiveOptions, {});
@@ -4224,7 +4405,12 @@ ${body}
4224
4405
  }
4225
4406
  const nizel = process;
4226
4407
  nizel.html = async (markdown, runtimeOptions) => {
4227
- const { ast, resolved } = prepareMarkdown(markdown, runtimeOptions);
4408
+ const prepared = prepareMeta(markdown, runtimeOptions);
4409
+ const source = prepareSource(prepared);
4410
+ const accelerated = htmlBackend?.(source, prepared.resolved);
4411
+ if (accelerated !== void 0)
4412
+ return applyAfterRender(accelerated, prepared.resolved);
4413
+ const { ast, resolved } = prepareMarkdown(markdown, runtimeOptions, prepared, source);
4228
4414
  return renderPreparedHtml(ast, resolved);
4229
4415
  };
4230
4416
  nizel.text = async (markdown, runtimeOptions) => {
@@ -4237,7 +4423,7 @@ ${body}
4237
4423
  nizel.meta = async (markdown, runtimeOptions) => {
4238
4424
  return prepareMeta(markdown, runtimeOptions).meta;
4239
4425
  };
4240
- nizel.preset = (name) => createNizel(resolvePreset(name));
4426
+ nizel.preset = (name) => createNizel(resolvePreset(name), htmlBackend);
4241
4427
  nizel.parse = async (markdown, runtimeOptions) => {
4242
4428
  const resolved = resolveRuntime(runtimeOptions);
4243
4429
  const extracted = resolved.frontmatter === false ? { markdown, frontmatter: {} } : extractFrontmatter(markdown);
@@ -4261,16 +4447,13 @@ ${body}
4261
4447
  unwrapStandaloneImages: resolved.unwrapStandaloneImages === true
4262
4448
  });
4263
4449
  };
4450
+ nizel.markdown = (value, markdownOptions) => renderMarkdown(value, markdownOptions);
4451
+ nizel.document = async (markdown, runtimeOptions) => {
4452
+ const result = await process(markdown, runtimeOptions);
4453
+ return createNizelDocument(result);
4454
+ };
4264
4455
  return nizel;
4265
- function prepareMarkdown(markdown, runtimeOptions = {}) {
4266
- const preparedMeta = prepareMeta(markdown, runtimeOptions);
4267
- let preparedMarkdown = preparedMeta.markdown;
4268
- for (const plugin of preparedMeta.resolved.plugins ?? []) {
4269
- const nextMarkdown = plugin.hooks?.beforeParse?.(preparedMarkdown, preparedMeta.resolved);
4270
- if (nextMarkdown !== void 0) {
4271
- preparedMarkdown = nextMarkdown;
4272
- }
4273
- }
4456
+ function prepareMarkdown(markdown, runtimeOptions = {}, preparedMeta = prepareMeta(markdown, runtimeOptions), preparedMarkdown = prepareSource(preparedMeta)) {
4274
4457
  let ast = parseMarkdown(preparedMarkdown, {
4275
4458
  anchors: preparedMeta.resolved.anchors !== false,
4276
4459
  autolinks: preparedMeta.resolved.autolinks,
@@ -4334,10 +4517,22 @@ ${body}
4334
4517
  };
4335
4518
  }
4336
4519
  }
4520
+ function prepareSource(prepared) {
4521
+ let markdown = prepared.markdown;
4522
+ for (const plugin of prepared.resolved.plugins ?? []) {
4523
+ const next = plugin.hooks?.beforeParse?.(markdown, prepared.resolved);
4524
+ if (next !== void 0)
4525
+ markdown = next;
4526
+ }
4527
+ return markdown;
4528
+ }
4337
4529
  function renderPreparedHtml(ast, resolved) {
4338
4530
  const html = renderHtml(ast, withAutolinkElements(resolved.elements ?? {}, resolved.autolinks), resolved.blocks ?? {}, {
4339
4531
  unwrapStandaloneImages: resolved.unwrapStandaloneImages === true
4340
4532
  });
4533
+ return applyAfterRender(html, resolved);
4534
+ }
4535
+ function applyAfterRender(html, resolved) {
4341
4536
  let finalHtml = html;
4342
4537
  for (const plugin of resolved.plugins ?? []) {
4343
4538
  const modified = plugin.hooks?.afterRender?.(finalHtml, resolved);
@@ -4358,8 +4553,13 @@ ${body}
4358
4553
  function hasRuntimeOptions(runtimeOptions) {
4359
4554
  return Boolean(runtimeOptions && Object.keys(runtimeOptions).length > 0);
4360
4555
  }
4361
- var useNizel = createNizel;
4362
- useNizel.preset = (name) => createNizel(resolvePreset(name));
4556
+ function createNizelFactory(htmlBackend) {
4557
+ const factory = (options) => createNizel(options, htmlBackend);
4558
+ return Object.assign(factory, {
4559
+ preset: (name) => createNizel(resolvePreset(name), htmlBackend)
4560
+ });
4561
+ }
4562
+ var useNizel = createNizelFactory();
4363
4563
  function stringMeta(value) {
4364
4564
  return typeof value === "string" ? value : void 0;
4365
4565
  }
@@ -4555,7 +4755,8 @@ ${body}
4555
4755
  options: {
4556
4756
  autolinks: resolveAutolinkPluginOptions(options)
4557
4757
  },
4558
- htmlToMarkdown: autolinkToMarkdown()
4758
+ htmlToMarkdown: autolinkToMarkdown(),
4759
+ htmlToMarkdownTags: ["a"]
4559
4760
  });
4560
4761
  };
4561
4762
  var autolinkToMarkdown = () => (node, ctx) => {
@@ -4580,7 +4781,10 @@ ${body}
4580
4781
  return transformTaskLists(ast, mode);
4581
4782
  }
4582
4783
  },
4583
- htmlToMarkdown: taskListToMarkdown()
4784
+ // Only items written with a `[ ]` or `[x]` box become task items.
4785
+ afterParseApplies: (markdown) => markdown.includes("["),
4786
+ htmlToMarkdown: taskListToMarkdown(),
4787
+ htmlToMarkdownTags: ["ul", "ol"]
4584
4788
  };
4585
4789
  };
4586
4790
  var CHECKBOX_ATTR = "data-nizel-task-checkbox";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nizel-plugin-gfm",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "description": "GFM-oriented plugin preset for Nizel.",
5
5
  "repository": {
6
6
  "type": "git",