@vite-hub/docs 0.0.0 → 0.4.1
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/LICENSE +201 -0
- package/README.md +456 -0
- package/dist/agent-copy-xPaWye_g.js +33 -0
- package/dist/assistant-pages-BN7hNsSZ.js +37 -0
- package/dist/assistant-shared-CWIKRtBv.d.ts +28 -0
- package/dist/assistant-shared-WzButktj.js +113 -0
- package/dist/assistant-worker.d.ts +11 -0
- package/dist/assistant-worker.js +16 -0
- package/dist/assistant.d.ts +14 -0
- package/dist/assistant.js +19 -0
- package/dist/content-CPZGnn3S.js +141 -0
- package/dist/draft-BjWmaiLn.js +45 -0
- package/dist/error-diagnostics-B_ZOy7kF.js +93 -0
- package/dist/files-UY4h1_36.js +38 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +27 -0
- package/dist/link-checker-redirects.d.ts +13 -0
- package/dist/link-checker-redirects.js +25 -0
- package/dist/manifest-CMoxcwPm.d.ts +80 -0
- package/dist/manifest-ZdxLrcvt.js +434 -0
- package/dist/markdown-DUWnEMPp.js +378 -0
- package/dist/navigation.d.ts +283 -0
- package/dist/navigation.js +519 -0
- package/dist/nuxt-CAGpKl_-.d.ts +241 -0
- package/dist/nuxt.d.ts +3 -0
- package/dist/nuxt.js +1868 -0
- package/dist/page-Dx2JD3y1.d.ts +74 -0
- package/dist/page-GPt09oex.js +82 -0
- package/dist/primitive-rail.d.ts +110 -0
- package/dist/primitive-rail.js +289 -0
- package/dist/raw-BChwipz_.js +857 -0
- package/dist/redirects-CmR1yu5A.js +74 -0
- package/dist/runtime/app/app.vue +11 -0
- package/dist/runtime/app/assistant/DocsAssistant.vue +81 -0
- package/dist/runtime/app/assistant/DocsAssistantOff.vue +8 -0
- package/dist/runtime/app/assistant/DocsAssistantPanel.vue +322 -0
- package/dist/runtime/app/components/AppHeader.vue +368 -0
- package/dist/runtime/app/components/AppSearch.vue +68 -0
- package/dist/runtime/app/components/DocsAppShell.vue +62 -0
- package/dist/runtime/app/components/DocsArticle.vue +184 -0
- package/dist/runtime/app/components/DocsAsideFooter.vue +94 -0
- package/dist/runtime/app/components/DocsAsideLeftBody.vue +584 -0
- package/dist/runtime/app/components/DocsAsideLeftTop.vue +132 -0
- package/dist/runtime/app/components/DocsBrandMark.vue +52 -0
- package/dist/runtime/app/components/DocsCatalogFooter.vue +129 -0
- package/dist/runtime/app/components/DocsCodePanel.vue +388 -0
- package/dist/runtime/app/components/DocsCodePre.vue +120 -0
- package/dist/runtime/app/components/DocsHeaderActions.vue +4 -0
- package/dist/runtime/app/components/DocsLanding.vue +83 -0
- package/dist/runtime/app/components/DocsMarkdown.vue +64 -0
- package/dist/runtime/app/components/DocsPage.vue +149 -0
- package/dist/runtime/app/components/DocsPageCredits.vue +41 -0
- package/dist/runtime/app/components/DocsPageHeaderLinks.vue +120 -0
- package/dist/runtime/app/components/DocsRail.vue +239 -0
- package/dist/runtime/app/components/DocsSidebarStrip.vue +81 -0
- package/dist/runtime/app/components/DocsSidebars.vue +63 -0
- package/dist/runtime/app/components/OgImage/DocsPage.takumi.vue +33 -0
- package/dist/runtime/app/components/content/AgentOnly.vue +9 -0
- package/dist/runtime/app/components/content/CodeTree.vue +203 -0
- package/dist/runtime/app/components/content/ComarkHtml.vue +31 -0
- package/dist/runtime/app/components/content/Correct.vue +17 -0
- package/dist/runtime/app/components/content/Example.vue +260 -0
- package/dist/runtime/app/components/content/ExamplePreview.vue +6 -0
- package/dist/runtime/app/components/content/Examples.vue +71 -0
- package/dist/runtime/app/components/content/Incorrect.vue +17 -0
- package/dist/runtime/app/components/content/McpClient.vue +170 -0
- package/dist/runtime/app/components/content/McpInstall.vue +238 -0
- package/dist/runtime/app/components/content/PageList.vue +206 -0
- package/dist/runtime/app/components/content/ProductFeatureItem.vue +43 -0
- package/dist/runtime/app/components/content/ProductFeatures.vue +17 -0
- package/dist/runtime/app/components/content/TutorialStep.vue +39 -0
- package/dist/runtime/app/composables/docs-assistant-problem.ts +59 -0
- package/dist/runtime/app/composables/docs-theme.ts +15 -0
- package/dist/runtime/app/composables/docs.ts +83 -0
- package/dist/runtime/app/composables/headerActions.ts +6 -0
- package/dist/runtime/app/composables/icons.ts +14 -0
- package/dist/runtime/app/composables/seo.ts +64 -0
- package/dist/runtime/app/composables/tutorial.ts +40 -0
- package/dist/runtime/app/composables/useDocsAssistant.ts +17 -0
- package/dist/runtime/app/error.vue +88 -0
- package/dist/runtime/app/layouts/default.vue +7 -0
- package/dist/runtime/app/layouts/docs.vue +104 -0
- package/dist/runtime/app/middleware/docs-layout.ts +23 -0
- package/dist/runtime/app/pages/docs-page.vue +3 -0
- package/dist/runtime/app/plugins/comark-css.ts +14 -0
- package/dist/runtime/app/plugins/icon-stroke.ts +12 -0
- package/dist/runtime/app/plugins/theme-color.ts +18 -0
- package/dist/runtime/app/utils/docs-theme.ts +43 -0
- package/dist/runtime/app/utils/file-tree.ts +40 -0
- package/dist/runtime/server/llms.d.ts +6 -0
- package/dist/runtime/server/llms.js +7 -0
- package/dist/runtime/server/markdown.d.ts +10 -0
- package/dist/runtime/server/markdown.js +11 -0
- package/dist/runtime/server/mcp.d.ts +6 -0
- package/dist/runtime/server/mcp.js +7 -0
- package/dist/runtime/server/page.d.ts +7 -0
- package/dist/runtime/server/page.js +27 -0
- package/dist/runtime/server/raw.d.ts +10 -0
- package/dist/runtime/server/raw.js +23 -0
- package/dist/runtime/server/search.d.ts +6 -0
- package/dist/runtime/server/search.js +32 -0
- package/dist/runtime/server/sitemap.d.ts +6 -0
- package/dist/runtime/server/sitemap.js +52 -0
- package/dist/runtime/server/trailing-slash.d.ts +10 -0
- package/dist/runtime/server/trailing-slash.js +28 -0
- package/dist/runtime/theme/design.css +464 -0
- package/dist/schema-DwpXW0VZ.js +98 -0
- package/dist/server.d.ts +15 -0
- package/dist/server.js +5 -0
- package/dist/theme-BXyu4uFL.d.ts +32 -0
- package/dist/theme-DzC8LtMH.js +237 -0
- package/dist/theme.d.ts +2 -0
- package/dist/theme.js +2 -0
- package/dist/types-BhG6vGfG.d.ts +212 -0
- package/package.json +144 -1
|
@@ -0,0 +1,857 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { parse } from "yaml";
|
|
3
|
+
//#region src/raw.ts
|
|
4
|
+
const frontmatterBoundary = "---";
|
|
5
|
+
const frontmatterSchema = z.object({ title: z.string().optional() });
|
|
6
|
+
const pageCardSchema = z.object({
|
|
7
|
+
description: z.string().optional(),
|
|
8
|
+
title: z.string().optional(),
|
|
9
|
+
to: z.string().optional()
|
|
10
|
+
});
|
|
11
|
+
function fenceRun(line) {
|
|
12
|
+
let rest = line;
|
|
13
|
+
let consumed = "";
|
|
14
|
+
let listIndent = null;
|
|
15
|
+
let quoteDepth = 0;
|
|
16
|
+
while (true) {
|
|
17
|
+
const container = rest.match(/^[ \t]*(?:(>)|(?:[-+*]|\d{1,9}[.)])[ \t]+)/);
|
|
18
|
+
if (!container) break;
|
|
19
|
+
if (container[1]) quoteDepth += 1;
|
|
20
|
+
else listIndent = indentationColumns((consumed + container[0]).replace(/>[ \t]?/g, "").replace(/[^ \t]/g, " "));
|
|
21
|
+
consumed += container[0];
|
|
22
|
+
rest = rest.slice(container[0].length);
|
|
23
|
+
}
|
|
24
|
+
const match = rest.match(/^([ \t]*)(```+|~~~+)/);
|
|
25
|
+
if (!match || indentationColumns(match[1]) > 3) return null;
|
|
26
|
+
const info = rest.slice(match[0].length);
|
|
27
|
+
if (match[2][0] === "`" && info.includes("`")) return null;
|
|
28
|
+
return match ? {
|
|
29
|
+
listIndent,
|
|
30
|
+
quoteDepth,
|
|
31
|
+
rest: rest.slice(match[0].length),
|
|
32
|
+
run: match[2]
|
|
33
|
+
} : null;
|
|
34
|
+
}
|
|
35
|
+
function closesFence(line, fence) {
|
|
36
|
+
const parsed = fenceRun(line);
|
|
37
|
+
return parsed?.listIndent === null && parsed.quoteDepth === fence.quoteDepth && parsed.run[0] === fence.marker && parsed.run.length >= fence.length && /^[ \t]*$/.test(parsed.rest);
|
|
38
|
+
}
|
|
39
|
+
function leadingQuoteDepth(line) {
|
|
40
|
+
return (line.match(/^[ \t]*(?:>[ \t]*)+/)?.[0].match(/>/g) || []).length;
|
|
41
|
+
}
|
|
42
|
+
function indentationOutsideQuotes(line) {
|
|
43
|
+
const prefix = line.match(/^(?:[ \t]*>[ \t]?)+/)?.[0] || "";
|
|
44
|
+
return indentationColumns(prefix.replace(/>[ \t]?/g, "") + line.slice(prefix.length));
|
|
45
|
+
}
|
|
46
|
+
function markdownContainer(line) {
|
|
47
|
+
const parsed = fenceRun(`${referenceContainer(line)}\`\`\``);
|
|
48
|
+
return {
|
|
49
|
+
listIndent: parsed?.listIndent ?? null,
|
|
50
|
+
quoteDepth: parsed?.quoteDepth ?? 0
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function exitsMarkdownContainer(line, listIndent, quoteDepth) {
|
|
54
|
+
return leadingQuoteDepth(line) < quoteDepth || listIndent !== null && line.trim() !== "" && indentationOutsideQuotes(line) < listIndent;
|
|
55
|
+
}
|
|
56
|
+
function splitFrontmatter(source) {
|
|
57
|
+
const normalized = source.replaceAll("\r\n", "\n");
|
|
58
|
+
if (!normalized.startsWith(`${frontmatterBoundary}\n`)) return {
|
|
59
|
+
body: normalized,
|
|
60
|
+
frontmatter: {}
|
|
61
|
+
};
|
|
62
|
+
const closing = normalized.slice(4).match(/\n---(?:\n|$)/);
|
|
63
|
+
if (!closing || closing.index === void 0) return {
|
|
64
|
+
body: normalized,
|
|
65
|
+
frontmatter: {}
|
|
66
|
+
};
|
|
67
|
+
const end = 4 + closing.index;
|
|
68
|
+
const parsed = parse(normalized.slice(4, end));
|
|
69
|
+
const result = frontmatterSchema.safeParse(parsed);
|
|
70
|
+
const frontmatter = result.success ? result.data : {};
|
|
71
|
+
return {
|
|
72
|
+
body: normalized.slice(end + closing[0].length),
|
|
73
|
+
frontmatter
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function absoluteUrl(value, links) {
|
|
77
|
+
if (!links.siteUrl || value.startsWith("//") || /^[a-z][a-z\d+.-]*:/i.test(value)) return value;
|
|
78
|
+
if (value.startsWith("/")) return `${links.siteUrl}${value}`;
|
|
79
|
+
return links.pagePath ? new URL(value, `${links.siteUrl}${links.pagePath}`).href : value;
|
|
80
|
+
}
|
|
81
|
+
function rewriteInlineMarkdownLinks(line, links, protectedHtmlMarker) {
|
|
82
|
+
let cursor = 0;
|
|
83
|
+
let output = "";
|
|
84
|
+
for (let opening = 0; opening < line.length; opening += 1) {
|
|
85
|
+
if (line[opening] !== "[" || isEscaped(line, opening)) continue;
|
|
86
|
+
let depth = 1;
|
|
87
|
+
let closing = opening + 1;
|
|
88
|
+
for (; closing < line.length && depth > 0; closing += 1) {
|
|
89
|
+
if (isEscaped(line, closing)) continue;
|
|
90
|
+
if (line[closing] === "[") depth += 1;
|
|
91
|
+
else if (line[closing] === "]") depth -= 1;
|
|
92
|
+
}
|
|
93
|
+
if (depth !== 0 || line[closing] !== "(") continue;
|
|
94
|
+
let targetStart = closing + 1;
|
|
95
|
+
while (targetStart < line.length && /[ \t\n]/.test(line[targetStart])) targetStart += 1;
|
|
96
|
+
const angleDestination = line[targetStart] === "<";
|
|
97
|
+
let targetEnd = targetStart + (angleDestination ? 1 : 0);
|
|
98
|
+
if (angleDestination) {
|
|
99
|
+
while (targetEnd < line.length && line[targetEnd] !== ">" && line[targetEnd] !== "\n") targetEnd += 1;
|
|
100
|
+
if (line[targetEnd] !== ">") continue;
|
|
101
|
+
} else {
|
|
102
|
+
let parentheses = 0;
|
|
103
|
+
let invalidDestination = false;
|
|
104
|
+
while (targetEnd < line.length) {
|
|
105
|
+
const character = line[targetEnd];
|
|
106
|
+
if (character === "(" && !isEscaped(line, targetEnd)) {
|
|
107
|
+
parentheses += 1;
|
|
108
|
+
if (parentheses > 32) {
|
|
109
|
+
invalidDestination = true;
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
} else if (character === ")" && !isEscaped(line, targetEnd)) {
|
|
113
|
+
if (parentheses === 0) break;
|
|
114
|
+
parentheses -= 1;
|
|
115
|
+
} else if (/\s/.test(character)) {
|
|
116
|
+
if (parentheses > 0) invalidDestination = true;
|
|
117
|
+
break;
|
|
118
|
+
} else if ((character === "<" || character === ">") && !isEscaped(line, targetEnd) || protectedHtmlMarker && line.startsWith(protectedHtmlMarker, targetEnd)) {
|
|
119
|
+
invalidDestination = true;
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
targetEnd += 1;
|
|
123
|
+
}
|
|
124
|
+
if (invalidDestination) continue;
|
|
125
|
+
}
|
|
126
|
+
const linkClosing = inlineLinkClosing(line, targetEnd + (angleDestination ? 1 : 0));
|
|
127
|
+
if (targetEnd === targetStart || linkClosing === null) continue;
|
|
128
|
+
const destinationStart = targetStart + (angleDestination ? 1 : 0);
|
|
129
|
+
output += line.slice(cursor, destinationStart) + absoluteUrl(line.slice(destinationStart, targetEnd), links);
|
|
130
|
+
cursor = targetEnd;
|
|
131
|
+
opening = linkClosing;
|
|
132
|
+
}
|
|
133
|
+
return output + line.slice(cursor);
|
|
134
|
+
}
|
|
135
|
+
function inlineLinkClosing(line, suffixStart) {
|
|
136
|
+
if (line[suffixStart] === ")") return suffixStart;
|
|
137
|
+
let cursor = suffixStart;
|
|
138
|
+
while (cursor < line.length && /[ \t\n]/.test(line[cursor])) cursor += 1;
|
|
139
|
+
if (cursor === suffixStart) return null;
|
|
140
|
+
const opener = line[cursor];
|
|
141
|
+
const closer = opener === "(" ? ")" : opener === "\"" ? "\"" : opener === "'" ? "'" : null;
|
|
142
|
+
if (!closer) return null;
|
|
143
|
+
cursor += 1;
|
|
144
|
+
for (; cursor < line.length; cursor += 1) {
|
|
145
|
+
if (line[cursor] === "\\") {
|
|
146
|
+
cursor += 1;
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (line[cursor] === closer) break;
|
|
150
|
+
if (opener === "(" && line[cursor] === "(") return null;
|
|
151
|
+
}
|
|
152
|
+
if (line[cursor] !== closer) return null;
|
|
153
|
+
cursor += 1;
|
|
154
|
+
while (cursor < line.length && /[ \t\n]/.test(line[cursor])) cursor += 1;
|
|
155
|
+
return line[cursor] === ")" ? cursor : null;
|
|
156
|
+
}
|
|
157
|
+
function rewriteMarkdownLinks(line, links, protectedHtmlMarker) {
|
|
158
|
+
return rewriteInlineMarkdownLinks(line, links, protectedHtmlMarker);
|
|
159
|
+
}
|
|
160
|
+
function referenceContainer(line) {
|
|
161
|
+
let rest = line;
|
|
162
|
+
let prefix = "";
|
|
163
|
+
while (true) {
|
|
164
|
+
const match = rest.match(/^[ \t]{0,3}(?:>[ \t]?|(?:[-+*]|\d{1,9}[.)])[ \t]+)/);
|
|
165
|
+
if (!match) return prefix;
|
|
166
|
+
prefix += match[0];
|
|
167
|
+
rest = rest.slice(match[0].length);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
function validReferenceLabel(label) {
|
|
171
|
+
let characters = 0;
|
|
172
|
+
for (let index = 0; index < label.length; index += 1) {
|
|
173
|
+
if (label[index] === "\\") index += 1;
|
|
174
|
+
else if (label[index] === "[") return false;
|
|
175
|
+
characters += 1;
|
|
176
|
+
}
|
|
177
|
+
return characters > 0 && characters <= 999;
|
|
178
|
+
}
|
|
179
|
+
function validReferenceSuffix(suffix) {
|
|
180
|
+
if (!suffix) return true;
|
|
181
|
+
const trimmed = suffix.trimStart();
|
|
182
|
+
if (trimmed.length === suffix.length) return false;
|
|
183
|
+
const close = {
|
|
184
|
+
"\"": "\"",
|
|
185
|
+
"'": "'",
|
|
186
|
+
"(": ")"
|
|
187
|
+
}[trimmed[0]];
|
|
188
|
+
if (!close || trimmed.length < 2 || !trimmed.endsWith(close)) return false;
|
|
189
|
+
for (let index = 1; index < trimmed.length - 1; index += 1) {
|
|
190
|
+
if (trimmed[index] === "\\") {
|
|
191
|
+
if (index + 1 === trimmed.length - 1) return false;
|
|
192
|
+
index += 1;
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
if (trimmed[index] === close || trimmed[0] === "(" && trimmed[index] === "(") return false;
|
|
196
|
+
}
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
function parseReferenceDestination(value) {
|
|
200
|
+
if (value.startsWith("<")) {
|
|
201
|
+
const end = value.indexOf(">");
|
|
202
|
+
if (end === -1 || value.slice(1, end).includes("<")) return null;
|
|
203
|
+
return {
|
|
204
|
+
angle: true,
|
|
205
|
+
destination: value.slice(1, end),
|
|
206
|
+
suffix: value.slice(end + 1)
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
let depth = 0;
|
|
210
|
+
let end = 0;
|
|
211
|
+
while (end < value.length) {
|
|
212
|
+
const character = value[end];
|
|
213
|
+
if (character === "\\") {
|
|
214
|
+
if (end + 1 >= value.length) return null;
|
|
215
|
+
end += 2;
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
if (/\s/.test(character)) break;
|
|
219
|
+
if (character === "<" || character === ">") return null;
|
|
220
|
+
if (character === "(") {
|
|
221
|
+
depth += 1;
|
|
222
|
+
if (depth > 32) return null;
|
|
223
|
+
} else if (character === ")") {
|
|
224
|
+
if (depth === 0) return null;
|
|
225
|
+
depth -= 1;
|
|
226
|
+
}
|
|
227
|
+
end += 1;
|
|
228
|
+
}
|
|
229
|
+
if (end === 0 || depth !== 0) return null;
|
|
230
|
+
return {
|
|
231
|
+
angle: false,
|
|
232
|
+
destination: value.slice(0, end),
|
|
233
|
+
suffix: value.slice(end)
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
function rewriteReferenceDefinitions(source, links) {
|
|
237
|
+
const lines = source.split("\n");
|
|
238
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
239
|
+
const line = lines[index];
|
|
240
|
+
const container = referenceContainer(line);
|
|
241
|
+
const definition = line.slice(container.length).match(/^([ \t]{0,3})\[((?:\\.|[^\\\]])+)\]:([ \t]*)(.*)$/);
|
|
242
|
+
if (!definition) continue;
|
|
243
|
+
if (!validReferenceLabel(definition[2])) continue;
|
|
244
|
+
let destinationLine = index;
|
|
245
|
+
let destinationPrefix = `${container}${definition[1]}[${definition[2]}]:${definition[3]}`;
|
|
246
|
+
let destinationAndTitle = definition[4];
|
|
247
|
+
if (!destinationAndTitle) {
|
|
248
|
+
const next = lines[index + 1];
|
|
249
|
+
if (next === void 0) continue;
|
|
250
|
+
const nextContainer = referenceContainer(next);
|
|
251
|
+
if (leadingQuoteDepth(nextContainer) !== leadingQuoteDepth(container)) continue;
|
|
252
|
+
const continuation = next.slice(nextContainer.length).match(/^([ \t]{1,3})(\S.*)$/);
|
|
253
|
+
if (!continuation) continue;
|
|
254
|
+
destinationLine = index + 1;
|
|
255
|
+
destinationPrefix = `${nextContainer}${continuation[1]}`;
|
|
256
|
+
destinationAndTitle = continuation[2];
|
|
257
|
+
}
|
|
258
|
+
const parsed = parseReferenceDestination(destinationAndTitle);
|
|
259
|
+
if (!parsed) continue;
|
|
260
|
+
if (!validReferenceSuffix(parsed.suffix)) continue;
|
|
261
|
+
lines[destinationLine] = parsed.angle ? `${destinationPrefix}<${absoluteUrl(parsed.destination, links)}>${parsed.suffix}` : `${destinationPrefix}${absoluteUrl(parsed.destination, links)}${parsed.suffix}`;
|
|
262
|
+
}
|
|
263
|
+
return lines.join("\n");
|
|
264
|
+
}
|
|
265
|
+
function isCompleteReferenceDefinition(line) {
|
|
266
|
+
const definition = line.slice(referenceContainer(line).length).match(/^[ \t]{0,3}\[((?:\\.|[^\\\]])+)\]:[ \t]*(.*)$/);
|
|
267
|
+
if (!definition || !validReferenceLabel(definition[1])) return false;
|
|
268
|
+
const parsed = parseReferenceDestination(definition[2]);
|
|
269
|
+
return Boolean(parsed && validReferenceSuffix(parsed.suffix));
|
|
270
|
+
}
|
|
271
|
+
function isOrdinaryParagraphLine(line) {
|
|
272
|
+
const content = line.slice(referenceContainer(line).length).trimStart();
|
|
273
|
+
return Boolean(content) && !/^(?:`|~|:{2,}|\[((?:\\.|[^\\\]])+)\]:)/.test(content);
|
|
274
|
+
}
|
|
275
|
+
function rawHtmlBlockEnd(line) {
|
|
276
|
+
const start = line.match(/^[ \t]{0,3}<(script|pre|style|textarea)(?:[ \t>]|$)/i);
|
|
277
|
+
if (start) return new RegExp(`</${start[1]}>`, "i");
|
|
278
|
+
if (/^[ \t]{0,3}<!--/.test(line)) return /-->/;
|
|
279
|
+
if (/^[ \t]{0,3}<\?/.test(line)) return /\?>/;
|
|
280
|
+
if (/^[ \t]{0,3}<![A-Z]/.test(line)) return />/;
|
|
281
|
+
if (/^[ \t]{0,3}<!\[CDATA\[/.test(line)) return /\]\]>/;
|
|
282
|
+
if (/^[ \t]{0,3}<\/?(?:address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)(?:[ \t/>]|$)/i.test(line)) return /^\s*$/;
|
|
283
|
+
if (/^[ \t]{0,3}(?:<\/?[A-Za-z][A-Za-z0-9-]*(?:[ \t]+[A-Za-z_:][A-Za-z0-9_.:-]*(?:[ \t]*=[ \t]*(?:[^ \t\n"'=<>`]+|'[^']*'|"[^"]*"))?)*[ \t]*\/?>)[ \t]*$/.test(line)) return /^\s*$/;
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
function isTypeSevenHtml(line, end) {
|
|
287
|
+
return end.source === "^\\s*$" && !/^[ \t]{0,3}<\/?(?:address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)(?:[ \t/>]|$)/i.test(line);
|
|
288
|
+
}
|
|
289
|
+
function withoutMarkdownContainers(line, listIndent = null) {
|
|
290
|
+
const container = referenceContainer(line);
|
|
291
|
+
const content = line.slice(container.length);
|
|
292
|
+
return listIndent !== null && indentationColumns(content) >= listIndent ? removeIndentation(content, listIndent) : content;
|
|
293
|
+
}
|
|
294
|
+
function htmlBlockContinues(end, openingLine) {
|
|
295
|
+
return end.source === "^\\s*$" || !end.test(openingLine);
|
|
296
|
+
}
|
|
297
|
+
function startsParagraph(line, paragraphOpen) {
|
|
298
|
+
const container = referenceContainer(line);
|
|
299
|
+
const content = line.slice(container.length);
|
|
300
|
+
if (/^[ \t]{0,3}#{1,6}(?:[ \t]+|$)/.test(content)) return false;
|
|
301
|
+
if (/^[ \t]{0,3}(?:=+|-+)[ \t]*$/.test(content)) return !paragraphOpen;
|
|
302
|
+
if (/^[ \t]{0,3}(?:(?:\*[ \t]*){3,}|(?:_[ \t]*){3,}|(?:-[ \t]*){3,})$/.test(content)) return false;
|
|
303
|
+
const definition = content.match(/^[ \t]{0,3}\[((?:\\.|[^\\\]])+)\]:[ \t]*(.*)$/);
|
|
304
|
+
if (definition && validReferenceLabel(definition[1])) {
|
|
305
|
+
const parsed = parseReferenceDestination(definition[2]);
|
|
306
|
+
if (parsed && validReferenceSuffix(parsed.suffix)) return paragraphOpen;
|
|
307
|
+
}
|
|
308
|
+
if (/^[ \t]*:{2,}/.test(content)) return false;
|
|
309
|
+
return Boolean(content.trim());
|
|
310
|
+
}
|
|
311
|
+
function interruptsInlineBlock(line) {
|
|
312
|
+
const container = referenceContainer(line);
|
|
313
|
+
const content = line.slice(container.length);
|
|
314
|
+
if (/^[ \t]{0,3}#{1,6}(?:[ \t]+|$)/.test(content)) return true;
|
|
315
|
+
if (/^[ \t]{0,3}(?:(?:\*[ \t]*){3,}|(?:_[ \t]*){3,}|(?:-[ \t]*){3,})$/.test(content)) return true;
|
|
316
|
+
if (/^[ \t]*:{2,}/.test(content)) return true;
|
|
317
|
+
return false;
|
|
318
|
+
}
|
|
319
|
+
function isEscaped(source, index) {
|
|
320
|
+
let backslashes = 0;
|
|
321
|
+
while (index > backslashes && source[index - backslashes - 1] === "\\") backslashes += 1;
|
|
322
|
+
return backslashes % 2 === 1;
|
|
323
|
+
}
|
|
324
|
+
function protectCodeSpans(source) {
|
|
325
|
+
let protectedSource = "";
|
|
326
|
+
let offset = 0;
|
|
327
|
+
const codeSpans = [];
|
|
328
|
+
let placeholderPrefix = "__VITEHUB_RAW_CODE_SPAN_";
|
|
329
|
+
while (source.includes(placeholderPrefix)) placeholderPrefix += "_";
|
|
330
|
+
for (const opening of source.matchAll(/`+/g)) {
|
|
331
|
+
const openingIndex = opening.index;
|
|
332
|
+
if (openingIndex < offset || isEscaped(source, openingIndex)) continue;
|
|
333
|
+
const marker = opening[0];
|
|
334
|
+
const closingPattern = new RegExp(`(?<!\`)${marker}(?!\`)`, "g");
|
|
335
|
+
closingPattern.lastIndex = openingIndex + marker.length;
|
|
336
|
+
const closing = closingPattern.exec(source);
|
|
337
|
+
if (!closing) continue;
|
|
338
|
+
protectedSource += source.slice(offset, openingIndex);
|
|
339
|
+
const index = codeSpans.push(source.slice(openingIndex, closing.index + marker.length)) - 1;
|
|
340
|
+
protectedSource += `${placeholderPrefix}${index}__`;
|
|
341
|
+
offset = closing.index + marker.length;
|
|
342
|
+
}
|
|
343
|
+
protectedSource += source.slice(offset);
|
|
344
|
+
return {
|
|
345
|
+
protectedSource,
|
|
346
|
+
restore(transformed) {
|
|
347
|
+
return transformed.replace(new RegExp(`${placeholderPrefix}(\\d+)__`, "g"), (_match, index) => codeSpans[Number(index)]);
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
function rewriteInlineLinks(source, links) {
|
|
352
|
+
const codeSpans = protectCodeSpans(source);
|
|
353
|
+
let protectedSource = codeSpans.protectedSource;
|
|
354
|
+
const htmlTags = [];
|
|
355
|
+
let htmlPlaceholderPrefix = "__VITEHUB_RAW_HTML_TAG_";
|
|
356
|
+
while (protectedSource.includes(htmlPlaceholderPrefix)) htmlPlaceholderPrefix += "_";
|
|
357
|
+
protectedSource = protectedSource.replace(/<!--[\s\S]*?-->|<\?[\s\S]*?\?>|<![A-Z][^>]*>|<!\[CDATA\[[\s\S]*?\]\]>|<\/?[A-Za-z][A-Za-z0-9-]*(?:[ \t\n]+[A-Za-z_:][A-Za-z0-9_.:-]*(?:[ \t\n]*=[ \t\n]*(?:[^ \t\n"'=<>`]+|'[^']*'|"[^"]*"))?)*[ \t\n]*\/?>/g, (tag, offset) => isEscaped(protectedSource, offset) ? tag : `${htmlPlaceholderPrefix}${htmlTags.push(tag) - 1}__`);
|
|
358
|
+
return codeSpans.restore(rewriteMarkdownLinks(protectedSource, links, htmlPlaceholderPrefix).replace(new RegExp(`${htmlPlaceholderPrefix}(\\d+)__`, "g"), (_match, index) => htmlTags[Number(index)]));
|
|
359
|
+
}
|
|
360
|
+
function isMarkdownThematicBreak(content) {
|
|
361
|
+
const indentation = content.match(/^[ \t]*/)?.[0] || "";
|
|
362
|
+
if (indentationColumns(indentation) > 3) return false;
|
|
363
|
+
return /^(?:(?:\*[ \t]*){3,}|(?:_[ \t]*){3,}|(?:-[ \t]*){3,})$/.test(content.slice(indentation.length));
|
|
364
|
+
}
|
|
365
|
+
function markdownListItemPrefix(content) {
|
|
366
|
+
const indentation = content.match(/^[ \t]*/)?.[0] || "";
|
|
367
|
+
if (indentationColumns(indentation) > 3) return null;
|
|
368
|
+
const marker = content.slice(indentation.length).match(/^(?:[-+*]|\d{1,9}[.)])/)?.[0];
|
|
369
|
+
if (!marker) return null;
|
|
370
|
+
const markerEnd = indentation.length + marker.length;
|
|
371
|
+
const padding = content.slice(markerEnd).match(/^[ \t]+/)?.[0];
|
|
372
|
+
if (!padding) return null;
|
|
373
|
+
const beforePadding = `${indentation}${marker.replace(/./g, " ")}`;
|
|
374
|
+
const paddingColumns = indentationColumns(`${beforePadding}${padding}`) - indentationColumns(beforePadding);
|
|
375
|
+
return paddingColumns >= 1 && paddingColumns <= 4 ? content.slice(0, markerEnd + padding.length) : null;
|
|
376
|
+
}
|
|
377
|
+
function updateMarkdownListState(line, state) {
|
|
378
|
+
const quotePrefix = line.match(/^(?:[ \t]*>[ \t]?)+/)?.[0] || "";
|
|
379
|
+
const content = line.slice(quotePrefix.length);
|
|
380
|
+
if (isMarkdownThematicBreak(content)) {
|
|
381
|
+
state.indent = null;
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
let listPrefix = "";
|
|
385
|
+
let remainder = content;
|
|
386
|
+
while (true) {
|
|
387
|
+
const listItem = markdownListItemPrefix(remainder);
|
|
388
|
+
if (!listItem) break;
|
|
389
|
+
listPrefix += listItem;
|
|
390
|
+
remainder = remainder.slice(listItem.length);
|
|
391
|
+
}
|
|
392
|
+
if (listPrefix) {
|
|
393
|
+
state.indent = indentationColumns(listPrefix.replace(/[^ \t]/g, " "));
|
|
394
|
+
state.quotePrefix = quotePrefix;
|
|
395
|
+
} else if (content.trim() && (state.indent === null || quotePrefix !== state.quotePrefix || indentationColumns(content) < state.indent)) state.indent = null;
|
|
396
|
+
}
|
|
397
|
+
function activeListIndent(line, state) {
|
|
398
|
+
if (state.indent === null) return null;
|
|
399
|
+
const quotePrefix = line.match(/^(?:[ \t]*>[ \t]?)+/)?.[0] || "";
|
|
400
|
+
if (quotePrefix !== state.quotePrefix) return null;
|
|
401
|
+
return indentationColumns(line.slice(quotePrefix.length)) >= state.indent ? state.indent : null;
|
|
402
|
+
}
|
|
403
|
+
function rewriteLinks(source, links) {
|
|
404
|
+
const output = [];
|
|
405
|
+
let outsideFence = "";
|
|
406
|
+
let fence = null;
|
|
407
|
+
let htmlEnd = null;
|
|
408
|
+
let htmlListIndent = null;
|
|
409
|
+
let htmlQuoteDepth = 0;
|
|
410
|
+
const listState = {
|
|
411
|
+
indent: null,
|
|
412
|
+
quotePrefix: ""
|
|
413
|
+
};
|
|
414
|
+
let paragraphOpen = false;
|
|
415
|
+
let paragraphListIndent = null;
|
|
416
|
+
let paragraphQuoteDepth = 0;
|
|
417
|
+
let previousLineWasOrdinaryParagraph = false;
|
|
418
|
+
const protectedLines = [];
|
|
419
|
+
const rewriteOutside = () => {
|
|
420
|
+
const codeSpans = protectCodeSpans(outsideFence);
|
|
421
|
+
return codeSpans.restore(rewriteReferenceDefinitions(rewriteInlineLinks(codeSpans.protectedSource, links), links)).replace(new RegExp(`${String.fromCodePoint(0)}INDENT(\\d+)${String.fromCodePoint(0)}`, "g"), (_match, index) => protectedLines[Number(index)]);
|
|
422
|
+
};
|
|
423
|
+
for (const lineWithEnding of source.match(/.*(?:\n|$)/g) || []) {
|
|
424
|
+
if (!lineWithEnding) continue;
|
|
425
|
+
const line = lineWithEnding.endsWith("\n") ? lineWithEnding.slice(0, -1) : lineWithEnding;
|
|
426
|
+
updateMarkdownListState(line, listState);
|
|
427
|
+
const listContinuationIndent = activeListIndent(line, listState);
|
|
428
|
+
const parsedFence = fenceRun(line);
|
|
429
|
+
if (htmlEnd) {
|
|
430
|
+
if (exitsMarkdownContainer(line, htmlListIndent, htmlQuoteDepth)) {
|
|
431
|
+
htmlEnd = null;
|
|
432
|
+
htmlListIndent = null;
|
|
433
|
+
htmlQuoteDepth = 0;
|
|
434
|
+
} else {
|
|
435
|
+
output.push(lineWithEnding);
|
|
436
|
+
if (htmlEnd.test(withoutMarkdownContainers(line, htmlListIndent))) {
|
|
437
|
+
htmlEnd = null;
|
|
438
|
+
htmlListIndent = null;
|
|
439
|
+
htmlQuoteDepth = 0;
|
|
440
|
+
}
|
|
441
|
+
continue;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
const htmlLine = withoutMarkdownContainers(line, listContinuationIndent);
|
|
445
|
+
const nextHtmlEnd = rawHtmlBlockEnd(htmlLine);
|
|
446
|
+
const typeSevenHtml = nextHtmlEnd ? isTypeSevenHtml(htmlLine, nextHtmlEnd) : false;
|
|
447
|
+
const quoteDepth = leadingQuoteDepth(referenceContainer(line));
|
|
448
|
+
const lazyTypeSevenContinuation = typeSevenHtml && paragraphOpen && quoteDepth <= paragraphQuoteDepth;
|
|
449
|
+
if (paragraphOpen && exitsMarkdownContainer(line, paragraphListIndent, paragraphQuoteDepth) && !lazyTypeSevenContinuation) {
|
|
450
|
+
paragraphOpen = false;
|
|
451
|
+
paragraphListIndent = null;
|
|
452
|
+
}
|
|
453
|
+
if (!fence && nextHtmlEnd && !lazyTypeSevenContinuation) {
|
|
454
|
+
output.push(rewriteOutside(), lineWithEnding);
|
|
455
|
+
outsideFence = "";
|
|
456
|
+
if (htmlBlockContinues(nextHtmlEnd, htmlLine)) {
|
|
457
|
+
const htmlContainer = markdownContainer(line);
|
|
458
|
+
htmlEnd = nextHtmlEnd;
|
|
459
|
+
htmlListIndent = htmlContainer.listIndent ?? listContinuationIndent;
|
|
460
|
+
htmlQuoteDepth = htmlContainer.quoteDepth;
|
|
461
|
+
}
|
|
462
|
+
paragraphOpen = false;
|
|
463
|
+
paragraphListIndent = null;
|
|
464
|
+
previousLineWasOrdinaryParagraph = false;
|
|
465
|
+
continue;
|
|
466
|
+
}
|
|
467
|
+
if (!fence && parsedFence) {
|
|
468
|
+
output.push(rewriteOutside(), lineWithEnding);
|
|
469
|
+
outsideFence = "";
|
|
470
|
+
paragraphOpen = false;
|
|
471
|
+
paragraphListIndent = null;
|
|
472
|
+
previousLineWasOrdinaryParagraph = false;
|
|
473
|
+
fence = {
|
|
474
|
+
length: parsedFence.run.length,
|
|
475
|
+
listIndent: parsedFence.listIndent,
|
|
476
|
+
marker: parsedFence.run[0],
|
|
477
|
+
quoteDepth: parsedFence.quoteDepth
|
|
478
|
+
};
|
|
479
|
+
continue;
|
|
480
|
+
}
|
|
481
|
+
if (fence) {
|
|
482
|
+
if (leadingQuoteDepth(line) < fence.quoteDepth || fence.listIndent !== null && line.trim() && indentationOutsideQuotes(line) < fence.listIndent) fence = null;
|
|
483
|
+
else {
|
|
484
|
+
output.push(lineWithEnding);
|
|
485
|
+
if (closesFence(line, fence)) fence = null;
|
|
486
|
+
continue;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
if (!line.trim()) {
|
|
490
|
+
outsideFence += lineWithEnding;
|
|
491
|
+
output.push(rewriteOutside());
|
|
492
|
+
outsideFence = "";
|
|
493
|
+
paragraphOpen = false;
|
|
494
|
+
paragraphListIndent = null;
|
|
495
|
+
previousLineWasOrdinaryParagraph = false;
|
|
496
|
+
continue;
|
|
497
|
+
}
|
|
498
|
+
const quotePrefix = line.match(/^(?:[ \t]*>[ \t]?)+/)?.[0] || "";
|
|
499
|
+
const contentIndent = indentationColumns(line.slice(quotePrefix.length));
|
|
500
|
+
const codeIndent = listState.indent !== null && quotePrefix === listState.quotePrefix ? listState.indent + 4 : 4;
|
|
501
|
+
if ((!paragraphOpen || quoteDepth !== paragraphQuoteDepth) && contentIndent >= codeIndent) {
|
|
502
|
+
const index = protectedLines.push(line) - 1;
|
|
503
|
+
outsideFence += `\0INDENT${index}\0${lineWithEnding.endsWith("\n") ? "\n" : ""}`;
|
|
504
|
+
previousLineWasOrdinaryParagraph = false;
|
|
505
|
+
continue;
|
|
506
|
+
}
|
|
507
|
+
if (paragraphOpen && previousLineWasOrdinaryParagraph && isCompleteReferenceDefinition(line)) {
|
|
508
|
+
const index = protectedLines.push(line) - 1;
|
|
509
|
+
outsideFence += `\0INDENT${index}\0${lineWithEnding.endsWith("\n") ? "\n" : ""}`;
|
|
510
|
+
paragraphOpen = false;
|
|
511
|
+
paragraphListIndent = null;
|
|
512
|
+
previousLineWasOrdinaryParagraph = false;
|
|
513
|
+
continue;
|
|
514
|
+
}
|
|
515
|
+
if (paragraphOpen && interruptsInlineBlock(line)) {
|
|
516
|
+
output.push(rewriteOutside());
|
|
517
|
+
outsideFence = "";
|
|
518
|
+
paragraphOpen = false;
|
|
519
|
+
paragraphListIndent = null;
|
|
520
|
+
}
|
|
521
|
+
outsideFence += lineWithEnding;
|
|
522
|
+
const nextParagraphOpen = startsParagraph(line, paragraphOpen);
|
|
523
|
+
if (nextParagraphOpen && (!paragraphOpen || quoteDepth !== paragraphQuoteDepth)) paragraphListIndent = markdownContainer(line).listIndent;
|
|
524
|
+
else if (!nextParagraphOpen) paragraphListIndent = null;
|
|
525
|
+
paragraphOpen = nextParagraphOpen;
|
|
526
|
+
paragraphQuoteDepth = quoteDepth;
|
|
527
|
+
previousLineWasOrdinaryParagraph = nextParagraphOpen && isOrdinaryParagraphLine(line);
|
|
528
|
+
}
|
|
529
|
+
output.push(rewriteOutside());
|
|
530
|
+
return output.join("");
|
|
531
|
+
}
|
|
532
|
+
function indentationColumns(line) {
|
|
533
|
+
let columns = 0;
|
|
534
|
+
for (const character of line) if (character === " ") columns += 1;
|
|
535
|
+
else if (character === " ") columns += 4 - columns % 4;
|
|
536
|
+
else break;
|
|
537
|
+
return columns;
|
|
538
|
+
}
|
|
539
|
+
function removeIndentation(line, columns) {
|
|
540
|
+
let index = 0;
|
|
541
|
+
let removed = 0;
|
|
542
|
+
while (index < line.length && removed < columns) {
|
|
543
|
+
const character = line[index];
|
|
544
|
+
const width = character === " " ? 1 : character === " " ? 4 - removed % 4 : 0;
|
|
545
|
+
if (width === 0 || removed + width > columns) break;
|
|
546
|
+
removed += width;
|
|
547
|
+
index += 1;
|
|
548
|
+
}
|
|
549
|
+
return line.slice(index);
|
|
550
|
+
}
|
|
551
|
+
function listIndentAtOffset(source, offset) {
|
|
552
|
+
const state = {
|
|
553
|
+
indent: null,
|
|
554
|
+
quotePrefix: ""
|
|
555
|
+
};
|
|
556
|
+
const prefix = source.slice(0, offset);
|
|
557
|
+
for (const line of prefix.split("\n")) updateMarkdownListState(line, state);
|
|
558
|
+
return activeListIndent(source.slice(offset).split("\n", 1)[0], state);
|
|
559
|
+
}
|
|
560
|
+
function cardList(source, links) {
|
|
561
|
+
return source.replace(/^([ \t]*)::u-page-grid[^\n]*\n([\s\S]*?)^\1::\s*$/gm, (grid, indent, cards, offset) => {
|
|
562
|
+
const codeIndent = (listIndentAtOffset(source, offset) ?? 0) + 4;
|
|
563
|
+
if (indentationColumns(indent) >= codeIndent) return grid;
|
|
564
|
+
const items = [];
|
|
565
|
+
for (const match of cards.matchAll(/^\s*:::u-page-card[^\n]*\n\s*---\n([\s\S]*?)\n\s*---\n\s*:::\s*$/gm)) {
|
|
566
|
+
const parsed = parse(match[1] || "");
|
|
567
|
+
const result = pageCardSchema.safeParse(parsed);
|
|
568
|
+
const fields = result.success ? result.data : {};
|
|
569
|
+
const title = fields.title?.trim() || null;
|
|
570
|
+
const to = fields.to?.trim() || null;
|
|
571
|
+
const description = fields.description?.trim() || null;
|
|
572
|
+
if (!title) continue;
|
|
573
|
+
const label = to ? `[${title}](${absoluteUrl(to, links)})` : title;
|
|
574
|
+
items.push(`${indent}- ${label}${description ? ` — ${description}` : ""}`);
|
|
575
|
+
}
|
|
576
|
+
return items.length > 0 ? `${items.join("\n")}\n` : "";
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
function cardListsOutsideFences(source, links) {
|
|
580
|
+
const output = [];
|
|
581
|
+
let outsideFence = "";
|
|
582
|
+
let fence = null;
|
|
583
|
+
let htmlEnd = null;
|
|
584
|
+
let htmlListIndent = null;
|
|
585
|
+
let htmlQuoteDepth = 0;
|
|
586
|
+
let paragraphOpen = false;
|
|
587
|
+
let paragraphQuoteDepth = 0;
|
|
588
|
+
const directives = [];
|
|
589
|
+
for (const lineWithEnding of source.match(/.*(?:\n|$)/g) || []) {
|
|
590
|
+
if (!lineWithEnding) continue;
|
|
591
|
+
const line = lineWithEnding.endsWith("\n") ? lineWithEnding.slice(0, -1) : lineWithEnding;
|
|
592
|
+
const structuralDepth = directives.filter(Boolean).length;
|
|
593
|
+
const deindented = removeIndentation(line, Math.min(indentationColumns(line), structuralDepth * 2));
|
|
594
|
+
const parsedFence = fenceRun(deindented);
|
|
595
|
+
if (htmlEnd) {
|
|
596
|
+
if (exitsMarkdownContainer(line, htmlListIndent, htmlQuoteDepth)) {
|
|
597
|
+
htmlEnd = null;
|
|
598
|
+
htmlListIndent = null;
|
|
599
|
+
htmlQuoteDepth = 0;
|
|
600
|
+
} else {
|
|
601
|
+
output.push(lineWithEnding);
|
|
602
|
+
if (htmlEnd.test(withoutMarkdownContainers(line))) {
|
|
603
|
+
htmlEnd = null;
|
|
604
|
+
htmlListIndent = null;
|
|
605
|
+
htmlQuoteDepth = 0;
|
|
606
|
+
}
|
|
607
|
+
continue;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
const htmlLine = withoutMarkdownContainers(line);
|
|
611
|
+
const nextHtmlEnd = rawHtmlBlockEnd(htmlLine);
|
|
612
|
+
const quoteDepth = leadingQuoteDepth(referenceContainer(line));
|
|
613
|
+
const typeSevenHtml = nextHtmlEnd ? isTypeSevenHtml(htmlLine, nextHtmlEnd) : false;
|
|
614
|
+
if (!fence && nextHtmlEnd && !(typeSevenHtml && paragraphOpen && quoteDepth <= paragraphQuoteDepth)) {
|
|
615
|
+
output.push(cardList(outsideFence, links), lineWithEnding);
|
|
616
|
+
outsideFence = "";
|
|
617
|
+
if (htmlBlockContinues(nextHtmlEnd, htmlLine)) {
|
|
618
|
+
const htmlContainer = markdownContainer(line);
|
|
619
|
+
htmlEnd = nextHtmlEnd;
|
|
620
|
+
htmlListIndent = htmlContainer.listIndent;
|
|
621
|
+
htmlQuoteDepth = htmlContainer.quoteDepth;
|
|
622
|
+
}
|
|
623
|
+
paragraphOpen = false;
|
|
624
|
+
continue;
|
|
625
|
+
}
|
|
626
|
+
if (!fence && parsedFence) {
|
|
627
|
+
output.push(cardList(outsideFence, links), lineWithEnding);
|
|
628
|
+
outsideFence = "";
|
|
629
|
+
fence = {
|
|
630
|
+
length: parsedFence.run.length,
|
|
631
|
+
listIndent: parsedFence.listIndent,
|
|
632
|
+
marker: parsedFence.run[0],
|
|
633
|
+
quoteDepth: parsedFence.quoteDepth
|
|
634
|
+
};
|
|
635
|
+
paragraphOpen = false;
|
|
636
|
+
continue;
|
|
637
|
+
}
|
|
638
|
+
if (fence) {
|
|
639
|
+
if (leadingQuoteDepth(deindented) < fence.quoteDepth || fence.listIndent !== null && deindented.trim() && indentationOutsideQuotes(deindented) < fence.listIndent) fence = null;
|
|
640
|
+
else {
|
|
641
|
+
output.push(lineWithEnding);
|
|
642
|
+
if (closesFence(deindented, fence)) fence = null;
|
|
643
|
+
continue;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
outsideFence += lineWithEnding;
|
|
647
|
+
if (!line.trim()) {
|
|
648
|
+
paragraphOpen = false;
|
|
649
|
+
continue;
|
|
650
|
+
}
|
|
651
|
+
paragraphOpen = startsParagraph(line, paragraphOpen);
|
|
652
|
+
paragraphQuoteDepth = quoteDepth;
|
|
653
|
+
if (/^\s*:{2,}\s*$/.test(deindented)) {
|
|
654
|
+
directives.pop();
|
|
655
|
+
continue;
|
|
656
|
+
}
|
|
657
|
+
const directive = deindented.match(/^\s*:{2,}([a-z][a-z0-9-]*)(?:\{[^}]*\})?\s*$/i);
|
|
658
|
+
if (directive) directives.push(presentationDirectives.has((directive[1] || "").toLowerCase()));
|
|
659
|
+
}
|
|
660
|
+
output.push(cardList(outsideFence, links));
|
|
661
|
+
return output.join("");
|
|
662
|
+
}
|
|
663
|
+
const presentationDirectives = /* @__PURE__ */ new Set([
|
|
664
|
+
"docs-learning-paths",
|
|
665
|
+
"agent-only",
|
|
666
|
+
"support-matrix",
|
|
667
|
+
"collapsible",
|
|
668
|
+
"code-tree",
|
|
669
|
+
"component-preview",
|
|
670
|
+
"correct",
|
|
671
|
+
"example",
|
|
672
|
+
"examples",
|
|
673
|
+
"incorrect",
|
|
674
|
+
"mcp-client",
|
|
675
|
+
"mcp-install",
|
|
676
|
+
"page-list",
|
|
677
|
+
"important",
|
|
678
|
+
"note",
|
|
679
|
+
"product-hero",
|
|
680
|
+
"product-files",
|
|
681
|
+
"product-screenshot",
|
|
682
|
+
"cms-console-demo",
|
|
683
|
+
"product-features",
|
|
684
|
+
"product-feature-item",
|
|
685
|
+
"steps",
|
|
686
|
+
"tabs",
|
|
687
|
+
"tabs-item",
|
|
688
|
+
"tip",
|
|
689
|
+
"u-page-card",
|
|
690
|
+
"u-page-grid",
|
|
691
|
+
"warning"
|
|
692
|
+
]);
|
|
693
|
+
function directiveLabel(name, attributes) {
|
|
694
|
+
if (name === "product-feature-item") {
|
|
695
|
+
const title = attributes?.match(/\btitle=(?:"([^"]+)"|'([^']+)')/)?.slice(1).find(Boolean);
|
|
696
|
+
const to = attributes?.match(/\bto=(?:"([^"]+)"|'([^']+)')/)?.slice(1).find(Boolean);
|
|
697
|
+
return title ? `### ${to ? `[${title}](${to})` : title}` : "";
|
|
698
|
+
}
|
|
699
|
+
if (name === "product-hero") {
|
|
700
|
+
const tagline = attributes?.match(/\btagline=(?:"([^"]+)"|'([^']+)')/)?.slice(1).find(Boolean);
|
|
701
|
+
const hosts = attributes?.match(/\bhosts=(?:"([^"]+)"|'([^']+)')/)?.slice(1).find(Boolean);
|
|
702
|
+
const channels = attributes?.match(/\bchannels=(?:"([^"]+)"|'([^']+)')/)?.slice(1).find(Boolean);
|
|
703
|
+
const customChannels = /\bchannel(?:-mode|Mode)=(?:"custom"|'custom')/.test(attributes || "");
|
|
704
|
+
return [
|
|
705
|
+
tagline,
|
|
706
|
+
hosts ? `Hosts: ${hosts}.` : "",
|
|
707
|
+
channels ? `${customChannels ? "Example connectors" : "Built-in channels"}: ${channels}.` : "",
|
|
708
|
+
channels && customChannels ? "You write each connector. Use Agent Channels for built-in chat integrations." : ""
|
|
709
|
+
].filter(Boolean).join("\n\n");
|
|
710
|
+
}
|
|
711
|
+
if (name === "product-screenshot") {
|
|
712
|
+
const src = attributes?.match(/\bsrc=(?:"([^"]+)"|'([^']+)')/)?.slice(1).find(Boolean);
|
|
713
|
+
const alt = attributes?.match(/\balt=(?:"([^"]+)"|'([^']+)')/)?.slice(1).find(Boolean);
|
|
714
|
+
return src ? `` : "";
|
|
715
|
+
}
|
|
716
|
+
if ([
|
|
717
|
+
"note",
|
|
718
|
+
"tip",
|
|
719
|
+
"warning",
|
|
720
|
+
"important"
|
|
721
|
+
].includes(name)) return `> **${name[0].toUpperCase()}${name.slice(1)}**`;
|
|
722
|
+
if (name === "mcp-client") {
|
|
723
|
+
const label = attributes?.match(/\blabel=(?:"([^"]+)"|'([^']+)')/)?.slice(1).find(Boolean);
|
|
724
|
+
return label ? `### ${label}` : "";
|
|
725
|
+
}
|
|
726
|
+
if (name === "tabs-item") {
|
|
727
|
+
const label = attributes?.match(/\blabel=(?:"([^"]+)"|'([^']+)')/)?.slice(1).find(Boolean);
|
|
728
|
+
return label ? `### ${label}` : "";
|
|
729
|
+
}
|
|
730
|
+
if (name === "component-preview") return "_Interactive preview available on the rendered documentation page._";
|
|
731
|
+
if (name === "correct" || name === "incorrect") return `**${attributes?.match(/\btitle=(?:"([^"]+)"|'([^']+)')/)?.slice(1).find(Boolean) ?? (name === "correct" ? "Correct" : "Incorrect")}**`;
|
|
732
|
+
if (name === "example") {
|
|
733
|
+
const label = attributes?.match(/\blabel=(?:"([^"]+)"|'([^']+)')/)?.slice(1).find(Boolean);
|
|
734
|
+
if (/\bname=/.test(attributes || "")) return "_Interactive preview available on the rendered documentation page._";
|
|
735
|
+
return label ? `**${label}**` : "";
|
|
736
|
+
}
|
|
737
|
+
return "";
|
|
738
|
+
}
|
|
739
|
+
function stripPresentationDirectives(source, includeAgentOnly, links) {
|
|
740
|
+
const output = [];
|
|
741
|
+
const directives = [];
|
|
742
|
+
const omitted = [];
|
|
743
|
+
const emit = (...lines) => {
|
|
744
|
+
if (!omitted.includes(true)) output.push(...lines);
|
|
745
|
+
};
|
|
746
|
+
let fence = null;
|
|
747
|
+
let htmlEnd = null;
|
|
748
|
+
let htmlListIndent = null;
|
|
749
|
+
let htmlQuoteDepth = 0;
|
|
750
|
+
let paragraphOpen = false;
|
|
751
|
+
let paragraphQuoteDepth = 0;
|
|
752
|
+
const listState = {
|
|
753
|
+
indent: null,
|
|
754
|
+
quotePrefix: ""
|
|
755
|
+
};
|
|
756
|
+
for (const originalLine of source.split("\n")) {
|
|
757
|
+
updateMarkdownListState(originalLine, listState);
|
|
758
|
+
const listIndent = activeListIndent(originalLine, listState) ?? 0;
|
|
759
|
+
const leadingColumns = indentationColumns(originalLine);
|
|
760
|
+
const structuralDepth = directives.filter(Boolean).length;
|
|
761
|
+
const structuralIndent = fence?.indent ?? Math.min(Math.max(leadingColumns - listIndent, 0), structuralDepth * 2);
|
|
762
|
+
const deindented = removeIndentation(originalLine, structuralIndent);
|
|
763
|
+
if (htmlEnd) {
|
|
764
|
+
if (exitsMarkdownContainer(deindented, htmlListIndent, htmlQuoteDepth)) {
|
|
765
|
+
htmlEnd = null;
|
|
766
|
+
htmlListIndent = null;
|
|
767
|
+
htmlQuoteDepth = 0;
|
|
768
|
+
} else {
|
|
769
|
+
emit(deindented);
|
|
770
|
+
if (htmlEnd.test(withoutMarkdownContainers(deindented))) {
|
|
771
|
+
htmlEnd = null;
|
|
772
|
+
htmlListIndent = null;
|
|
773
|
+
htmlQuoteDepth = 0;
|
|
774
|
+
}
|
|
775
|
+
continue;
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
if (fence && (leadingQuoteDepth(deindented) < fence.quoteDepth || fence.listIndent !== null && deindented.trim() && indentationOutsideQuotes(deindented) < fence.listIndent)) fence = null;
|
|
779
|
+
if (!fence && leadingColumns - listIndent >= structuralDepth * 2 + 4) {
|
|
780
|
+
emit(deindented);
|
|
781
|
+
continue;
|
|
782
|
+
}
|
|
783
|
+
const parsedFence = fenceRun(deindented);
|
|
784
|
+
if (parsedFence) {
|
|
785
|
+
if (!fence) fence = {
|
|
786
|
+
indent: structuralIndent,
|
|
787
|
+
length: parsedFence.run.length,
|
|
788
|
+
listIndent: parsedFence.listIndent,
|
|
789
|
+
marker: parsedFence.run[0],
|
|
790
|
+
quoteDepth: parsedFence.quoteDepth
|
|
791
|
+
};
|
|
792
|
+
else if (closesFence(deindented, fence)) fence = null;
|
|
793
|
+
emit(deindented);
|
|
794
|
+
continue;
|
|
795
|
+
}
|
|
796
|
+
if (fence) {
|
|
797
|
+
emit(deindented);
|
|
798
|
+
continue;
|
|
799
|
+
}
|
|
800
|
+
const htmlLine = withoutMarkdownContainers(deindented, listIndent || null);
|
|
801
|
+
const nextHtmlEnd = rawHtmlBlockEnd(htmlLine);
|
|
802
|
+
const quoteDepth = leadingQuoteDepth(referenceContainer(deindented));
|
|
803
|
+
const typeSevenHtml = nextHtmlEnd ? isTypeSevenHtml(htmlLine, nextHtmlEnd) : false;
|
|
804
|
+
if (nextHtmlEnd && !(typeSevenHtml && paragraphOpen && quoteDepth <= paragraphQuoteDepth)) {
|
|
805
|
+
emit(deindented);
|
|
806
|
+
if (htmlBlockContinues(nextHtmlEnd, htmlLine)) {
|
|
807
|
+
const htmlContainer = markdownContainer(deindented);
|
|
808
|
+
htmlEnd = nextHtmlEnd;
|
|
809
|
+
htmlListIndent = htmlContainer.listIndent ?? (listIndent || null);
|
|
810
|
+
htmlQuoteDepth = htmlContainer.quoteDepth;
|
|
811
|
+
}
|
|
812
|
+
paragraphOpen = false;
|
|
813
|
+
continue;
|
|
814
|
+
}
|
|
815
|
+
if (!deindented.trim()) paragraphOpen = false;
|
|
816
|
+
else {
|
|
817
|
+
paragraphOpen = startsParagraph(deindented, paragraphOpen);
|
|
818
|
+
paragraphQuoteDepth = quoteDepth;
|
|
819
|
+
}
|
|
820
|
+
if (/^\s*:{2,}\s*$/.test(deindented)) {
|
|
821
|
+
const stripped = directives.pop();
|
|
822
|
+
if (stripped === false || stripped === void 0) emit(deindented);
|
|
823
|
+
omitted.pop();
|
|
824
|
+
continue;
|
|
825
|
+
}
|
|
826
|
+
const directive = deindented.match(/^\s*:{2,}([a-z][a-z0-9-]*)(?:\{([^}]*)\})?\s*$/i);
|
|
827
|
+
if (directive) {
|
|
828
|
+
const name = (directive[1] || "").toLowerCase();
|
|
829
|
+
const stripped = presentationDirectives.has(name);
|
|
830
|
+
directives.push(stripped);
|
|
831
|
+
omitted.push(name === "agent-only" && !includeAgentOnly);
|
|
832
|
+
if (!stripped) {
|
|
833
|
+
emit(deindented);
|
|
834
|
+
continue;
|
|
835
|
+
}
|
|
836
|
+
const label = directiveLabel(name, directive[2]);
|
|
837
|
+
if (label) emit(`${deindented.match(/^\s*/)?.[0] || ""}${label}`, "");
|
|
838
|
+
continue;
|
|
839
|
+
}
|
|
840
|
+
emit(deindented);
|
|
841
|
+
}
|
|
842
|
+
return rewriteLinks(output.join("\n"), links);
|
|
843
|
+
}
|
|
844
|
+
/** The page as an agent reads it: plain Markdown, links absolute, presentation blocks unwrapped, and a `# title`. */
|
|
845
|
+
function toRawMarkdown(source, options = {}) {
|
|
846
|
+
const { body, frontmatter } = splitFrontmatter(source);
|
|
847
|
+
const title = typeof frontmatter.title === "string" ? frontmatter.title.trim() : void 0;
|
|
848
|
+
const links = {
|
|
849
|
+
siteUrl: options.siteUrl?.replace(/\/+$/, "") ?? "",
|
|
850
|
+
pagePath: options.pagePath
|
|
851
|
+
};
|
|
852
|
+
const content = stripPresentationDirectives(cardListsOutsideFences(body, links), options.includeAgentOnly ?? true, links).replace(/^\n+|\n+$/g, "");
|
|
853
|
+
const startsWithH1 = /^[ \t]{0,3}#(?:[ \t]+|$)/.test(content) || /^[^\n]+\n[ \t]{0,3}=+[ \t]*(?:\n|$)/.test(content);
|
|
854
|
+
return `${title && !startsWithH1 ? `# ${title}\n\n${content}` : content}\n`;
|
|
855
|
+
}
|
|
856
|
+
//#endregion
|
|
857
|
+
export { toRawMarkdown as t };
|