nizel-plugin-gfm 0.1.9 → 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/gfm.iife.js +423 -136
- package/package.json +1 -1
package/dist/gfm.iife.js
CHANGED
|
@@ -26,87 +26,6 @@ var NizelGfm = (() => {
|
|
|
26
26
|
gfmPlugins: () => gfmPlugins
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
// ../plugin-alert/dist/index.js
|
|
30
|
-
var ALERT_TYPES = ["note", "tip", "important", "warning", "caution"];
|
|
31
|
-
var alertPlugin = (options = {}) => {
|
|
32
|
-
const blocks = Object.fromEntries(ALERT_TYPES.map((alertType) => [alertType, createAlertBlock(alertType, options)]));
|
|
33
|
-
return {
|
|
34
|
-
name: "alert",
|
|
35
|
-
blocks,
|
|
36
|
-
hooks: {
|
|
37
|
-
beforeParse: transformGitHubAlerts
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
var transformGitHubAlerts = (markdown) => {
|
|
42
|
-
const lines = markdown.split("\n");
|
|
43
|
-
const result = [];
|
|
44
|
-
let index = 0;
|
|
45
|
-
while (index < lines.length) {
|
|
46
|
-
const opener = /^ {0,3}> ?\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*$/i.exec(lines[index]);
|
|
47
|
-
if (!opener) {
|
|
48
|
-
result.push(lines[index]);
|
|
49
|
-
index += 1;
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
const alertType = opener[1].toLowerCase();
|
|
53
|
-
const content = [];
|
|
54
|
-
index += 1;
|
|
55
|
-
while (index < lines.length) {
|
|
56
|
-
const quoteLine = /^ {0,3}> ?(.*)$/.exec(lines[index]);
|
|
57
|
-
if (!quoteLine)
|
|
58
|
-
break;
|
|
59
|
-
content.push(quoteLine[1]);
|
|
60
|
-
index += 1;
|
|
61
|
-
}
|
|
62
|
-
result.push(`::${alertType} ${alertTitle(alertType)}`);
|
|
63
|
-
result.push(...trimAlertContent(content));
|
|
64
|
-
result.push("::");
|
|
65
|
-
}
|
|
66
|
-
return result.join("\n");
|
|
67
|
-
};
|
|
68
|
-
var createAlertBlock = (alertType, options) => {
|
|
69
|
-
return {
|
|
70
|
-
name: alertType,
|
|
71
|
-
parse({ args, props }) {
|
|
72
|
-
const title = props.title ?? args[0] ?? "";
|
|
73
|
-
return { alertType, title: String(title) };
|
|
74
|
-
},
|
|
75
|
-
formats: {
|
|
76
|
-
html(node, ctx) {
|
|
77
|
-
if (node.type !== "customBlock" || !isAlertValue(node.value))
|
|
78
|
-
return "";
|
|
79
|
-
return renderAlert(node.value, node.children ?? [], ctx, options);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
};
|
|
84
|
-
var renderAlert = (value, children, ctx, options) => {
|
|
85
|
-
const rootClass = options.className ?? "alert";
|
|
86
|
-
const titleHtml = value.title ? `<p class="${rootClass}__title">${ctx.escape(value.title)}</p>` : "";
|
|
87
|
-
const contentHtml = ctx.render(children);
|
|
88
|
-
const escapedType = ctx.escape(value.alertType);
|
|
89
|
-
return `<div class="${ctx.escape(rootClass)} ${ctx.escape(rootClass)}--${escapedType}" data-alert="${escapedType}">${titleHtml}<div class="${ctx.escape(rootClass)}__content">${contentHtml}</div></div>`;
|
|
90
|
-
};
|
|
91
|
-
var trimAlertContent = (lines) => {
|
|
92
|
-
let start = 0;
|
|
93
|
-
let end = lines.length;
|
|
94
|
-
while (start < end && !lines[start].trim())
|
|
95
|
-
start += 1;
|
|
96
|
-
while (end > start && !lines[end - 1].trim())
|
|
97
|
-
end -= 1;
|
|
98
|
-
return lines.slice(start, end);
|
|
99
|
-
};
|
|
100
|
-
var alertTitle = (alertType) => {
|
|
101
|
-
return alertType.charAt(0).toUpperCase() + alertType.slice(1);
|
|
102
|
-
};
|
|
103
|
-
var isAlertValue = (value) => {
|
|
104
|
-
if (!value || typeof value !== "object")
|
|
105
|
-
return false;
|
|
106
|
-
const candidate = value;
|
|
107
|
-
return typeof candidate.title === "string" && ALERT_TYPES.includes(candidate.alertType);
|
|
108
|
-
};
|
|
109
|
-
|
|
110
29
|
// ../nizel/dist/collect.js
|
|
111
30
|
function collect(ast) {
|
|
112
31
|
const headings = [];
|
|
@@ -1994,9 +1913,16 @@ var NizelGfm = (() => {
|
|
|
1994
1913
|
};
|
|
1995
1914
|
|
|
1996
1915
|
// ../nizel/dist/utils.js
|
|
1916
|
+
var htmlEntities = {
|
|
1917
|
+
"&": "&",
|
|
1918
|
+
"<": "<",
|
|
1919
|
+
">": ">",
|
|
1920
|
+
'"': """
|
|
1921
|
+
};
|
|
1922
|
+
var replaceHtmlEntity = (character) => htmlEntities[character];
|
|
1997
1923
|
var escapeHtml = (value) => {
|
|
1998
1924
|
const text = String(value);
|
|
1999
|
-
return /[&<>"]/.test(text) ? text.
|
|
1925
|
+
return /[&<>"]/.test(text) ? text.replace(/[&<>"]/g, replaceHtmlEntity) : text;
|
|
2000
1926
|
};
|
|
2001
1927
|
var slugify = (value, style = "github") => {
|
|
2002
1928
|
if (style === "classic") {
|
|
@@ -2146,6 +2072,10 @@ var NizelGfm = (() => {
|
|
|
2146
2072
|
...left.variables ?? {},
|
|
2147
2073
|
...right.variables ?? {}
|
|
2148
2074
|
},
|
|
2075
|
+
meta: {
|
|
2076
|
+
...left.meta ?? {},
|
|
2077
|
+
...right.meta ?? {}
|
|
2078
|
+
},
|
|
2149
2079
|
elements: {
|
|
2150
2080
|
...left.elements ?? {},
|
|
2151
2081
|
...right.elements ?? {}
|
|
@@ -2654,36 +2584,31 @@ var NizelGfm = (() => {
|
|
|
2654
2584
|
// ../nizel/dist/parse/emphasis.js
|
|
2655
2585
|
var resolveRemainingEmphasis = (nodes) => {
|
|
2656
2586
|
const tokens = tokenizeEmphasisDelimiters(nodes);
|
|
2657
|
-
let
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
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) {
|
|
2663
2594
|
continue;
|
|
2664
|
-
for (let openIndex = closeIndex - 1; openIndex >= 0; openIndex -= 1) {
|
|
2665
|
-
const opener = tokens[openIndex];
|
|
2666
|
-
if (opener.type !== "delimiter" || !opener.open || opener.char !== closer.char || opener.length === 0) {
|
|
2667
|
-
continue;
|
|
2668
|
-
}
|
|
2669
|
-
if (isForbiddenDelimiterMatch(opener, closer))
|
|
2670
|
-
continue;
|
|
2671
|
-
const size = opener.length >= 2 && closer.length >= 2 ? 2 : 1;
|
|
2672
|
-
const children = inlineTokensToNodes(tokens.slice(openIndex + 1, closeIndex));
|
|
2673
|
-
const wrapped = size === 2 ? { type: "strong", children: resolveRemainingEmphasis(children) } : { type: "emphasis", children: resolveRemainingEmphasis(children) };
|
|
2674
|
-
const replacement = [];
|
|
2675
|
-
if (opener.length > size) {
|
|
2676
|
-
replacement.push({ ...opener, length: opener.length - size });
|
|
2677
|
-
}
|
|
2678
|
-
replacement.push({ type: "node", node: wrapped });
|
|
2679
|
-
if (closer.length > size) {
|
|
2680
|
-
replacement.push({ ...closer, length: closer.length - size });
|
|
2681
|
-
}
|
|
2682
|
-
tokens.splice(openIndex, closeIndex - openIndex + 1, ...replacement);
|
|
2683
|
-
changed = true;
|
|
2684
|
-
closeIndex = -1;
|
|
2685
|
-
break;
|
|
2686
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;
|
|
2687
2612
|
}
|
|
2688
2613
|
}
|
|
2689
2614
|
return inlineTokensToNodes(tokens);
|
|
@@ -3052,12 +2977,19 @@ var NizelGfm = (() => {
|
|
|
3052
2977
|
};
|
|
3053
2978
|
|
|
3054
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);
|
|
3055
2983
|
var parseInline = (source, options = { autolinks: true }) => parseInlineWithState(source, options, { references: /* @__PURE__ */ new Map() });
|
|
3056
2984
|
var parseInlineWithState = (source, options = { autolinks: true }, state, extractNestedLinks = true) => {
|
|
3057
2985
|
const autolinks = options.autolinks !== false && getAutolinkOptions(options.autolinks).enabled !== false;
|
|
3058
2986
|
if (!hasInlineSyntax(source, autolinks)) {
|
|
3059
2987
|
return source ? [{ type: "text", value: source }] : [];
|
|
3060
2988
|
}
|
|
2989
|
+
const hasAtSign = source.includes("@");
|
|
2990
|
+
if (!hasAtSign && !hasNonEmphasisSyntax(source)) {
|
|
2991
|
+
return resolveRemainingEmphasis([{ type: "text", value: source }]);
|
|
2992
|
+
}
|
|
3061
2993
|
if (extractNestedLinks && hasBalancedLinkCandidate(source)) {
|
|
3062
2994
|
const scanned = scanBalancedInlineLinks(source, options, state);
|
|
3063
2995
|
if (scanned)
|
|
@@ -3065,10 +2997,14 @@ var NizelGfm = (() => {
|
|
|
3065
2997
|
}
|
|
3066
2998
|
const nodes = [];
|
|
3067
2999
|
const safe = options.safe !== false;
|
|
3068
|
-
const pattern =
|
|
3000
|
+
const pattern = hasAtSign ? inlineTokenPatternWithBareEmail : inlineTokenPatternWithoutBareEmail;
|
|
3069
3001
|
let lastIndex = 0;
|
|
3070
|
-
|
|
3071
|
-
|
|
3002
|
+
while (true) {
|
|
3003
|
+
pattern.lastIndex = lastIndex;
|
|
3004
|
+
const match = pattern.exec(source);
|
|
3005
|
+
if (!match)
|
|
3006
|
+
break;
|
|
3007
|
+
const end = pattern.lastIndex;
|
|
3072
3008
|
if (match.index > lastIndex) {
|
|
3073
3009
|
nodes.push({ type: "text", value: source.slice(lastIndex, match.index) });
|
|
3074
3010
|
}
|
|
@@ -3202,7 +3138,7 @@ var NizelGfm = (() => {
|
|
|
3202
3138
|
} else {
|
|
3203
3139
|
nodes.push({ type: "text", value: match[0] });
|
|
3204
3140
|
}
|
|
3205
|
-
lastIndex =
|
|
3141
|
+
lastIndex = end;
|
|
3206
3142
|
}
|
|
3207
3143
|
if (lastIndex < source.length)
|
|
3208
3144
|
nodes.push({ type: "text", value: source.slice(lastIndex) });
|
|
@@ -3215,6 +3151,9 @@ var NizelGfm = (() => {
|
|
|
3215
3151
|
return true;
|
|
3216
3152
|
return autolinks && (source.includes("http://") || source.includes("https://") || source.includes("@"));
|
|
3217
3153
|
};
|
|
3154
|
+
var hasNonEmphasisSyntax = (source) => {
|
|
3155
|
+
return /[`<&\n[~\\]|https?:\/\//i.test(source);
|
|
3156
|
+
};
|
|
3218
3157
|
var hasBalancedLinkCandidate = (source) => {
|
|
3219
3158
|
return source.includes("[");
|
|
3220
3159
|
};
|
|
@@ -3641,7 +3580,7 @@ ${line}`) !== null;
|
|
|
3641
3580
|
function parseMarkdown(markdown, options) {
|
|
3642
3581
|
const normalizedMarkdown = markdown.includes("\r") ? markdown.replace(/\r\n?/g, "\n") : markdown;
|
|
3643
3582
|
const lines = normalizedMarkdown.includes(" ") ? expandLeadingTabsToLines(normalizedMarkdown) : normalizedMarkdown.split("\n");
|
|
3644
|
-
const { contentLines, references } = normalizedMarkdown.includes("
|
|
3583
|
+
const { contentLines, references } = normalizedMarkdown.includes("]:") && hasPossibleReferenceDefinitionStart(normalizedMarkdown) ? extractReferenceDefinitions(lines) : { contentLines: lines, references: /* @__PURE__ */ new Map() };
|
|
3645
3584
|
const children = parseBlocks(contentLines, options, /* @__PURE__ */ new Map(), { references });
|
|
3646
3585
|
return { type: "root", children };
|
|
3647
3586
|
}
|
|
@@ -3652,7 +3591,8 @@ ${line}`) !== null;
|
|
|
3652
3591
|
const children = [];
|
|
3653
3592
|
for (let index = 0; index < lines.length; index += 1) {
|
|
3654
3593
|
const line = lines[index];
|
|
3655
|
-
|
|
3594
|
+
const trimmed = line.trim();
|
|
3595
|
+
if (!trimmed)
|
|
3656
3596
|
continue;
|
|
3657
3597
|
if (!options.safe) {
|
|
3658
3598
|
const htmlBlock = readHtmlBlock(lines, index);
|
|
@@ -3662,7 +3602,7 @@ ${line}`) !== null;
|
|
|
3662
3602
|
continue;
|
|
3663
3603
|
}
|
|
3664
3604
|
}
|
|
3665
|
-
const customBlock = /^::([A-Za-z][\w-]*)(?:\s+(.*))?$/.exec(
|
|
3605
|
+
const customBlock = /^::([A-Za-z][\w-]*)(?:\s+(.*))?$/.exec(trimmed);
|
|
3666
3606
|
if (customBlock) {
|
|
3667
3607
|
const parsed = readCustomBlock(lines, index);
|
|
3668
3608
|
const args = splitWords(customBlock[2] ?? "");
|
|
@@ -3747,9 +3687,8 @@ ${line}`) !== null;
|
|
|
3747
3687
|
continue;
|
|
3748
3688
|
}
|
|
3749
3689
|
const setext = lines[index + 1] && isSetextUnderline(lines[index + 1]);
|
|
3750
|
-
if (setext &&
|
|
3751
|
-
const
|
|
3752
|
-
const inlineChildren = parseInlineWithState(source, options, state);
|
|
3690
|
+
if (setext && !isBlockStart(line, options, lines, index)) {
|
|
3691
|
+
const inlineChildren = parseInlineWithState(trimmed, options, state);
|
|
3753
3692
|
const text = stripInlineNodes(inlineChildren);
|
|
3754
3693
|
const node = {
|
|
3755
3694
|
type: "heading",
|
|
@@ -4203,6 +4142,167 @@ ${body}
|
|
|
4203
4142
|
].includes(node.type);
|
|
4204
4143
|
}
|
|
4205
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 `}${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
|
+
|
|
4206
4306
|
// ../nizel/dist/template.js
|
|
4207
4307
|
var renderTemplate = (markdown, data, options) => {
|
|
4208
4308
|
const filters = options.filters ?? {};
|
|
@@ -4276,7 +4376,7 @@ ${body}
|
|
|
4276
4376
|
};
|
|
4277
4377
|
|
|
4278
4378
|
// ../nizel/dist/use-nizel.js
|
|
4279
|
-
function createNizel(options = {}) {
|
|
4379
|
+
function createNizel(options = {}, htmlBackend) {
|
|
4280
4380
|
const presetOptions = options.preset ? resolvePreset(options.preset) : {};
|
|
4281
4381
|
const effectiveOptions = { ...presetOptions, ...options, preset: void 0 };
|
|
4282
4382
|
const baseResolved = resolveOptions(effectiveOptions, {});
|
|
@@ -4305,7 +4405,12 @@ ${body}
|
|
|
4305
4405
|
}
|
|
4306
4406
|
const nizel = process;
|
|
4307
4407
|
nizel.html = async (markdown, runtimeOptions) => {
|
|
4308
|
-
const
|
|
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);
|
|
4309
4414
|
return renderPreparedHtml(ast, resolved);
|
|
4310
4415
|
};
|
|
4311
4416
|
nizel.text = async (markdown, runtimeOptions) => {
|
|
@@ -4318,7 +4423,7 @@ ${body}
|
|
|
4318
4423
|
nizel.meta = async (markdown, runtimeOptions) => {
|
|
4319
4424
|
return prepareMeta(markdown, runtimeOptions).meta;
|
|
4320
4425
|
};
|
|
4321
|
-
nizel.preset = (name) => createNizel(resolvePreset(name));
|
|
4426
|
+
nizel.preset = (name) => createNizel(resolvePreset(name), htmlBackend);
|
|
4322
4427
|
nizel.parse = async (markdown, runtimeOptions) => {
|
|
4323
4428
|
const resolved = resolveRuntime(runtimeOptions);
|
|
4324
4429
|
const extracted = resolved.frontmatter === false ? { markdown, frontmatter: {} } : extractFrontmatter(markdown);
|
|
@@ -4342,16 +4447,13 @@ ${body}
|
|
|
4342
4447
|
unwrapStandaloneImages: resolved.unwrapStandaloneImages === true
|
|
4343
4448
|
});
|
|
4344
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
|
+
};
|
|
4345
4455
|
return nizel;
|
|
4346
|
-
function prepareMarkdown(markdown, runtimeOptions = {}) {
|
|
4347
|
-
const preparedMeta = prepareMeta(markdown, runtimeOptions);
|
|
4348
|
-
let preparedMarkdown = preparedMeta.markdown;
|
|
4349
|
-
for (const plugin of preparedMeta.resolved.plugins ?? []) {
|
|
4350
|
-
const nextMarkdown = plugin.hooks?.beforeParse?.(preparedMarkdown, preparedMeta.resolved);
|
|
4351
|
-
if (nextMarkdown !== void 0) {
|
|
4352
|
-
preparedMarkdown = nextMarkdown;
|
|
4353
|
-
}
|
|
4354
|
-
}
|
|
4456
|
+
function prepareMarkdown(markdown, runtimeOptions = {}, preparedMeta = prepareMeta(markdown, runtimeOptions), preparedMarkdown = prepareSource(preparedMeta)) {
|
|
4355
4457
|
let ast = parseMarkdown(preparedMarkdown, {
|
|
4356
4458
|
anchors: preparedMeta.resolved.anchors !== false,
|
|
4357
4459
|
autolinks: preparedMeta.resolved.autolinks,
|
|
@@ -4415,10 +4517,22 @@ ${body}
|
|
|
4415
4517
|
};
|
|
4416
4518
|
}
|
|
4417
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
|
+
}
|
|
4418
4529
|
function renderPreparedHtml(ast, resolved) {
|
|
4419
4530
|
const html = renderHtml(ast, withAutolinkElements(resolved.elements ?? {}, resolved.autolinks), resolved.blocks ?? {}, {
|
|
4420
4531
|
unwrapStandaloneImages: resolved.unwrapStandaloneImages === true
|
|
4421
4532
|
});
|
|
4533
|
+
return applyAfterRender(html, resolved);
|
|
4534
|
+
}
|
|
4535
|
+
function applyAfterRender(html, resolved) {
|
|
4422
4536
|
let finalHtml = html;
|
|
4423
4537
|
for (const plugin of resolved.plugins ?? []) {
|
|
4424
4538
|
const modified = plugin.hooks?.afterRender?.(finalHtml, resolved);
|
|
@@ -4439,8 +4553,13 @@ ${body}
|
|
|
4439
4553
|
function hasRuntimeOptions(runtimeOptions) {
|
|
4440
4554
|
return Boolean(runtimeOptions && Object.keys(runtimeOptions).length > 0);
|
|
4441
4555
|
}
|
|
4442
|
-
|
|
4443
|
-
|
|
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();
|
|
4444
4563
|
function stringMeta(value) {
|
|
4445
4564
|
return typeof value === "string" ? value : void 0;
|
|
4446
4565
|
}
|
|
@@ -4507,6 +4626,121 @@ ${body}
|
|
|
4507
4626
|
return plugin;
|
|
4508
4627
|
};
|
|
4509
4628
|
|
|
4629
|
+
// ../nizel/dist/html-to-markdown.js
|
|
4630
|
+
var htmlChildElements = (node) => node.type === "element" || node.type === "root" ? node.children.filter((child) => child.type === "element") : [];
|
|
4631
|
+
var findHtmlElement = (node, predicate) => htmlChildElements(node).find(predicate);
|
|
4632
|
+
var hasHtmlClass = (node, className) => node.type === "element" && (node.attrs.class ?? "").split(/\s+/).includes(className);
|
|
4633
|
+
var findHtmlDescendant = (node, predicate) => {
|
|
4634
|
+
for (const child of htmlChildElements(node)) {
|
|
4635
|
+
if (predicate(child))
|
|
4636
|
+
return child;
|
|
4637
|
+
const nested = findHtmlDescendant(child, predicate);
|
|
4638
|
+
if (nested)
|
|
4639
|
+
return nested;
|
|
4640
|
+
}
|
|
4641
|
+
return void 0;
|
|
4642
|
+
};
|
|
4643
|
+
var htmlRoot = (children) => ({ type: "root", children });
|
|
4644
|
+
|
|
4645
|
+
// ../plugin-alert/dist/index.js
|
|
4646
|
+
var ALERT_TYPES = ["note", "tip", "important", "warning", "caution"];
|
|
4647
|
+
var alertPlugin = (options = {}) => {
|
|
4648
|
+
const blocks = Object.fromEntries(ALERT_TYPES.map((alertType) => [alertType, createAlertBlock(alertType, options)]));
|
|
4649
|
+
return {
|
|
4650
|
+
name: "alert",
|
|
4651
|
+
blocks,
|
|
4652
|
+
hooks: {
|
|
4653
|
+
beforeParse: transformGitHubAlerts
|
|
4654
|
+
},
|
|
4655
|
+
htmlToMarkdown: alertToMarkdown(options)
|
|
4656
|
+
};
|
|
4657
|
+
};
|
|
4658
|
+
var alertToMarkdown = (options = {}) => {
|
|
4659
|
+
const rootClass = options.className ?? "alert";
|
|
4660
|
+
return (node, ctx) => {
|
|
4661
|
+
if (node.type !== "element" || node.tag !== "div")
|
|
4662
|
+
return void 0;
|
|
4663
|
+
const type = node.attrs["data-alert"];
|
|
4664
|
+
if (!type)
|
|
4665
|
+
return void 0;
|
|
4666
|
+
const titleEl = findHtmlElement(node, (el) => el.tag === "p" && hasHtmlClass(el, `${rootClass}__title`));
|
|
4667
|
+
const contentEl = findHtmlElement(node, (el) => hasHtmlClass(el, `${rootClass}__content`));
|
|
4668
|
+
const title = titleEl ? ctx.text(titleEl).trim() : "";
|
|
4669
|
+
const body = contentEl ? ctx.block(contentEl) : "";
|
|
4670
|
+
return `${title ? `::${type} ${title}` : `::${type}`}
|
|
4671
|
+
${body}
|
|
4672
|
+
::`;
|
|
4673
|
+
};
|
|
4674
|
+
};
|
|
4675
|
+
var transformGitHubAlerts = (markdown) => {
|
|
4676
|
+
const lines = markdown.split("\n");
|
|
4677
|
+
const result = [];
|
|
4678
|
+
let index = 0;
|
|
4679
|
+
while (index < lines.length) {
|
|
4680
|
+
const opener = /^ {0,3}> ?\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*$/i.exec(lines[index]);
|
|
4681
|
+
if (!opener) {
|
|
4682
|
+
result.push(lines[index]);
|
|
4683
|
+
index += 1;
|
|
4684
|
+
continue;
|
|
4685
|
+
}
|
|
4686
|
+
const alertType = opener[1].toLowerCase();
|
|
4687
|
+
const content = [];
|
|
4688
|
+
index += 1;
|
|
4689
|
+
while (index < lines.length) {
|
|
4690
|
+
const quoteLine = /^ {0,3}> ?(.*)$/.exec(lines[index]);
|
|
4691
|
+
if (!quoteLine)
|
|
4692
|
+
break;
|
|
4693
|
+
content.push(quoteLine[1]);
|
|
4694
|
+
index += 1;
|
|
4695
|
+
}
|
|
4696
|
+
result.push(`::${alertType} ${alertTitle(alertType)}`);
|
|
4697
|
+
result.push(...trimAlertContent(content));
|
|
4698
|
+
result.push("::");
|
|
4699
|
+
}
|
|
4700
|
+
return result.join("\n");
|
|
4701
|
+
};
|
|
4702
|
+
var createAlertBlock = (alertType, options) => {
|
|
4703
|
+
return {
|
|
4704
|
+
name: alertType,
|
|
4705
|
+
parse({ args, props }) {
|
|
4706
|
+
const title = props.title ?? args[0] ?? "";
|
|
4707
|
+
return { alertType, title: String(title) };
|
|
4708
|
+
},
|
|
4709
|
+
formats: {
|
|
4710
|
+
html(node, ctx) {
|
|
4711
|
+
if (node.type !== "customBlock" || !isAlertValue(node.value))
|
|
4712
|
+
return "";
|
|
4713
|
+
return renderAlert(node.value, node.children ?? [], ctx, options);
|
|
4714
|
+
}
|
|
4715
|
+
}
|
|
4716
|
+
};
|
|
4717
|
+
};
|
|
4718
|
+
var renderAlert = (value, children, ctx, options) => {
|
|
4719
|
+
const rootClass = options.className ?? "alert";
|
|
4720
|
+
const titleHtml = value.title ? `<p class="${rootClass}__title">${ctx.escape(value.title)}</p>` : "";
|
|
4721
|
+
const contentHtml = ctx.render(children);
|
|
4722
|
+
const escapedType = ctx.escape(value.alertType);
|
|
4723
|
+
return `<div class="${ctx.escape(rootClass)} ${ctx.escape(rootClass)}--${escapedType}" data-alert="${escapedType}">${titleHtml}<div class="${ctx.escape(rootClass)}__content">${contentHtml}</div></div>`;
|
|
4724
|
+
};
|
|
4725
|
+
var trimAlertContent = (lines) => {
|
|
4726
|
+
let start = 0;
|
|
4727
|
+
let end = lines.length;
|
|
4728
|
+
while (start < end && !lines[start].trim())
|
|
4729
|
+
start += 1;
|
|
4730
|
+
while (end > start && !lines[end - 1].trim())
|
|
4731
|
+
end -= 1;
|
|
4732
|
+
return lines.slice(start, end);
|
|
4733
|
+
};
|
|
4734
|
+
var alertTitle = (alertType) => {
|
|
4735
|
+
return alertType.charAt(0).toUpperCase() + alertType.slice(1);
|
|
4736
|
+
};
|
|
4737
|
+
var isAlertValue = (value) => {
|
|
4738
|
+
if (!value || typeof value !== "object")
|
|
4739
|
+
return false;
|
|
4740
|
+
const candidate = value;
|
|
4741
|
+
return typeof candidate.title === "string" && ALERT_TYPES.includes(candidate.alertType);
|
|
4742
|
+
};
|
|
4743
|
+
|
|
4510
4744
|
// ../plugin-autolink/dist/index.js
|
|
4511
4745
|
var resolveAutolinkPluginOptions = (options = {}) => {
|
|
4512
4746
|
return {
|
|
@@ -4520,9 +4754,22 @@ ${body}
|
|
|
4520
4754
|
name: "autolink",
|
|
4521
4755
|
options: {
|
|
4522
4756
|
autolinks: resolveAutolinkPluginOptions(options)
|
|
4523
|
-
}
|
|
4757
|
+
},
|
|
4758
|
+
htmlToMarkdown: autolinkToMarkdown(),
|
|
4759
|
+
htmlToMarkdownTags: ["a"]
|
|
4524
4760
|
});
|
|
4525
4761
|
};
|
|
4762
|
+
var autolinkToMarkdown = () => (node, ctx) => {
|
|
4763
|
+
if (node.type !== "element" || node.tag !== "a")
|
|
4764
|
+
return void 0;
|
|
4765
|
+
const href = node.attrs.href;
|
|
4766
|
+
if (!href)
|
|
4767
|
+
return void 0;
|
|
4768
|
+
const extras = Object.keys(node.attrs).filter((key) => key !== "href" && key !== "target" && key !== "rel");
|
|
4769
|
+
if (extras.length > 0)
|
|
4770
|
+
return void 0;
|
|
4771
|
+
return ctx.text(node).trim() === href ? href : void 0;
|
|
4772
|
+
};
|
|
4526
4773
|
|
|
4527
4774
|
// ../plugin-task-list/dist/index.js
|
|
4528
4775
|
var taskListPlugin = (options = {}) => {
|
|
@@ -4533,9 +4780,49 @@ ${body}
|
|
|
4533
4780
|
afterParse(ast) {
|
|
4534
4781
|
return transformTaskLists(ast, mode);
|
|
4535
4782
|
}
|
|
4536
|
-
}
|
|
4783
|
+
},
|
|
4784
|
+
// Only items written with a `[ ]` or `[x]` box become task items.
|
|
4785
|
+
afterParseApplies: (markdown) => markdown.includes("["),
|
|
4786
|
+
htmlToMarkdown: taskListToMarkdown(),
|
|
4787
|
+
htmlToMarkdownTags: ["ul", "ol"]
|
|
4537
4788
|
};
|
|
4538
4789
|
};
|
|
4790
|
+
var CHECKBOX_ATTR = "data-nizel-task-checkbox";
|
|
4791
|
+
var isCheckbox = (node) => node.type === "element" && node.tag === "input" && node.attrs?.[CHECKBOX_ATTR] !== void 0;
|
|
4792
|
+
var taskListToMarkdown = () => (node, ctx) => {
|
|
4793
|
+
if (node.type !== "element" || node.tag !== "ul" && node.tag !== "ol")
|
|
4794
|
+
return void 0;
|
|
4795
|
+
const items = htmlChildElements(node).filter((el) => el.tag === "li");
|
|
4796
|
+
if (!items.some((item) => findHtmlDescendant(item, isCheckbox)))
|
|
4797
|
+
return void 0;
|
|
4798
|
+
const ordered = node.tag === "ol";
|
|
4799
|
+
const start = Number(node.attrs.start ?? 1);
|
|
4800
|
+
return items.map((item, index) => {
|
|
4801
|
+
const checkbox = findHtmlDescendant(item, isCheckbox);
|
|
4802
|
+
const body = ctx.block(htmlRoot(cleanTaskChildren(item.children))).trim();
|
|
4803
|
+
const baseMarker = ordered ? `${start + index}. ` : "- ";
|
|
4804
|
+
const marker = checkbox ? `${baseMarker}${checkbox.attrs.checked !== void 0 ? "[x] " : "[ ] "}` : baseMarker;
|
|
4805
|
+
return ctx.indent(`${marker}${body}`, marker.length);
|
|
4806
|
+
}).join("\n");
|
|
4807
|
+
};
|
|
4808
|
+
var cleanTaskChildren = (nodes) => {
|
|
4809
|
+
const result = [];
|
|
4810
|
+
for (const node of nodes) {
|
|
4811
|
+
if (node.type === "element") {
|
|
4812
|
+
if (isCheckbox(node))
|
|
4813
|
+
continue;
|
|
4814
|
+
const cleaned = { ...node, children: cleanTaskChildren(node.children) };
|
|
4815
|
+
if (hasHtmlClass(cleaned, "nizel-task-list__label") || hasHtmlClass(cleaned, "nizel-task-list__content")) {
|
|
4816
|
+
result.push(...cleaned.children);
|
|
4817
|
+
} else {
|
|
4818
|
+
result.push(cleaned);
|
|
4819
|
+
}
|
|
4820
|
+
} else {
|
|
4821
|
+
result.push(node);
|
|
4822
|
+
}
|
|
4823
|
+
}
|
|
4824
|
+
return result;
|
|
4825
|
+
};
|
|
4539
4826
|
var transformTaskLists = (ast, mode = "view") => {
|
|
4540
4827
|
return { ...ast, children: ast.children.map((node) => transformBlock(node, mode)) };
|
|
4541
4828
|
};
|