@forsakringskassan/docs-generator 1.26.0 → 1.27.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--V6N9Daq.js +625 -0
- package/dist/generator.js +816 -85161
- package/dist/markdown.js +43 -19389
- package/dist/vendor-Dmnzl4fQ.js +56161 -0
- package/dist/vue2-DYKDshbg.js +478 -0
- package/dist/vue3-CEA3zw16.js +12908 -0
- package/package.json +8 -2
|
@@ -0,0 +1,625 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var vendor = require('./vendor-Dmnzl4fQ.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
|
+
if (liveExample) {
|
|
282
|
+
return (
|
|
283
|
+
/* HTML */
|
|
284
|
+
`
|
|
285
|
+
<div
|
|
286
|
+
id="example-${fingerprint}"
|
|
287
|
+
class="code-preview code-preview--borderless"
|
|
288
|
+
${testIdAttr}
|
|
289
|
+
>
|
|
290
|
+
${example.markup}
|
|
291
|
+
</div>
|
|
292
|
+
`
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
if (staticCode) {
|
|
296
|
+
return (
|
|
297
|
+
/* HTML */
|
|
298
|
+
`
|
|
299
|
+
<div
|
|
300
|
+
id="example-${fingerprint}"
|
|
301
|
+
class="code-preview ${modifier}"
|
|
302
|
+
${testIdAttr}
|
|
303
|
+
>
|
|
304
|
+
${example.comments.join("\n")}
|
|
305
|
+
<pre class="code-preview__markup">${highlightedCode}</pre>
|
|
306
|
+
</div>
|
|
307
|
+
`
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
if (noMarkup) {
|
|
311
|
+
return (
|
|
312
|
+
/* HTML */
|
|
313
|
+
`
|
|
314
|
+
<div
|
|
315
|
+
id="example-${fingerprint}"
|
|
316
|
+
class="code-preview ${modifier}"
|
|
317
|
+
${testIdAttr}
|
|
318
|
+
>
|
|
319
|
+
${example.comments.join("\n")}
|
|
320
|
+
<div class="code-preview__preview">${example.markup}</div>
|
|
321
|
+
</div>
|
|
322
|
+
`
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
const toggleMarkup = (
|
|
326
|
+
/* HTML */
|
|
327
|
+
`
|
|
328
|
+
<button
|
|
329
|
+
type="button"
|
|
330
|
+
class="button button--discrete code-preview__toggle-markup"
|
|
331
|
+
aria-expanded="false"
|
|
332
|
+
onclick="toggleMarkup(this)"
|
|
333
|
+
>
|
|
334
|
+
<i class="icon icon--code"></i>
|
|
335
|
+
Visa kod
|
|
336
|
+
</button>
|
|
337
|
+
`
|
|
338
|
+
);
|
|
339
|
+
const toggleFullscreen = fullscreen ? (
|
|
340
|
+
/* HTML */
|
|
341
|
+
`
|
|
342
|
+
<a href="${standalone}" class="code-preview__fullscreen">
|
|
343
|
+
<i class="icon icon--fullscreen"></i>
|
|
344
|
+
Helsk\xE4rm
|
|
345
|
+
</a>
|
|
346
|
+
`
|
|
347
|
+
) : "";
|
|
348
|
+
return (
|
|
349
|
+
/* HTML */
|
|
350
|
+
`
|
|
351
|
+
<div
|
|
352
|
+
id="example-${fingerprint}"
|
|
353
|
+
class="code-preview ${modifier}"
|
|
354
|
+
${testIdAttr}
|
|
355
|
+
>
|
|
356
|
+
${example.comments.join("\n")}
|
|
357
|
+
<div class="code-preview__preview">${example.markup}</div>
|
|
358
|
+
<div>${toggleMarkup} ${toggleFullscreen}</div>
|
|
359
|
+
<div
|
|
360
|
+
class="code-preview__expand animate-expand"
|
|
361
|
+
style="height: 0px;"
|
|
362
|
+
hidden
|
|
363
|
+
>
|
|
364
|
+
<pre class="code-preview__markup">${highlightedCode}</pre>
|
|
365
|
+
</div>
|
|
366
|
+
</div>
|
|
367
|
+
`
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function getTokensText(tokens) {
|
|
373
|
+
return tokens.filter((token) => ["text", "code_inline"].includes(token.type)).map((token) => token.content).join("");
|
|
374
|
+
}
|
|
375
|
+
function headingLevel(options) {
|
|
376
|
+
const { initialLevel } = options;
|
|
377
|
+
const offset = initialLevel - 1;
|
|
378
|
+
let counter = 1;
|
|
379
|
+
return function(md) {
|
|
380
|
+
md.renderer.rules.heading_open = function(tokens, idx, _options, env) {
|
|
381
|
+
var _a;
|
|
382
|
+
const { ids } = env;
|
|
383
|
+
const { tag } = tokens[idx];
|
|
384
|
+
const title = getTokensText(((_a = tokens[idx + 1]) == null ? void 0 : _a.children) ?? []);
|
|
385
|
+
let id = generateId(title);
|
|
386
|
+
if (ids.has(id)) {
|
|
387
|
+
id += `--${counter++}`;
|
|
388
|
+
}
|
|
389
|
+
ids.add(id);
|
|
390
|
+
return tag.replace(/h(\d)/, (_, n) => {
|
|
391
|
+
const level = parseInt(n, 10) + offset;
|
|
392
|
+
return `<h${level} id="${id}"><a class="header-anchor" href="#${id}">`;
|
|
393
|
+
});
|
|
394
|
+
};
|
|
395
|
+
md.renderer.rules.heading_close = function(tokens, idx) {
|
|
396
|
+
const { tag } = tokens[idx];
|
|
397
|
+
return tag.replace(/h(\d)/, (_, n) => {
|
|
398
|
+
const level = parseInt(n, 10) + offset;
|
|
399
|
+
return `</a></h${level}>`;
|
|
400
|
+
});
|
|
401
|
+
};
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function computeHash(source) {
|
|
406
|
+
return crypto.createHash("md5").update(source).digest("hex");
|
|
407
|
+
}
|
|
408
|
+
function getFilename(fileInfo, src) {
|
|
409
|
+
const key = [fileInfo.fullPath, src].join("-");
|
|
410
|
+
const hash = computeHash(key);
|
|
411
|
+
const { ext } = path.parse(src);
|
|
412
|
+
return `images/${hash}${ext}`;
|
|
413
|
+
}
|
|
414
|
+
function imageResources(options) {
|
|
415
|
+
const { addResource } = options;
|
|
416
|
+
function imageResource(tokens, index, options2, env, self) {
|
|
417
|
+
const { fileInfo } = env;
|
|
418
|
+
const token = tokens[index];
|
|
419
|
+
token.attrs ??= [];
|
|
420
|
+
const srcAttr = token.attrGet("src");
|
|
421
|
+
if (srcAttr) {
|
|
422
|
+
const dst = getFilename(fileInfo, srcAttr);
|
|
423
|
+
const src = path.join(path.dirname(fileInfo.fullPath), srcAttr);
|
|
424
|
+
const url = path.relative(fileInfo.path, path.join("assets", dst));
|
|
425
|
+
addResource(dst, src);
|
|
426
|
+
token.attrs[token.attrIndex("src")][1] = url;
|
|
427
|
+
}
|
|
428
|
+
token.attrs[token.attrIndex("alt")][1] = self.renderInlineAsText(
|
|
429
|
+
/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- from upstream code */
|
|
430
|
+
token.children,
|
|
431
|
+
options2,
|
|
432
|
+
env
|
|
433
|
+
);
|
|
434
|
+
return self.renderToken(tokens, index, options2);
|
|
435
|
+
}
|
|
436
|
+
return function(md) {
|
|
437
|
+
md.renderer.rules.image = imageResource;
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
const markerStr = ":";
|
|
442
|
+
const markerChar = markerStr.charCodeAt(0);
|
|
443
|
+
function parser(md, options) {
|
|
444
|
+
function container(state, startLine, endLine, silent) {
|
|
445
|
+
let pos = state.bMarks[startLine] + state.tShift[startLine];
|
|
446
|
+
let max = state.eMarks[startLine];
|
|
447
|
+
if (state.sCount[startLine] - state.blkIndent >= 4) {
|
|
448
|
+
return false;
|
|
449
|
+
}
|
|
450
|
+
if (pos + 3 > max) {
|
|
451
|
+
return false;
|
|
452
|
+
}
|
|
453
|
+
const marker = state.src.charCodeAt(pos);
|
|
454
|
+
if (marker !== markerChar) {
|
|
455
|
+
return false;
|
|
456
|
+
}
|
|
457
|
+
let mem = pos;
|
|
458
|
+
pos = state.skipChars(pos, marker);
|
|
459
|
+
let len = pos - mem;
|
|
460
|
+
if (len < 3) {
|
|
461
|
+
return false;
|
|
462
|
+
}
|
|
463
|
+
const markup = state.src.slice(mem, pos);
|
|
464
|
+
const params = state.src.slice(pos, max).trim();
|
|
465
|
+
const kind = params.split(" ", 2)[0];
|
|
466
|
+
if (silent) {
|
|
467
|
+
return true;
|
|
468
|
+
}
|
|
469
|
+
let nextLine = startLine;
|
|
470
|
+
let haveEndMarker = false;
|
|
471
|
+
for (; ; ) {
|
|
472
|
+
nextLine++;
|
|
473
|
+
if (nextLine >= endLine) {
|
|
474
|
+
break;
|
|
475
|
+
}
|
|
476
|
+
pos = mem = state.bMarks[nextLine] + state.tShift[nextLine];
|
|
477
|
+
max = state.eMarks[nextLine];
|
|
478
|
+
if (pos < max && state.sCount[nextLine] < state.blkIndent) {
|
|
479
|
+
break;
|
|
480
|
+
}
|
|
481
|
+
if (state.src.charCodeAt(pos) !== marker) {
|
|
482
|
+
continue;
|
|
483
|
+
}
|
|
484
|
+
if (state.sCount[nextLine] - state.blkIndent >= 4) {
|
|
485
|
+
continue;
|
|
486
|
+
}
|
|
487
|
+
pos = state.skipChars(pos, marker);
|
|
488
|
+
if (pos - mem < len) {
|
|
489
|
+
continue;
|
|
490
|
+
}
|
|
491
|
+
pos = state.skipSpaces(pos);
|
|
492
|
+
if (pos < max) {
|
|
493
|
+
continue;
|
|
494
|
+
}
|
|
495
|
+
haveEndMarker = true;
|
|
496
|
+
break;
|
|
497
|
+
}
|
|
498
|
+
len = state.sCount[startLine];
|
|
499
|
+
state.line = nextLine + (haveEndMarker ? 1 : 0);
|
|
500
|
+
const token = state.push(`doc_${kind}`, "div", 0);
|
|
501
|
+
token.info = params;
|
|
502
|
+
token.content = state.getLines(startLine + 1, nextLine, len, true);
|
|
503
|
+
token.markup = markup;
|
|
504
|
+
token.map = [startLine, state.line];
|
|
505
|
+
return true;
|
|
506
|
+
}
|
|
507
|
+
md.block.ruler.before("fence", "container_include", container, {
|
|
508
|
+
alt: ["paragraph", "reference", "blockquote", "list"]
|
|
509
|
+
});
|
|
510
|
+
for (const [kind, fn] of Object.entries(options)) {
|
|
511
|
+
md.renderer.rules[`doc_${kind}`] = fn;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
function include(docs, env, included, handleSoftError) {
|
|
515
|
+
return function(md) {
|
|
516
|
+
md.use(parser, {
|
|
517
|
+
api(tokens, index) {
|
|
518
|
+
const token = tokens[index];
|
|
519
|
+
const needle = token.content.trim();
|
|
520
|
+
const doc = findDocument(docs, needle);
|
|
521
|
+
if (!doc) {
|
|
522
|
+
return handleSoftError(
|
|
523
|
+
new SoftError(
|
|
524
|
+
"EINCLUDETARGET",
|
|
525
|
+
`No document matches "${needle}" when trying to include content`,
|
|
526
|
+
{ id: needle }
|
|
527
|
+
)
|
|
528
|
+
);
|
|
529
|
+
}
|
|
530
|
+
if (included.has(doc.id)) {
|
|
531
|
+
return handleSoftError(
|
|
532
|
+
new SoftError(
|
|
533
|
+
"EINCLUDERECURSION",
|
|
534
|
+
`Recursion detected when including document "${doc.id}"`
|
|
535
|
+
)
|
|
536
|
+
);
|
|
537
|
+
}
|
|
538
|
+
included.add(doc.id);
|
|
539
|
+
if (doc.format === "html") {
|
|
540
|
+
return doc.body;
|
|
541
|
+
}
|
|
542
|
+
const content = md.render(doc.body, env);
|
|
543
|
+
return (
|
|
544
|
+
/* HTML */
|
|
545
|
+
` <div>${content}</div> `
|
|
546
|
+
);
|
|
547
|
+
}
|
|
548
|
+
});
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
function table() {
|
|
553
|
+
return function(md) {
|
|
554
|
+
md.renderer.rules.table_open = () => `<table class="table">
|
|
555
|
+
`;
|
|
556
|
+
md.renderer.rules.tr_open = () => `<tr class="table__row">
|
|
557
|
+
`;
|
|
558
|
+
md.renderer.rules.th_open = () => `<th class="table__column table__column--text" scope="col">`;
|
|
559
|
+
md.renderer.rules.td_open = () => `<td class="table__column table__column--text">`;
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
function codeInline() {
|
|
564
|
+
return function(md) {
|
|
565
|
+
const original = md.renderer.rules.code_inline;
|
|
566
|
+
md.renderer.rules.code_inline = (...args) => {
|
|
567
|
+
const tmp = original(...args);
|
|
568
|
+
return replaceAtLink(tmp);
|
|
569
|
+
};
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
function createMarkdownRenderer(options) {
|
|
574
|
+
const { docs } = options;
|
|
575
|
+
const env = {
|
|
576
|
+
fileInfo: {
|
|
577
|
+
fullPath: "",
|
|
578
|
+
name: "",
|
|
579
|
+
path: "",
|
|
580
|
+
outputName: false
|
|
581
|
+
},
|
|
582
|
+
ids: /* @__PURE__ */ new Set()
|
|
583
|
+
};
|
|
584
|
+
const included = /* @__PURE__ */ new Set();
|
|
585
|
+
const md = vendor.MarkdownIt({
|
|
586
|
+
html: true
|
|
587
|
+
});
|
|
588
|
+
md.use(
|
|
589
|
+
codePreview({
|
|
590
|
+
generateExample: options.generateExample
|
|
591
|
+
})
|
|
592
|
+
);
|
|
593
|
+
md.use(headingLevel({ initialLevel: 1 }));
|
|
594
|
+
md.use(
|
|
595
|
+
imageResources({
|
|
596
|
+
addResource: options.addResource
|
|
597
|
+
})
|
|
598
|
+
);
|
|
599
|
+
md.use(include(docs, env, included, options.handleSoftError));
|
|
600
|
+
md.use(table());
|
|
601
|
+
md.use(codeInline());
|
|
602
|
+
return {
|
|
603
|
+
render(doc, content) {
|
|
604
|
+
included.clear();
|
|
605
|
+
included.add(doc.id);
|
|
606
|
+
env.fileInfo = doc.fileInfo;
|
|
607
|
+
env.ids = /* @__PURE__ */ new Set();
|
|
608
|
+
const html = md.render(content, env);
|
|
609
|
+
return processInlineTags(
|
|
610
|
+
inlineTags,
|
|
611
|
+
doc,
|
|
612
|
+
docs,
|
|
613
|
+
html,
|
|
614
|
+
options.handleSoftError
|
|
615
|
+
);
|
|
616
|
+
}
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
exports.SoftError = SoftError;
|
|
621
|
+
exports.createMarkdownRenderer = createMarkdownRenderer;
|
|
622
|
+
exports.generateId = generateId;
|
|
623
|
+
exports.getFingerprint = getFingerprint;
|
|
624
|
+
exports.getOutputFilePath = getOutputFilePath;
|
|
625
|
+
exports.normalizePath = normalizePath;
|