@d10f/asciidoc-astro-loader 0.0.2 → 0.0.4
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/README.md +153 -95
- package/dist/chunk-2UGTFP4R.js +22 -0
- package/dist/chunk-5P6LDJGO.js +65 -0
- package/dist/{chunk-BRMWIQA2.js → chunk-NC6IZHLR.js} +8 -10
- package/dist/{index-BNxO58s3.d.cts → index-CS3PBqxf.d.cts} +159 -66
- package/dist/{index-BNxO58s3.d.ts → index-CS3PBqxf.d.ts} +159 -66
- package/dist/index.cjs +227 -254
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +47 -37
- package/dist/lib/asciidoc/converters/index.cjs +6 -100
- package/dist/lib/asciidoc/converters/index.d.cts +5 -5
- package/dist/lib/asciidoc/converters/index.d.ts +5 -5
- package/dist/lib/asciidoc/converters/index.js +2 -2
- package/dist/lib/asciidoc/templates/engines/index.d.cts +1 -1
- package/dist/lib/asciidoc/templates/engines/index.d.ts +1 -1
- package/dist/lib/shiki/transformers/index.cjs +120 -79
- package/dist/lib/shiki/transformers/index.d.cts +52 -32
- package/dist/lib/shiki/transformers/index.d.ts +52 -32
- package/dist/lib/shiki/transformers/index.js +76 -4
- package/package.json +1 -1
- package/dist/chunk-DDIUST2Z.js +0 -113
package/dist/index.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
sourceCodeConverter
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-NC6IZHLR.js";
|
|
4
|
+
import {
|
|
5
|
+
transformAsciidocCallout
|
|
6
|
+
} from "./chunk-5P6LDJGO.js";
|
|
4
7
|
import {
|
|
5
8
|
slugify,
|
|
6
9
|
splitFilenameComponents
|
|
7
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-2UGTFP4R.js";
|
|
8
11
|
import {
|
|
9
12
|
HandlebarsEngine,
|
|
10
13
|
NunjucksEngine
|
|
@@ -279,13 +282,18 @@ var shikiOptionsSchema = z2.object({
|
|
|
279
282
|
cssVariablePrefix: z2.string().default("--shiki-"),
|
|
280
283
|
mergeWhitespaces: z2.union([z2.boolean(), z2.literal("never")]).default(true),
|
|
281
284
|
tabindex: z2.union([z2.number(), z2.string(), z2.literal(false)]).default(false),
|
|
282
|
-
transformers:
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
)
|
|
288
|
-
|
|
285
|
+
// transformers: z
|
|
286
|
+
// .array(
|
|
287
|
+
// z.object({
|
|
288
|
+
// name: z.string(),
|
|
289
|
+
// enforce: z.union([z.literal('pre'), z.literal('post')]),
|
|
290
|
+
// }),
|
|
291
|
+
// )
|
|
292
|
+
// .optional(),
|
|
293
|
+
callouts: z2.object({
|
|
294
|
+
cssClasses: z2.string().optional()
|
|
295
|
+
}).optional()
|
|
296
|
+
}).passthrough().transform(({ theme, ...rest }) => ({
|
|
289
297
|
themes: theme,
|
|
290
298
|
...rest
|
|
291
299
|
})).default({
|
|
@@ -297,7 +305,8 @@ var shikiOptionsSchema = z2.object({
|
|
|
297
305
|
light: "catppuccin-latte",
|
|
298
306
|
dark: "catppuccin-macchiato"
|
|
299
307
|
},
|
|
300
|
-
transformers:
|
|
308
|
+
// transformers: undefined,
|
|
309
|
+
callouts: void 0
|
|
301
310
|
});
|
|
302
311
|
function transformThemeProp(value) {
|
|
303
312
|
return typeof value === "string" ? { light: value, dark: value } : value;
|
|
@@ -342,13 +351,13 @@ async function createHighlighter(documents, themes) {
|
|
|
342
351
|
}
|
|
343
352
|
|
|
344
353
|
// src/loader.ts
|
|
345
|
-
function asciidocLoader(
|
|
346
|
-
const
|
|
347
|
-
if (
|
|
348
|
-
|
|
354
|
+
function asciidocLoader(_options) {
|
|
355
|
+
const options = loaderOptionsSchema.parse(_options);
|
|
356
|
+
if (options.document.converters === void 0) {
|
|
357
|
+
options.document.converters = [];
|
|
349
358
|
}
|
|
350
|
-
if (
|
|
351
|
-
|
|
359
|
+
if (options.document.templateEngines === void 0) {
|
|
360
|
+
options.document.templateEngines = [
|
|
352
361
|
new HandlebarsEngine(),
|
|
353
362
|
new NunjucksEngine()
|
|
354
363
|
];
|
|
@@ -360,18 +369,18 @@ function asciidocLoader(options) {
|
|
|
360
369
|
async load(loaderContext) {
|
|
361
370
|
const { config, logger, watcher } = loaderContext;
|
|
362
371
|
const root = config.root.pathname;
|
|
363
|
-
const base =
|
|
372
|
+
const base = options.base.startsWith(".") ? realpathSync(options.base) : root + options.base;
|
|
364
373
|
const docs = readdirSync2(base, "utf8").filter((file) => file.match(/(?:\.a(?:scii)?doc)$/)).map((filename) => new AsciidocDocument(`${base}/${filename}`));
|
|
365
374
|
if (docs.length === 0) {
|
|
366
375
|
logger.warn("No documents found for this collection.");
|
|
367
376
|
return;
|
|
368
377
|
}
|
|
369
|
-
if (
|
|
378
|
+
if (options.document.template) {
|
|
370
379
|
templateEngine = new TemplateEngineRegistry(
|
|
371
|
-
|
|
380
|
+
options.document.templateEngines,
|
|
372
381
|
{
|
|
373
|
-
rootDir:
|
|
374
|
-
recursive:
|
|
382
|
+
rootDir: options.document.template,
|
|
383
|
+
recursive: options.document.recursive
|
|
375
384
|
}
|
|
376
385
|
);
|
|
377
386
|
await templateEngine.loadEngines();
|
|
@@ -379,11 +388,11 @@ function asciidocLoader(options) {
|
|
|
379
388
|
if (!highlighter) {
|
|
380
389
|
highlighter = await createHighlighter(
|
|
381
390
|
docs,
|
|
382
|
-
|
|
391
|
+
options.syntaxHighlighting.themes
|
|
383
392
|
);
|
|
384
393
|
}
|
|
385
|
-
const converters =
|
|
386
|
-
(converter) => converter(
|
|
394
|
+
const converters = options.document.converters.map(
|
|
395
|
+
(converter) => converter(options, highlighter)
|
|
387
396
|
);
|
|
388
397
|
const hasSourceCodeConverter = converters.find(
|
|
389
398
|
(converter) => converter.nodeContext === "listing" && converter?.nodeStyle === "source"
|
|
@@ -391,18 +400,18 @@ function asciidocLoader(options) {
|
|
|
391
400
|
if (!hasSourceCodeConverter) {
|
|
392
401
|
converters.push(
|
|
393
402
|
sourceCodeConverter({
|
|
394
|
-
transformers:
|
|
395
|
-
|
|
403
|
+
transformers: [
|
|
404
|
+
...options.syntaxHighlighting.transformers ?? [],
|
|
405
|
+
transformAsciidocCallout(
|
|
406
|
+
options.syntaxHighlighting.callouts
|
|
407
|
+
)
|
|
408
|
+
]
|
|
409
|
+
})(options, highlighter)
|
|
396
410
|
);
|
|
397
411
|
}
|
|
398
412
|
await Promise.all(
|
|
399
413
|
docs.map(
|
|
400
|
-
(doc) =>
|
|
401
|
-
doc,
|
|
402
|
-
converters,
|
|
403
|
-
templateEngine,
|
|
404
|
-
loaderContext
|
|
405
|
-
)
|
|
414
|
+
(doc) => setDocument(doc, converters, templateEngine, loaderContext)
|
|
406
415
|
)
|
|
407
416
|
);
|
|
408
417
|
if (watcher) {
|
|
@@ -415,11 +424,10 @@ function asciidocLoader(options) {
|
|
|
415
424
|
const watchedFileRegExp = new RegExp(
|
|
416
425
|
`^${base}.*.(a(?:scii)?doc)$`
|
|
417
426
|
);
|
|
418
|
-
console.log(this.name);
|
|
419
427
|
watcher.on("change", async (changedPath) => {
|
|
420
428
|
if (changedPath.match(watchedFileRegExp)) {
|
|
421
429
|
const newDoc = new AsciidocDocument(changedPath);
|
|
422
|
-
await
|
|
430
|
+
await setDocument(
|
|
423
431
|
newDoc,
|
|
424
432
|
converters,
|
|
425
433
|
templateEngine,
|
|
@@ -427,15 +435,17 @@ function asciidocLoader(options) {
|
|
|
427
435
|
);
|
|
428
436
|
}
|
|
429
437
|
});
|
|
430
|
-
|
|
431
|
-
|
|
438
|
+
if (highlighter) {
|
|
439
|
+
process.on("SIGINT", handle2);
|
|
440
|
+
process.on("SIGTERM", handle2);
|
|
441
|
+
}
|
|
432
442
|
} else {
|
|
433
443
|
nextTick(highlighter.dispose);
|
|
434
444
|
}
|
|
435
445
|
}
|
|
436
446
|
};
|
|
437
447
|
}
|
|
438
|
-
async function
|
|
448
|
+
async function setDocument(doc, converters, templateEngine, { parseData, store }) {
|
|
439
449
|
const data = await parseData({
|
|
440
450
|
id: doc.slug,
|
|
441
451
|
data: {
|
|
@@ -28,10 +28,6 @@ module.exports = __toCommonJS(converters_exports);
|
|
|
28
28
|
var import_node_path = require("path");
|
|
29
29
|
|
|
30
30
|
// src/lib/utils.ts
|
|
31
|
-
function escapeRegexCharacters(str) {
|
|
32
|
-
const re = /[-\\^$*+?.()|\[\]{}]/g;
|
|
33
|
-
return str.replace(re, "\\$&");
|
|
34
|
-
}
|
|
35
31
|
function splitFilenameComponents(filename) {
|
|
36
32
|
const match = filename.match(/^(?<path>.*\/)*(?<name>[^\.]+)\.(?<ext>.*)$/);
|
|
37
33
|
return {
|
|
@@ -41,98 +37,10 @@ function splitFilenameComponents(filename) {
|
|
|
41
37
|
};
|
|
42
38
|
}
|
|
43
39
|
|
|
44
|
-
// src/lib/shiki/transformers/transformAsciidocCallout.ts
|
|
45
|
-
function transformAsciidocCallout({
|
|
46
|
-
node,
|
|
47
|
-
cssClasses = "pointer-events-none select-none ml-2"
|
|
48
|
-
}) {
|
|
49
|
-
const lineComments = ["//", "#", ";;"];
|
|
50
|
-
const customLineComment = node.getAttribute("line-comment");
|
|
51
|
-
if (customLineComment) {
|
|
52
|
-
lineComments.push(escapeRegexCharacters(customLineComment));
|
|
53
|
-
}
|
|
54
|
-
const calloutReList = [
|
|
55
|
-
// Handles C-style and similar comments like Perl, Python...
|
|
56
|
-
new RegExp(`(?:${lineComments.join("|")})((?:\\s+<(\\d+)>)+)`),
|
|
57
|
-
// Handles XML comments
|
|
58
|
-
new RegExp(/((?:\s*<!--(\d+)-->)+)/)
|
|
59
|
-
];
|
|
60
|
-
const linesWithCallout = {};
|
|
61
|
-
return {
|
|
62
|
-
preprocess(code) {
|
|
63
|
-
return code.split("\n").map((line, idx) => {
|
|
64
|
-
for (const re of calloutReList) {
|
|
65
|
-
const match = line.match(re);
|
|
66
|
-
if (!match) continue;
|
|
67
|
-
const callouts = match[0].trim().replaceAll(/(?:<!--|-->|[<>])/g, "").split(" ");
|
|
68
|
-
linesWithCallout[idx + 1] = callouts;
|
|
69
|
-
return line.replace(re, "");
|
|
70
|
-
}
|
|
71
|
-
return line;
|
|
72
|
-
}).join("\n");
|
|
73
|
-
},
|
|
74
|
-
line(hast, line) {
|
|
75
|
-
const callouts = linesWithCallout[line];
|
|
76
|
-
if (!callouts) return;
|
|
77
|
-
callouts.forEach((calloutId) => {
|
|
78
|
-
hast.properties[`data-callout-${calloutId}`] = "";
|
|
79
|
-
hast.children.push({
|
|
80
|
-
type: "element",
|
|
81
|
-
tagName: "i",
|
|
82
|
-
properties: {
|
|
83
|
-
class: `conum ${cssClasses}`,
|
|
84
|
-
"data-value": calloutId
|
|
85
|
-
},
|
|
86
|
-
children: [
|
|
87
|
-
{
|
|
88
|
-
type: "element",
|
|
89
|
-
tagName: "b",
|
|
90
|
-
properties: {},
|
|
91
|
-
children: [
|
|
92
|
-
{
|
|
93
|
-
type: "text",
|
|
94
|
-
value: calloutId
|
|
95
|
-
}
|
|
96
|
-
]
|
|
97
|
-
}
|
|
98
|
-
]
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// src/lib/shiki/transformers/transformConsoleCodeBlock.ts
|
|
106
|
-
function transformConsoleCodeBlock(options = {
|
|
107
|
-
cssClasses: "pointer-events-none select-none mr-2 opacity-50"
|
|
108
|
-
}) {
|
|
109
|
-
const unselectablePrompt = `<span $1 class="${options.cssClasses}">$</span>`;
|
|
110
|
-
const linePrefix = '<span class="line[^>]+?>';
|
|
111
|
-
const splitPrompt = new RegExp(
|
|
112
|
-
`(?<=${linePrefix})(?:<span (style="[^"]*?")>\\s*?\\$\\s+?([^<]))`
|
|
113
|
-
);
|
|
114
|
-
const trimWhitespace = new RegExp(
|
|
115
|
-
`(?<=${linePrefix})(?:<span (style="[^"]*?")>\\s*?\\$\\s*?<\\/span>(?:<span>\\s+<\\/span>)?)`
|
|
116
|
-
);
|
|
117
|
-
const trimWhitespaceAhead = new RegExp(
|
|
118
|
-
`(?<=${linePrefix}<span [^>]+?>\\$<\\/span>)(<span style="[^"]+?">)\\s+?`
|
|
119
|
-
);
|
|
120
|
-
return {
|
|
121
|
-
postprocess: (html, { lang }) => {
|
|
122
|
-
if (lang === "console") {
|
|
123
|
-
return html.split("\n").map((line) => {
|
|
124
|
-
return line.replace(
|
|
125
|
-
splitPrompt,
|
|
126
|
-
unselectablePrompt + "<span $1>$2"
|
|
127
|
-
).replace(trimWhitespace, unselectablePrompt).replace(trimWhitespaceAhead, "$1");
|
|
128
|
-
}).join("\n");
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
|
|
134
40
|
// src/lib/asciidoc/converters/sourceCodeConverter.ts
|
|
135
|
-
var sourceCodeConverter = (
|
|
41
|
+
var sourceCodeConverter = (converterOptions) => {
|
|
42
|
+
const transformers = converterOptions?.transformers;
|
|
43
|
+
const template = converterOptions?.template;
|
|
136
44
|
return (options, highlighter) => {
|
|
137
45
|
return {
|
|
138
46
|
nodeContext: "listing",
|
|
@@ -143,11 +51,9 @@ var sourceCodeConverter = ({ transformers, template }) => {
|
|
|
143
51
|
const output = highlighter.codeToHtml(input, {
|
|
144
52
|
...options.syntaxHighlighting,
|
|
145
53
|
lang,
|
|
146
|
-
transformers: [
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
transformConsoleCodeBlock()
|
|
150
|
-
]
|
|
54
|
+
transformers: (transformers ?? []).map((transformer) => {
|
|
55
|
+
return typeof transformer === "function" ? transformer(node) : transformer;
|
|
56
|
+
})
|
|
151
57
|
});
|
|
152
58
|
if (templateEngine && template) {
|
|
153
59
|
const { extension } = splitFilenameComponents(template);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { ShikiTransformer } from 'shiki';
|
|
2
|
-
import { C as CustomConverterFactoryFn } from '../../../index-
|
|
2
|
+
import { C as CustomConverterFactoryFn, S as ShikiTransformerFactoryFn } from '../../../index-CS3PBqxf.cjs';
|
|
3
3
|
import 'asciidoctor';
|
|
4
4
|
import 'astro/zod';
|
|
5
5
|
|
|
6
|
-
type CodeBlockConverterOptions = {
|
|
7
|
-
transformers: ShikiTransformer
|
|
6
|
+
type CodeBlockConverterOptions = Partial<{
|
|
7
|
+
transformers: Array<ShikiTransformer | ShikiTransformerFactoryFn>;
|
|
8
8
|
template: string;
|
|
9
|
-
}
|
|
10
|
-
declare const sourceCodeConverter: CustomConverterFactoryFn<
|
|
9
|
+
}>;
|
|
10
|
+
declare const sourceCodeConverter: CustomConverterFactoryFn<CodeBlockConverterOptions>;
|
|
11
11
|
|
|
12
12
|
export { sourceCodeConverter };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { ShikiTransformer } from 'shiki';
|
|
2
|
-
import { C as CustomConverterFactoryFn } from '../../../index-
|
|
2
|
+
import { C as CustomConverterFactoryFn, S as ShikiTransformerFactoryFn } from '../../../index-CS3PBqxf.js';
|
|
3
3
|
import 'asciidoctor';
|
|
4
4
|
import 'astro/zod';
|
|
5
5
|
|
|
6
|
-
type CodeBlockConverterOptions = {
|
|
7
|
-
transformers: ShikiTransformer
|
|
6
|
+
type CodeBlockConverterOptions = Partial<{
|
|
7
|
+
transformers: Array<ShikiTransformer | ShikiTransformerFactoryFn>;
|
|
8
8
|
template: string;
|
|
9
|
-
}
|
|
10
|
-
declare const sourceCodeConverter: CustomConverterFactoryFn<
|
|
9
|
+
}>;
|
|
10
|
+
declare const sourceCodeConverter: CustomConverterFactoryFn<CodeBlockConverterOptions>;
|
|
11
11
|
|
|
12
12
|
export { sourceCodeConverter };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as AbstractEngine, a as AsciidocTemplate, T as TemplateModule, F as FilesystemTemplate, R as RawTemplate } from '../../../../index-CS3PBqxf.cjs';
|
|
2
2
|
import { AbstractBlock } from 'asciidoctor';
|
|
3
3
|
import 'shiki';
|
|
4
4
|
import 'astro/zod';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as AbstractEngine, a as AsciidocTemplate, T as TemplateModule, F as FilesystemTemplate, R as RawTemplate } from '../../../../index-CS3PBqxf.js';
|
|
2
2
|
import { AbstractBlock } from 'asciidoctor';
|
|
3
3
|
import 'shiki';
|
|
4
4
|
import 'astro/zod';
|
|
@@ -21,7 +21,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var transformers_exports = {};
|
|
22
22
|
__export(transformers_exports, {
|
|
23
23
|
transformAsciidocCallout: () => transformAsciidocCallout,
|
|
24
|
-
|
|
24
|
+
transformConsolePrompt: () => transformConsolePrompt,
|
|
25
|
+
transformerPrompt: () => transformerPrompt
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(transformers_exports);
|
|
27
28
|
|
|
@@ -32,84 +33,93 @@ function escapeRegexCharacters(str) {
|
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
// src/lib/shiki/transformers/transformAsciidocCallout.ts
|
|
35
|
-
|
|
36
|
-
node
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (customLineComment) {
|
|
42
|
-
lineComments.push(escapeRegexCharacters(customLineComment));
|
|
43
|
-
}
|
|
44
|
-
const calloutReList = [
|
|
45
|
-
// Handles C-style and similar comments like Perl, Python...
|
|
46
|
-
new RegExp(`(?:${lineComments.join("|")})((?:\\s+<(\\d+)>)+)`),
|
|
47
|
-
// Handles XML comments
|
|
48
|
-
new RegExp(/((?:\s*<!--(\d+)-->)+)/)
|
|
49
|
-
];
|
|
50
|
-
const linesWithCallout = {};
|
|
51
|
-
return {
|
|
52
|
-
preprocess(code) {
|
|
53
|
-
return code.split("\n").map((line, idx) => {
|
|
54
|
-
for (const re of calloutReList) {
|
|
55
|
-
const match = line.match(re);
|
|
56
|
-
if (!match) continue;
|
|
57
|
-
const callouts = match[0].trim().replaceAll(/(?:<!--|-->|[<>])/g, "").split(" ");
|
|
58
|
-
linesWithCallout[idx + 1] = callouts;
|
|
59
|
-
return line.replace(re, "");
|
|
60
|
-
}
|
|
61
|
-
return line;
|
|
62
|
-
}).join("\n");
|
|
63
|
-
},
|
|
64
|
-
line(hast, line) {
|
|
65
|
-
const callouts = linesWithCallout[line];
|
|
66
|
-
if (!callouts) return;
|
|
67
|
-
callouts.forEach((calloutId) => {
|
|
68
|
-
hast.properties[`data-callout-${calloutId}`] = "";
|
|
69
|
-
hast.children.push({
|
|
70
|
-
type: "element",
|
|
71
|
-
tagName: "i",
|
|
72
|
-
properties: {
|
|
73
|
-
class: `conum ${cssClasses}`,
|
|
74
|
-
"data-value": calloutId
|
|
75
|
-
},
|
|
76
|
-
children: [
|
|
77
|
-
{
|
|
78
|
-
type: "element",
|
|
79
|
-
tagName: "b",
|
|
80
|
-
properties: {},
|
|
81
|
-
children: [
|
|
82
|
-
{
|
|
83
|
-
type: "text",
|
|
84
|
-
value: calloutId
|
|
85
|
-
}
|
|
86
|
-
]
|
|
87
|
-
}
|
|
88
|
-
]
|
|
89
|
-
});
|
|
90
|
-
});
|
|
36
|
+
var transformAsciidocCallout = (options) => {
|
|
37
|
+
return (node) => {
|
|
38
|
+
const lineComments = ["//", "#", ";;"];
|
|
39
|
+
const customLineComment = node.getAttribute("line-comment");
|
|
40
|
+
if (customLineComment) {
|
|
41
|
+
lineComments.push(escapeRegexCharacters(customLineComment));
|
|
91
42
|
}
|
|
43
|
+
const calloutReList = [
|
|
44
|
+
// Handles C-style and similar comments like Perl, Python...
|
|
45
|
+
new RegExp(`\\s+(?:${lineComments.join("|")})((?:\\s+<(\\d+)>)+)`),
|
|
46
|
+
// Handles XML comments
|
|
47
|
+
new RegExp(/((?:\s*<!--(\d+)-->)+)/)
|
|
48
|
+
];
|
|
49
|
+
const commentTokensRe = new RegExp(
|
|
50
|
+
`(?:${lineComments.join("|")}|<!--|-->|[<>])`,
|
|
51
|
+
"g"
|
|
52
|
+
);
|
|
53
|
+
const linesWithCallout = {};
|
|
54
|
+
return {
|
|
55
|
+
preprocess(code) {
|
|
56
|
+
return code.split("\n").map((line, idx) => {
|
|
57
|
+
for (const re of calloutReList) {
|
|
58
|
+
const match = line.match(re);
|
|
59
|
+
if (!match) continue;
|
|
60
|
+
const callouts = match[0].replaceAll(commentTokensRe, "").trim().split(" ");
|
|
61
|
+
linesWithCallout[idx + 1] = callouts;
|
|
62
|
+
return line.replace(re, "");
|
|
63
|
+
}
|
|
64
|
+
return line;
|
|
65
|
+
}).join("\n");
|
|
66
|
+
},
|
|
67
|
+
line(hast, line) {
|
|
68
|
+
const callouts = linesWithCallout[line];
|
|
69
|
+
if (!callouts) return;
|
|
70
|
+
callouts.forEach((calloutId) => {
|
|
71
|
+
hast.properties[`data-callout-${calloutId}`] = "";
|
|
72
|
+
hast.children.push({
|
|
73
|
+
type: "element",
|
|
74
|
+
tagName: "span",
|
|
75
|
+
properties: {
|
|
76
|
+
class: options?.cssClasses ?? "conum",
|
|
77
|
+
style: options?.cssClasses ? "" : "user-select:none; pointer-events:none; opacity:0.5; margin-inline:8px;",
|
|
78
|
+
"data-value": calloutId
|
|
79
|
+
},
|
|
80
|
+
children: [
|
|
81
|
+
{
|
|
82
|
+
type: "text",
|
|
83
|
+
value: calloutId
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
};
|
|
92
90
|
};
|
|
93
|
-
}
|
|
91
|
+
};
|
|
94
92
|
|
|
95
|
-
// src/lib/shiki/transformers/
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
93
|
+
// src/lib/shiki/transformers/transformConsolePrompt.ts
|
|
94
|
+
var transformConsolePrompt = (options) => {
|
|
95
|
+
return (node) => {
|
|
96
|
+
const language = node.getAttribute("language");
|
|
97
|
+
const cssClasses = options?.cssClasses;
|
|
98
|
+
const promptChar = options?.promptChar ?? "$";
|
|
99
|
+
const unselectablePrompt = `<span $1 class="${cssClasses}">${promptChar}</span>`;
|
|
100
|
+
const linePrefix = '<span class="line[^>]+?>';
|
|
101
|
+
const splitPrompt = new RegExp(
|
|
102
|
+
`(?<=${linePrefix})(?:<span (style="[^"]*?")>\\s*?\\${promptChar}\\s+?([^<]))`
|
|
103
|
+
);
|
|
104
|
+
const trimWhitespace = new RegExp(
|
|
105
|
+
`(?<=${linePrefix})(?:<span (style="[^"]*?")>\\s*?\\${promptChar}\\s*?<\\/span>(?:<span>\\s+<\\/span>)?)`
|
|
106
|
+
);
|
|
107
|
+
const trimWhitespaceAhead = new RegExp(
|
|
108
|
+
`(?<=${linePrefix}<span [^>]+?>\\${promptChar}<\\/span>)(<span style="[^"]+?">)\\s+?`
|
|
109
|
+
);
|
|
110
|
+
return {
|
|
111
|
+
line(hast) {
|
|
112
|
+
if (language !== "console") return;
|
|
113
|
+
const textNode = hast.children.at(0)?.children.at(0);
|
|
114
|
+
if (textNode && textNode.type === "text") {
|
|
115
|
+
const leadingChar = textNode.value;
|
|
116
|
+
if (!leadingChar.startsWith(promptChar)) {
|
|
117
|
+
textNode.value = promptChar + " " + textNode.value;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
postprocess: (html) => {
|
|
122
|
+
if (language !== "console") return;
|
|
113
123
|
return html.split("\n").map((line) => {
|
|
114
124
|
return line.replace(
|
|
115
125
|
splitPrompt,
|
|
@@ -117,11 +127,42 @@ function transformConsoleCodeBlock(options = {
|
|
|
117
127
|
).replace(trimWhitespace, unselectablePrompt).replace(trimWhitespaceAhead, "$1");
|
|
118
128
|
}).join("\n");
|
|
119
129
|
}
|
|
120
|
-
}
|
|
130
|
+
};
|
|
121
131
|
};
|
|
122
|
-
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
// src/lib/shiki/transformers/transformerPrompt.ts
|
|
135
|
+
var transformerPrompt = (options) => {
|
|
136
|
+
return (node) => {
|
|
137
|
+
const language = node.getAttribute("language");
|
|
138
|
+
const customPrompt = node.getAttribute(
|
|
139
|
+
options?.promptAttribute ?? "custom-prompt"
|
|
140
|
+
);
|
|
141
|
+
const promptToAdd = customPrompt ?? (options?.prompts && options.prompts[language]);
|
|
142
|
+
const cssClasses = typeof promptToAdd === "object" ? promptToAdd.cssClasses : options?.cssClasses;
|
|
143
|
+
return {
|
|
144
|
+
line(hast) {
|
|
145
|
+
if (!promptToAdd) return;
|
|
146
|
+
hast.children.unshift({
|
|
147
|
+
type: "element",
|
|
148
|
+
tagName: "span",
|
|
149
|
+
properties: {
|
|
150
|
+
class: cssClasses
|
|
151
|
+
},
|
|
152
|
+
children: [
|
|
153
|
+
{
|
|
154
|
+
type: "text",
|
|
155
|
+
value: typeof promptToAdd === "object" ? promptToAdd.prompt : promptToAdd
|
|
156
|
+
}
|
|
157
|
+
]
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
};
|
|
123
163
|
// Annotate the CommonJS export names for ESM import in node:
|
|
124
164
|
0 && (module.exports = {
|
|
125
165
|
transformAsciidocCallout,
|
|
126
|
-
|
|
166
|
+
transformConsolePrompt,
|
|
167
|
+
transformerPrompt
|
|
127
168
|
});
|