@forsakringskassan/docs-generator 1.26.0 → 1.28.0
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/compile-example.js +47 -13313
- package/dist/create-markdown-renderer-CPrI2LLQ.js +640 -0
- package/dist/{generator.d.ts → index.d.ts} +45 -4
- package/dist/index.js +2283 -0
- package/dist/markdown.js +43 -19389
- package/dist/style/core.css +3 -6
- package/dist/style/index.css +30 -8
- package/dist/style/site.css +27 -2
- package/dist/vendor-uab7h6x-.js +56161 -0
- package/dist/vue2-CBDrnmVO.js +478 -0
- package/dist/vue3-xJIC7Aol.js +12908 -0
- package/package.json +10 -4
- package/templates/partials/version.njk.html +15 -0
- package/dist/generator.js +0 -86510
- package/templates/partials/version.html +0 -3
|
@@ -0,0 +1,640 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var vendor = require('./vendor-uab7h6x-.js');
|
|
4
|
+
var path = require('node:path/posix');
|
|
5
|
+
require('node:path');
|
|
6
|
+
require('crypto');
|
|
7
|
+
var crypto = require('node:crypto');
|
|
8
|
+
|
|
9
|
+
function findDocument(haystack, needle) {
|
|
10
|
+
const match = haystack.find((it) => {
|
|
11
|
+
if (it.id === needle) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
if (it.name === needle) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
if (it.alias.includes(needle)) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
21
|
+
});
|
|
22
|
+
return match ?? null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const replacements = {
|
|
26
|
+
\u00E5: "a",
|
|
27
|
+
\u00E4: "a",
|
|
28
|
+
\u00F6: "o"
|
|
29
|
+
};
|
|
30
|
+
function findVersion(text) {
|
|
31
|
+
const match = text.match(/(\d+)\.(\d+)\.(\d+) \(\d+-\d+-\d+\)/);
|
|
32
|
+
if (match) {
|
|
33
|
+
return [
|
|
34
|
+
parseInt(match[1], 10),
|
|
35
|
+
parseInt(match[2], 10),
|
|
36
|
+
parseInt(match[3], 10)
|
|
37
|
+
];
|
|
38
|
+
} else {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function generateId(text) {
|
|
43
|
+
const version = findVersion(text);
|
|
44
|
+
if (version) {
|
|
45
|
+
return `v${version.join("-")}`;
|
|
46
|
+
}
|
|
47
|
+
return text.toLowerCase().trim().replace(/[åäö]/g, (m) => replacements[m]).replace(/[^a-z0-9]+/g, "_").replace(/^_+/, "").replace(/_+$/, "");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function getFingerprint(source) {
|
|
51
|
+
return crypto.createHash("md5").update(source).digest("hex").slice(0, 6);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function normalizePath(...pathSegments) {
|
|
55
|
+
const filePath = path.join(...pathSegments);
|
|
56
|
+
return path.normalize(filePath).replace(/\\/g, "/");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function getOutputFilePath(outputFolder, fileInfo) {
|
|
60
|
+
const { path, outputName } = fileInfo;
|
|
61
|
+
if (outputName === false) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
return normalizePath(outputFolder, path, outputName);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
class SoftError extends Error {
|
|
68
|
+
code;
|
|
69
|
+
details;
|
|
70
|
+
/**
|
|
71
|
+
* @internal
|
|
72
|
+
*/
|
|
73
|
+
constructor(code, message, ...args) {
|
|
74
|
+
super(message);
|
|
75
|
+
this.name = this.constructor.name;
|
|
76
|
+
this.code = code;
|
|
77
|
+
const [details] = args;
|
|
78
|
+
this.details = details;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function processInlineTags(tags, doc, docs, text, handleSoftError) {
|
|
83
|
+
return text.replace(/{@([\S}]+)([^}]*)}/g, (_, name, content) => {
|
|
84
|
+
const tag = tags.find((it) => it.name === name);
|
|
85
|
+
if (!tag) {
|
|
86
|
+
return handleSoftError(
|
|
87
|
+
new SoftError(
|
|
88
|
+
"ETAGMISSING",
|
|
89
|
+
`No inline tag registered with the name "${name}"`
|
|
90
|
+
)
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
return tag.handler(doc, docs, content.trim());
|
|
95
|
+
} catch (err) {
|
|
96
|
+
if (err instanceof SoftError) {
|
|
97
|
+
return handleSoftError(err);
|
|
98
|
+
} else {
|
|
99
|
+
throw err;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function getRelativeUrl(from, to) {
|
|
106
|
+
const fromResolved = getOutputFilePath(".", from.fileInfo);
|
|
107
|
+
const toResolved = getOutputFilePath(".", to.fileInfo);
|
|
108
|
+
if (!fromResolved || !toResolved) {
|
|
109
|
+
throw new Error("Cannot create link to document with no output");
|
|
110
|
+
}
|
|
111
|
+
const fromDir = path.dirname(fromResolved);
|
|
112
|
+
const toDir = path.dirname(toResolved);
|
|
113
|
+
const relative = path.relative(fromDir, toResolved);
|
|
114
|
+
if (fromDir === toDir) {
|
|
115
|
+
return relative === "index.html" ? "./" : `./${relative}`;
|
|
116
|
+
} else if (relative.endsWith("/index.html")) {
|
|
117
|
+
return path.dirname(relative);
|
|
118
|
+
} else {
|
|
119
|
+
return relative;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function getLinkTitle(doc, key, explicitTitle) {
|
|
123
|
+
if (explicitTitle) {
|
|
124
|
+
return explicitTitle;
|
|
125
|
+
}
|
|
126
|
+
const { title, component } = doc.attributes;
|
|
127
|
+
if (component && component.includes(key)) {
|
|
128
|
+
return `<code>${key}</code>`;
|
|
129
|
+
} else {
|
|
130
|
+
return title ?? doc.name;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const linkTag = {
|
|
134
|
+
name: "link",
|
|
135
|
+
description: "Create a link to another document",
|
|
136
|
+
handler(doc, docs, content) {
|
|
137
|
+
const match = content.match(/^([^\s#]+)(#\S+)?\s*(.+)?$/);
|
|
138
|
+
if (!match) {
|
|
139
|
+
throw new SoftError(
|
|
140
|
+
"ELINKFORMAT",
|
|
141
|
+
`Failed to parse link "${content}"`
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
const [, key, hash, explicitTitle] = match;
|
|
145
|
+
if (key.startsWith("http://") || key.startsWith("https://")) {
|
|
146
|
+
return `<a href="${key}${hash ?? ""}">${explicitTitle ?? key}</a>`;
|
|
147
|
+
}
|
|
148
|
+
const linked = findDocument(docs, key);
|
|
149
|
+
if (!linked) {
|
|
150
|
+
throw new SoftError(
|
|
151
|
+
"ELINKTARGET",
|
|
152
|
+
`Failed to find linked document "${key}"`,
|
|
153
|
+
{
|
|
154
|
+
key,
|
|
155
|
+
hash,
|
|
156
|
+
title: explicitTitle
|
|
157
|
+
}
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
const url = getRelativeUrl(doc, linked);
|
|
161
|
+
const title = getLinkTitle(linked, key, explicitTitle);
|
|
162
|
+
return `<a href="${url}${hash ?? ""}">${title}</a>`;
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const inlineTags = [linkTag];
|
|
167
|
+
|
|
168
|
+
function findTestId(tags) {
|
|
169
|
+
const prefix = "test-id=";
|
|
170
|
+
const tag = tags.find((it) => {
|
|
171
|
+
return it.startsWith(prefix);
|
|
172
|
+
});
|
|
173
|
+
const match = tag == null ? void 0 : tag.match(/^test-id=(?:"([^"]+)"|'([^']+)'|([^'"]+))$/);
|
|
174
|
+
if (!match) {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
return match.slice(1).find(Boolean) ?? null;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const HTML_ESCAPE_REPLACE_RE = /[&<>"]/g;
|
|
181
|
+
const HTML_REPLACEMENTS = {
|
|
182
|
+
"&": "&",
|
|
183
|
+
"<": "<",
|
|
184
|
+
">": ">",
|
|
185
|
+
'"': """
|
|
186
|
+
};
|
|
187
|
+
function escapeHtml(str) {
|
|
188
|
+
return str.replace(HTML_ESCAPE_REPLACE_RE, (ch) => HTML_REPLACEMENTS[ch]);
|
|
189
|
+
}
|
|
190
|
+
function wrap(content, language) {
|
|
191
|
+
const markup = (
|
|
192
|
+
/* HTML */
|
|
193
|
+
`
|
|
194
|
+
<code class="hljs lang-${language}" tabindex="0">${content}</code>
|
|
195
|
+
`
|
|
196
|
+
);
|
|
197
|
+
return markup.trim();
|
|
198
|
+
}
|
|
199
|
+
function highlight({
|
|
200
|
+
source,
|
|
201
|
+
language
|
|
202
|
+
}) {
|
|
203
|
+
switch (language) {
|
|
204
|
+
case "":
|
|
205
|
+
case "import":
|
|
206
|
+
case "mermaid":
|
|
207
|
+
case "plaintext":
|
|
208
|
+
return `<code>${escapeHtml(source)}</code>`;
|
|
209
|
+
case "vue":
|
|
210
|
+
return highlight({ source, language: "html" });
|
|
211
|
+
}
|
|
212
|
+
try {
|
|
213
|
+
const { value } = vendor.HighlightJS.highlight(source, { language });
|
|
214
|
+
return wrap(value, language);
|
|
215
|
+
} catch (err) {
|
|
216
|
+
return wrap(String(err), language);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const replacement = {
|
|
221
|
+
"<": `<`,
|
|
222
|
+
">": `>`,
|
|
223
|
+
"&": `&`,
|
|
224
|
+
'"': `"`,
|
|
225
|
+
"'": `'`
|
|
226
|
+
};
|
|
227
|
+
function htmlencode(text) {
|
|
228
|
+
return text.replace(/[<>&"']/g, (m) => {
|
|
229
|
+
return replacement[m];
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function replaceAtLink(text) {
|
|
234
|
+
return text.replace(
|
|
235
|
+
/{@link [^}]+[$}]/g,
|
|
236
|
+
(match) => match.replace("{", "{").replace("}", "}")
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function getClassModifier(tags) {
|
|
241
|
+
if (tags.includes("borderless")) {
|
|
242
|
+
return "code-preview--borderless";
|
|
243
|
+
}
|
|
244
|
+
return "code-preview--default";
|
|
245
|
+
}
|
|
246
|
+
function codePreview(options) {
|
|
247
|
+
const { generateExample } = options;
|
|
248
|
+
return (md) => {
|
|
249
|
+
md.renderer.rules.fence = fence.bind(void 0, md);
|
|
250
|
+
};
|
|
251
|
+
function fence(_md, tokens, idx, _options, env) {
|
|
252
|
+
const { fileInfo } = env;
|
|
253
|
+
const { content: source, info, map } = tokens[idx];
|
|
254
|
+
const [language, ...rawTags] = info.split(/\s+/);
|
|
255
|
+
if (language === "mermaid") {
|
|
256
|
+
return (
|
|
257
|
+
/* HTML */
|
|
258
|
+
`
|
|
259
|
+
<pre class="mermaid">${htmlencode(source)}</pre>
|
|
260
|
+
`
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
const example = generateExample({
|
|
264
|
+
source,
|
|
265
|
+
language,
|
|
266
|
+
filename: fileInfo.fullPath,
|
|
267
|
+
tags: rawTags
|
|
268
|
+
});
|
|
269
|
+
const { tags } = example;
|
|
270
|
+
const hashContent = `${map == null ? void 0 : map[0]}:${map == null ? void 0 : map[1]}:${info}:${source}`;
|
|
271
|
+
const fingerprint = getFingerprint(hashContent);
|
|
272
|
+
const highlightedCode = replaceAtLink(highlight(example));
|
|
273
|
+
const testId = findTestId(tags);
|
|
274
|
+
const liveExample = tags.includes("live-example");
|
|
275
|
+
const staticCode = example.runtime === false || tags.includes("static");
|
|
276
|
+
const noMarkup = tags.includes("nomarkup");
|
|
277
|
+
const fullscreen = tags.includes("fullscreen");
|
|
278
|
+
const modifier = getClassModifier(tags);
|
|
279
|
+
const standalone = Boolean(example.output) && fullscreen;
|
|
280
|
+
const testIdAttr = testId ? `data-test="${testId}"` : "";
|
|
281
|
+
const filteredTags = tags.filter((it) => {
|
|
282
|
+
if (it.startsWith("test-id=")) {
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
return true;
|
|
286
|
+
});
|
|
287
|
+
const dataTagsAttr = filteredTags.length > 0 ? `data-tags=${filteredTags.join(" ")}` : "";
|
|
288
|
+
if (liveExample) {
|
|
289
|
+
return (
|
|
290
|
+
/* HTML */
|
|
291
|
+
`
|
|
292
|
+
<div
|
|
293
|
+
id="example-${fingerprint}"
|
|
294
|
+
class="code-preview code-preview--borderless"
|
|
295
|
+
${testIdAttr}
|
|
296
|
+
${dataTagsAttr}
|
|
297
|
+
data-language="${example.language}"
|
|
298
|
+
>
|
|
299
|
+
${example.markup}
|
|
300
|
+
</div>
|
|
301
|
+
`
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
if (staticCode) {
|
|
305
|
+
return (
|
|
306
|
+
/* HTML */
|
|
307
|
+
`
|
|
308
|
+
<div
|
|
309
|
+
id="example-${fingerprint}"
|
|
310
|
+
class="code-preview ${modifier}"
|
|
311
|
+
${testIdAttr}
|
|
312
|
+
${dataTagsAttr}
|
|
313
|
+
data-language="${example.language}"
|
|
314
|
+
>
|
|
315
|
+
${example.comments.join("\n")}
|
|
316
|
+
<pre class="code-preview__markup">${highlightedCode}</pre>
|
|
317
|
+
</div>
|
|
318
|
+
`
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
if (noMarkup) {
|
|
322
|
+
return (
|
|
323
|
+
/* HTML */
|
|
324
|
+
`
|
|
325
|
+
<div
|
|
326
|
+
id="example-${fingerprint}"
|
|
327
|
+
class="code-preview ${modifier}"
|
|
328
|
+
${testIdAttr}
|
|
329
|
+
${dataTagsAttr}
|
|
330
|
+
data-language="${example.language}"
|
|
331
|
+
>
|
|
332
|
+
${example.comments.join("\n")}
|
|
333
|
+
<div class="code-preview__preview">${example.markup}</div>
|
|
334
|
+
</div>
|
|
335
|
+
`
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
const toggleMarkup = (
|
|
339
|
+
/* HTML */
|
|
340
|
+
`
|
|
341
|
+
<button
|
|
342
|
+
type="button"
|
|
343
|
+
class="button button--discrete code-preview__toggle-markup"
|
|
344
|
+
aria-expanded="false"
|
|
345
|
+
onclick="toggleMarkup(this)"
|
|
346
|
+
>
|
|
347
|
+
<i class="icon icon--code"></i>
|
|
348
|
+
Visa kod
|
|
349
|
+
</button>
|
|
350
|
+
`
|
|
351
|
+
);
|
|
352
|
+
const toggleFullscreen = fullscreen ? (
|
|
353
|
+
/* HTML */
|
|
354
|
+
`
|
|
355
|
+
<a href="${standalone}" class="code-preview__fullscreen">
|
|
356
|
+
<i class="icon icon--fullscreen"></i>
|
|
357
|
+
Helsk\xE4rm
|
|
358
|
+
</a>
|
|
359
|
+
`
|
|
360
|
+
) : "";
|
|
361
|
+
return (
|
|
362
|
+
/* HTML */
|
|
363
|
+
`
|
|
364
|
+
<div
|
|
365
|
+
id="example-${fingerprint}"
|
|
366
|
+
class="code-preview ${modifier}"
|
|
367
|
+
${testIdAttr}
|
|
368
|
+
${dataTagsAttr}
|
|
369
|
+
data-language="${example.language}"
|
|
370
|
+
>
|
|
371
|
+
${example.comments.join("\n")}
|
|
372
|
+
<div class="code-preview__preview">${example.markup}</div>
|
|
373
|
+
<div>${toggleMarkup} ${toggleFullscreen}</div>
|
|
374
|
+
<div
|
|
375
|
+
class="code-preview__expand animate-expand"
|
|
376
|
+
style="height: 0px;"
|
|
377
|
+
hidden
|
|
378
|
+
>
|
|
379
|
+
<pre class="code-preview__markup">${highlightedCode}</pre>
|
|
380
|
+
</div>
|
|
381
|
+
</div>
|
|
382
|
+
`
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
function getTokensText(tokens) {
|
|
388
|
+
return tokens.filter((token) => ["text", "code_inline"].includes(token.type)).map((token) => token.content).join("");
|
|
389
|
+
}
|
|
390
|
+
function headingLevel(options) {
|
|
391
|
+
const { initialLevel } = options;
|
|
392
|
+
const offset = initialLevel - 1;
|
|
393
|
+
let counter = 1;
|
|
394
|
+
return function(md) {
|
|
395
|
+
md.renderer.rules.heading_open = function(tokens, idx, _options, env) {
|
|
396
|
+
var _a;
|
|
397
|
+
const { ids } = env;
|
|
398
|
+
const { tag } = tokens[idx];
|
|
399
|
+
const title = getTokensText(((_a = tokens[idx + 1]) == null ? void 0 : _a.children) ?? []);
|
|
400
|
+
let id = generateId(title);
|
|
401
|
+
if (ids.has(id)) {
|
|
402
|
+
id += `--${counter++}`;
|
|
403
|
+
}
|
|
404
|
+
ids.add(id);
|
|
405
|
+
return tag.replace(/h(\d)/, (_, n) => {
|
|
406
|
+
const level = parseInt(n, 10) + offset;
|
|
407
|
+
return `<h${level} id="${id}"><a class="header-anchor" href="#${id}">`;
|
|
408
|
+
});
|
|
409
|
+
};
|
|
410
|
+
md.renderer.rules.heading_close = function(tokens, idx) {
|
|
411
|
+
const { tag } = tokens[idx];
|
|
412
|
+
return tag.replace(/h(\d)/, (_, n) => {
|
|
413
|
+
const level = parseInt(n, 10) + offset;
|
|
414
|
+
return `</a></h${level}>`;
|
|
415
|
+
});
|
|
416
|
+
};
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
function computeHash(source) {
|
|
421
|
+
return crypto.createHash("md5").update(source).digest("hex");
|
|
422
|
+
}
|
|
423
|
+
function getFilename(fileInfo, src) {
|
|
424
|
+
const key = [fileInfo.fullPath, src].join("-");
|
|
425
|
+
const hash = computeHash(key);
|
|
426
|
+
const { ext } = path.parse(src);
|
|
427
|
+
return `images/${hash}${ext}`;
|
|
428
|
+
}
|
|
429
|
+
function imageResources(options) {
|
|
430
|
+
const { addResource } = options;
|
|
431
|
+
function imageResource(tokens, index, options2, env, self) {
|
|
432
|
+
const { fileInfo } = env;
|
|
433
|
+
const token = tokens[index];
|
|
434
|
+
token.attrs ??= [];
|
|
435
|
+
const srcAttr = token.attrGet("src");
|
|
436
|
+
if (srcAttr) {
|
|
437
|
+
const dst = getFilename(fileInfo, srcAttr);
|
|
438
|
+
const src = path.join(path.dirname(fileInfo.fullPath), srcAttr);
|
|
439
|
+
const url = path.relative(fileInfo.path, path.join("assets", dst));
|
|
440
|
+
addResource(dst, src);
|
|
441
|
+
token.attrs[token.attrIndex("src")][1] = url;
|
|
442
|
+
}
|
|
443
|
+
token.attrs[token.attrIndex("alt")][1] = self.renderInlineAsText(
|
|
444
|
+
/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- from upstream code */
|
|
445
|
+
token.children,
|
|
446
|
+
options2,
|
|
447
|
+
env
|
|
448
|
+
);
|
|
449
|
+
return self.renderToken(tokens, index, options2);
|
|
450
|
+
}
|
|
451
|
+
return function(md) {
|
|
452
|
+
md.renderer.rules.image = imageResource;
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
const markerStr = ":";
|
|
457
|
+
const markerChar = markerStr.charCodeAt(0);
|
|
458
|
+
function parser(md, options) {
|
|
459
|
+
function container(state, startLine, endLine, silent) {
|
|
460
|
+
let pos = state.bMarks[startLine] + state.tShift[startLine];
|
|
461
|
+
let max = state.eMarks[startLine];
|
|
462
|
+
if (state.sCount[startLine] - state.blkIndent >= 4) {
|
|
463
|
+
return false;
|
|
464
|
+
}
|
|
465
|
+
if (pos + 3 > max) {
|
|
466
|
+
return false;
|
|
467
|
+
}
|
|
468
|
+
const marker = state.src.charCodeAt(pos);
|
|
469
|
+
if (marker !== markerChar) {
|
|
470
|
+
return false;
|
|
471
|
+
}
|
|
472
|
+
let mem = pos;
|
|
473
|
+
pos = state.skipChars(pos, marker);
|
|
474
|
+
let len = pos - mem;
|
|
475
|
+
if (len < 3) {
|
|
476
|
+
return false;
|
|
477
|
+
}
|
|
478
|
+
const markup = state.src.slice(mem, pos);
|
|
479
|
+
const params = state.src.slice(pos, max).trim();
|
|
480
|
+
const kind = params.split(" ", 2)[0];
|
|
481
|
+
if (silent) {
|
|
482
|
+
return true;
|
|
483
|
+
}
|
|
484
|
+
let nextLine = startLine;
|
|
485
|
+
let haveEndMarker = false;
|
|
486
|
+
for (; ; ) {
|
|
487
|
+
nextLine++;
|
|
488
|
+
if (nextLine >= endLine) {
|
|
489
|
+
break;
|
|
490
|
+
}
|
|
491
|
+
pos = mem = state.bMarks[nextLine] + state.tShift[nextLine];
|
|
492
|
+
max = state.eMarks[nextLine];
|
|
493
|
+
if (pos < max && state.sCount[nextLine] < state.blkIndent) {
|
|
494
|
+
break;
|
|
495
|
+
}
|
|
496
|
+
if (state.src.charCodeAt(pos) !== marker) {
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
if (state.sCount[nextLine] - state.blkIndent >= 4) {
|
|
500
|
+
continue;
|
|
501
|
+
}
|
|
502
|
+
pos = state.skipChars(pos, marker);
|
|
503
|
+
if (pos - mem < len) {
|
|
504
|
+
continue;
|
|
505
|
+
}
|
|
506
|
+
pos = state.skipSpaces(pos);
|
|
507
|
+
if (pos < max) {
|
|
508
|
+
continue;
|
|
509
|
+
}
|
|
510
|
+
haveEndMarker = true;
|
|
511
|
+
break;
|
|
512
|
+
}
|
|
513
|
+
len = state.sCount[startLine];
|
|
514
|
+
state.line = nextLine + (haveEndMarker ? 1 : 0);
|
|
515
|
+
const token = state.push(`doc_${kind}`, "div", 0);
|
|
516
|
+
token.info = params;
|
|
517
|
+
token.content = state.getLines(startLine + 1, nextLine, len, true);
|
|
518
|
+
token.markup = markup;
|
|
519
|
+
token.map = [startLine, state.line];
|
|
520
|
+
return true;
|
|
521
|
+
}
|
|
522
|
+
md.block.ruler.before("fence", "container_include", container, {
|
|
523
|
+
alt: ["paragraph", "reference", "blockquote", "list"]
|
|
524
|
+
});
|
|
525
|
+
for (const [kind, fn] of Object.entries(options)) {
|
|
526
|
+
md.renderer.rules[`doc_${kind}`] = fn;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
function include(docs, env, included, handleSoftError) {
|
|
530
|
+
return function(md) {
|
|
531
|
+
md.use(parser, {
|
|
532
|
+
api(tokens, index) {
|
|
533
|
+
const token = tokens[index];
|
|
534
|
+
const needle = token.content.trim();
|
|
535
|
+
const doc = findDocument(docs, needle);
|
|
536
|
+
if (!doc) {
|
|
537
|
+
return handleSoftError(
|
|
538
|
+
new SoftError(
|
|
539
|
+
"EINCLUDETARGET",
|
|
540
|
+
`No document matches "${needle}" when trying to include content`,
|
|
541
|
+
{ id: needle }
|
|
542
|
+
)
|
|
543
|
+
);
|
|
544
|
+
}
|
|
545
|
+
if (included.has(doc.id)) {
|
|
546
|
+
return handleSoftError(
|
|
547
|
+
new SoftError(
|
|
548
|
+
"EINCLUDERECURSION",
|
|
549
|
+
`Recursion detected when including document "${doc.id}"`
|
|
550
|
+
)
|
|
551
|
+
);
|
|
552
|
+
}
|
|
553
|
+
included.add(doc.id);
|
|
554
|
+
if (doc.format === "html") {
|
|
555
|
+
return doc.body;
|
|
556
|
+
}
|
|
557
|
+
const content = md.render(doc.body, env);
|
|
558
|
+
return (
|
|
559
|
+
/* HTML */
|
|
560
|
+
` <div>${content}</div> `
|
|
561
|
+
);
|
|
562
|
+
}
|
|
563
|
+
});
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
function table() {
|
|
568
|
+
return function(md) {
|
|
569
|
+
md.renderer.rules.table_open = () => `<table class="table">
|
|
570
|
+
`;
|
|
571
|
+
md.renderer.rules.tr_open = () => `<tr class="table__row">
|
|
572
|
+
`;
|
|
573
|
+
md.renderer.rules.th_open = () => `<th class="table__column table__column--text" scope="col">`;
|
|
574
|
+
md.renderer.rules.td_open = () => `<td class="table__column table__column--text">`;
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
function codeInline() {
|
|
579
|
+
return function(md) {
|
|
580
|
+
const original = md.renderer.rules.code_inline;
|
|
581
|
+
md.renderer.rules.code_inline = (...args) => {
|
|
582
|
+
const tmp = original(...args);
|
|
583
|
+
return replaceAtLink(tmp);
|
|
584
|
+
};
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
function createMarkdownRenderer(options) {
|
|
589
|
+
const { docs } = options;
|
|
590
|
+
const env = {
|
|
591
|
+
fileInfo: {
|
|
592
|
+
fullPath: "",
|
|
593
|
+
name: "",
|
|
594
|
+
path: "",
|
|
595
|
+
outputName: false
|
|
596
|
+
},
|
|
597
|
+
ids: /* @__PURE__ */ new Set()
|
|
598
|
+
};
|
|
599
|
+
const included = /* @__PURE__ */ new Set();
|
|
600
|
+
const md = vendor.MarkdownIt({
|
|
601
|
+
html: true
|
|
602
|
+
});
|
|
603
|
+
md.use(
|
|
604
|
+
codePreview({
|
|
605
|
+
generateExample: options.generateExample
|
|
606
|
+
})
|
|
607
|
+
);
|
|
608
|
+
md.use(headingLevel({ initialLevel: 1 }));
|
|
609
|
+
md.use(
|
|
610
|
+
imageResources({
|
|
611
|
+
addResource: options.addResource
|
|
612
|
+
})
|
|
613
|
+
);
|
|
614
|
+
md.use(include(docs, env, included, options.handleSoftError));
|
|
615
|
+
md.use(table());
|
|
616
|
+
md.use(codeInline());
|
|
617
|
+
return {
|
|
618
|
+
render(doc, content) {
|
|
619
|
+
included.clear();
|
|
620
|
+
included.add(doc.id);
|
|
621
|
+
env.fileInfo = doc.fileInfo;
|
|
622
|
+
env.ids = /* @__PURE__ */ new Set();
|
|
623
|
+
const html = md.render(content, env);
|
|
624
|
+
return processInlineTags(
|
|
625
|
+
inlineTags,
|
|
626
|
+
doc,
|
|
627
|
+
docs,
|
|
628
|
+
html,
|
|
629
|
+
options.handleSoftError
|
|
630
|
+
);
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
exports.SoftError = SoftError;
|
|
636
|
+
exports.createMarkdownRenderer = createMarkdownRenderer;
|
|
637
|
+
exports.generateId = generateId;
|
|
638
|
+
exports.getFingerprint = getFingerprint;
|
|
639
|
+
exports.getOutputFilePath = getOutputFilePath;
|
|
640
|
+
exports.normalizePath = normalizePath;
|
|
@@ -26,6 +26,13 @@ export declare interface CompileOptions {
|
|
|
26
26
|
attributes: AttributeTable;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Tiny wrapper to provide type completion for IDE.
|
|
31
|
+
*
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
export declare function defineSources(sources: SourceFiles[]): SourceFiles[];
|
|
35
|
+
|
|
29
36
|
/**
|
|
30
37
|
* @public
|
|
31
38
|
*/
|
|
@@ -332,7 +339,7 @@ export declare interface ProcessorContext {
|
|
|
332
339
|
* @param id - A unique identifier for this block.
|
|
333
340
|
* @param renderer - Describes how to render the block content.
|
|
334
341
|
*/
|
|
335
|
-
addTemplateBlock(container: string, id: string, renderer: TemplateBlockRenderer): void;
|
|
342
|
+
addTemplateBlock<T>(container: string, id: string, renderer: TemplateBlockRenderer<T>): void;
|
|
336
343
|
/* Excluded from this release type: getAllTemplateBlocks */
|
|
337
344
|
setTopNavigation(root: NavigationSection): void;
|
|
338
345
|
setSideNavigation(root: NavigationSection): void;
|
|
@@ -444,9 +451,9 @@ export declare interface SourceFiles {
|
|
|
444
451
|
*
|
|
445
452
|
* @public
|
|
446
453
|
*/
|
|
447
|
-
export declare type TemplateBlockRenderer = {
|
|
454
|
+
export declare type TemplateBlockRenderer<T> = {
|
|
448
455
|
filename: string;
|
|
449
|
-
data?:
|
|
456
|
+
data?: T;
|
|
450
457
|
} | {
|
|
451
458
|
render(): string;
|
|
452
459
|
};
|
|
@@ -464,6 +471,26 @@ export declare interface TemplateData {
|
|
|
464
471
|
*/
|
|
465
472
|
export declare function themeSelectProcessor(): Processor;
|
|
466
473
|
|
|
474
|
+
/**
|
|
475
|
+
* Single entry for a topnav item.
|
|
476
|
+
*
|
|
477
|
+
* @public
|
|
478
|
+
*/
|
|
479
|
+
export declare interface TopnavEntry {
|
|
480
|
+
path: string;
|
|
481
|
+
title: string;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* Processor to create a manual topnav:
|
|
486
|
+
*
|
|
487
|
+
* - Custom order.
|
|
488
|
+
* - Custom items.
|
|
489
|
+
*
|
|
490
|
+
* @public
|
|
491
|
+
*/
|
|
492
|
+
export declare function topnavProcessor(filename: string, title: string): Processor;
|
|
493
|
+
|
|
467
494
|
/**
|
|
468
495
|
* Represents a compiled vendor asset.
|
|
469
496
|
*
|
|
@@ -555,7 +582,21 @@ export declare function versionBannerProcessor(message: string, container: strin
|
|
|
555
582
|
export declare function versionProcessor(pkg: {
|
|
556
583
|
name: string;
|
|
557
584
|
version: string;
|
|
558
|
-
|
|
585
|
+
homepage: string;
|
|
586
|
+
}, container: string, options?: VersionProcessorOptions): Processor;
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* Options for {@link versionProcessor}.
|
|
590
|
+
*
|
|
591
|
+
* @public
|
|
592
|
+
*/
|
|
593
|
+
export declare interface VersionProcessorOptions {
|
|
594
|
+
readonly enabled: boolean;
|
|
595
|
+
readonly scm?: {
|
|
596
|
+
readonly commitUrlFormat: string;
|
|
597
|
+
readonly prUrlFormat: string;
|
|
598
|
+
};
|
|
599
|
+
}
|
|
559
600
|
|
|
560
601
|
/**
|
|
561
602
|
* Generate API documentation from a Vue SFC.
|