@d10f/asciidoc-astro-loader 0.0.1 → 0.0.3
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 +132 -92
- package/dist/chunk-2UGTFP4R.js +22 -0
- package/dist/chunk-5P6LDJGO.js +65 -0
- package/dist/{chunk-HAZIHU2Y.js → chunk-KZRXEKZK.js} +8 -19
- package/dist/{index-Cf7MF6tZ.d.cts → index-sFlXF8Qm.d.cts} +232 -28
- package/dist/{index-Cf7MF6tZ.d.ts → index-sFlXF8Qm.d.ts} +232 -28
- package/dist/index.cjs +282 -259
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +112 -47
- package/dist/lib/asciidoc/converters/index.cjs +6 -105
- package/dist/lib/asciidoc/converters/index.d.cts +3 -4
- package/dist/lib/asciidoc/converters/index.d.ts +3 -4
- package/dist/lib/asciidoc/converters/index.js +2 -2
- package/dist/lib/asciidoc/templates/engines/index.cjs +2 -23
- package/dist/lib/asciidoc/templates/engines/index.d.cts +6 -12
- package/dist/lib/asciidoc/templates/engines/index.d.ts +6 -12
- package/dist/lib/asciidoc/templates/engines/index.js +1 -21
- package/dist/lib/shiki/transformers/index.cjs +88 -79
- package/dist/lib/shiki/transformers/index.d.cts +23 -32
- package/dist/lib/shiki/transformers/index.d.ts +23 -32
- package/dist/lib/shiki/transformers/index.js +45 -4
- package/package.json +6 -5
- package/dist/chunk-DDIUST2Z.js +0 -113
package/dist/index.cjs
CHANGED
|
@@ -287,229 +287,6 @@ var AsciidocDocument = class {
|
|
|
287
287
|
}
|
|
288
288
|
};
|
|
289
289
|
|
|
290
|
-
// src/schemas/index.ts
|
|
291
|
-
var import_zod3 = require("zod");
|
|
292
|
-
|
|
293
|
-
// src/schemas/document.ts
|
|
294
|
-
var import_node_path = require("path");
|
|
295
|
-
var import_zod = require("zod");
|
|
296
|
-
var documentOptionsSchema = import_zod.z.looseObject({
|
|
297
|
-
mode: import_zod.z.union([import_zod.z.literal("safe"), import_zod.z.literal("unsafe")]).default("safe"),
|
|
298
|
-
template: import_zod.z.string().default("").transform((val) => (0, import_node_path.resolve)(process.cwd(), val)),
|
|
299
|
-
recursive: import_zod.z.boolean().default(false)
|
|
300
|
-
}).default({
|
|
301
|
-
mode: "safe",
|
|
302
|
-
template: "",
|
|
303
|
-
recursive: false
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
// src/schemas/shiki.ts
|
|
307
|
-
var import_zod2 = require("zod");
|
|
308
|
-
var shikiOptionsSchema = import_zod2.z.object({
|
|
309
|
-
theme: import_zod2.z.union([
|
|
310
|
-
import_zod2.z.string(),
|
|
311
|
-
import_zod2.z.object({
|
|
312
|
-
light: import_zod2.z.string(),
|
|
313
|
-
dark: import_zod2.z.string()
|
|
314
|
-
}).catchall(import_zod2.z.string())
|
|
315
|
-
]).transform(transformThemeProp).default({
|
|
316
|
-
light: "catppuccin-latte",
|
|
317
|
-
dark: "catppuccin-macchiato"
|
|
318
|
-
}),
|
|
319
|
-
defaultColor: import_zod2.z.string().default("light-dark()"),
|
|
320
|
-
cssVariablePrefix: import_zod2.z.string().default("--shiki-"),
|
|
321
|
-
mergeWhitespaces: import_zod2.z.union([import_zod2.z.boolean(), import_zod2.z.literal("never")]).default(true),
|
|
322
|
-
tabindex: import_zod2.z.union([import_zod2.z.number(), import_zod2.z.string(), import_zod2.z.literal(false)]).default(false)
|
|
323
|
-
}).transform(({ theme, ...rest }) => ({
|
|
324
|
-
themes: theme,
|
|
325
|
-
...rest
|
|
326
|
-
})).default({
|
|
327
|
-
mergeWhitespaces: true,
|
|
328
|
-
cssVariablePrefix: "--shiki-",
|
|
329
|
-
defaultColor: "light-dark()",
|
|
330
|
-
tabindex: false,
|
|
331
|
-
theme: {
|
|
332
|
-
light: "catppuccin-latte",
|
|
333
|
-
dark: "catppuccin-macchiato"
|
|
334
|
-
}
|
|
335
|
-
});
|
|
336
|
-
function transformThemeProp(value) {
|
|
337
|
-
return typeof value === "string" ? { light: value, dark: value } : value;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
// src/schemas/index.ts
|
|
341
|
-
var preambleOptionsSchema = import_zod3.z.object({
|
|
342
|
-
tableOfContents: import_zod3.z.boolean().default(true),
|
|
343
|
-
maxLevel: import_zod3.z.number().max(6).min(1).default(3),
|
|
344
|
-
position: import_zod3.z.union([import_zod3.z.literal("before"), import_zod3.z.literal("after")]).default("after")
|
|
345
|
-
}).default({
|
|
346
|
-
tableOfContents: true,
|
|
347
|
-
maxLevel: 3,
|
|
348
|
-
position: "after"
|
|
349
|
-
});
|
|
350
|
-
var loaderOptionsSchema = import_zod3.z.object({
|
|
351
|
-
base: import_zod3.z.string(),
|
|
352
|
-
document: documentOptionsSchema,
|
|
353
|
-
syntaxHighlighting: shikiOptionsSchema,
|
|
354
|
-
preamble: preambleOptionsSchema
|
|
355
|
-
});
|
|
356
|
-
|
|
357
|
-
// src/lib/shiki/Highlighter.ts
|
|
358
|
-
var import_shiki2 = require("shiki");
|
|
359
|
-
async function createHighlighter(documents, themes) {
|
|
360
|
-
const langs = documents.reduce((acc, cur) => {
|
|
361
|
-
cur.languages.forEach((lang) => {
|
|
362
|
-
acc.add(lang);
|
|
363
|
-
});
|
|
364
|
-
return acc;
|
|
365
|
-
}, /* @__PURE__ */ new Set());
|
|
366
|
-
const highlighter = await (0, import_shiki2.createHighlighterCore)({
|
|
367
|
-
themes: Object.values(themes).map((theme) => {
|
|
368
|
-
return import(`@shikijs/themes/${theme}`);
|
|
369
|
-
}),
|
|
370
|
-
langs: Array.from(langs).map((lang) => {
|
|
371
|
-
return import(`@shikijs/langs/${lang}`);
|
|
372
|
-
}),
|
|
373
|
-
engine: (0, import_shiki2.createJavaScriptRegexEngine)()
|
|
374
|
-
});
|
|
375
|
-
return Object.freeze(highlighter);
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
// src/lib/asciidoc/converters/sourceCodeConverter.ts
|
|
379
|
-
var import_transformers = require("@shikijs/transformers");
|
|
380
|
-
var import_node_path2 = require("path");
|
|
381
|
-
|
|
382
|
-
// src/lib/shiki/transformers/transformAsciidocCallout.ts
|
|
383
|
-
function transformAsciidocCallout({
|
|
384
|
-
node,
|
|
385
|
-
cssClasses = "pointer-events-none select-none ml-2"
|
|
386
|
-
}) {
|
|
387
|
-
const lineComments = ["//", "#", ";;"];
|
|
388
|
-
const customLineComment = node.getAttribute("line-comment");
|
|
389
|
-
if (customLineComment) {
|
|
390
|
-
lineComments.push(escapeRegexCharacters(customLineComment));
|
|
391
|
-
}
|
|
392
|
-
const calloutReList = [
|
|
393
|
-
// Handles C-style and similar comments like Perl, Python...
|
|
394
|
-
new RegExp(`(?:${lineComments.join("|")})((?:\\s+<(\\d+)>)+)`),
|
|
395
|
-
// Handles XML comments
|
|
396
|
-
new RegExp(/((?:\s*<!--(\d+)-->)+)/)
|
|
397
|
-
];
|
|
398
|
-
const linesWithCallout = {};
|
|
399
|
-
return {
|
|
400
|
-
preprocess(code) {
|
|
401
|
-
return code.split("\n").map((line, idx) => {
|
|
402
|
-
for (const re of calloutReList) {
|
|
403
|
-
const match = line.match(re);
|
|
404
|
-
if (!match) continue;
|
|
405
|
-
const callouts = match[0].trim().replaceAll(/(?:<!--|-->|[<>])/g, "").split(" ");
|
|
406
|
-
linesWithCallout[idx + 1] = callouts;
|
|
407
|
-
return line.replace(re, "");
|
|
408
|
-
}
|
|
409
|
-
return line;
|
|
410
|
-
}).join("\n");
|
|
411
|
-
},
|
|
412
|
-
line(hast, line) {
|
|
413
|
-
const callouts = linesWithCallout[line];
|
|
414
|
-
if (!callouts) return;
|
|
415
|
-
callouts.forEach((calloutId) => {
|
|
416
|
-
hast.properties[`data-callout-${calloutId}`] = "";
|
|
417
|
-
hast.children.push({
|
|
418
|
-
type: "element",
|
|
419
|
-
tagName: "i",
|
|
420
|
-
properties: {
|
|
421
|
-
class: `conum ${cssClasses}`,
|
|
422
|
-
"data-value": calloutId
|
|
423
|
-
},
|
|
424
|
-
children: [
|
|
425
|
-
{
|
|
426
|
-
type: "element",
|
|
427
|
-
tagName: "b",
|
|
428
|
-
properties: {},
|
|
429
|
-
children: [
|
|
430
|
-
{
|
|
431
|
-
type: "text",
|
|
432
|
-
value: calloutId
|
|
433
|
-
}
|
|
434
|
-
]
|
|
435
|
-
}
|
|
436
|
-
]
|
|
437
|
-
});
|
|
438
|
-
});
|
|
439
|
-
}
|
|
440
|
-
};
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
// src/lib/shiki/transformers/transformConsoleCodeBlock.ts
|
|
444
|
-
function transformConsoleCodeBlock(options = {
|
|
445
|
-
cssClasses: "pointer-events-none select-none mr-2 opacity-50"
|
|
446
|
-
}) {
|
|
447
|
-
const unselectablePrompt = `<span $1 class="${options.cssClasses}">$</span>`;
|
|
448
|
-
const linePrefix = '<span class="line[^>]+?>';
|
|
449
|
-
const splitPrompt = new RegExp(
|
|
450
|
-
`(?<=${linePrefix})(?:<span (style="[^"]*?")>\\s*?\\$\\s+?([^<]))`
|
|
451
|
-
);
|
|
452
|
-
const trimWhitespace = new RegExp(
|
|
453
|
-
`(?<=${linePrefix})(?:<span (style="[^"]*?")>\\s*?\\$\\s*?<\\/span>(?:<span>\\s+<\\/span>)?)`
|
|
454
|
-
);
|
|
455
|
-
const trimWhitespaceAhead = new RegExp(
|
|
456
|
-
`(?<=${linePrefix}<span [^>]+?>\\$<\\/span>)(<span style="[^"]+?">)\\s+?`
|
|
457
|
-
);
|
|
458
|
-
return {
|
|
459
|
-
postprocess: (html, { lang }) => {
|
|
460
|
-
if (lang === "console") {
|
|
461
|
-
return html.split("\n").map((line) => {
|
|
462
|
-
return line.replace(
|
|
463
|
-
splitPrompt,
|
|
464
|
-
unselectablePrompt + "<span $1>$2"
|
|
465
|
-
).replace(trimWhitespace, unselectablePrompt).replace(trimWhitespaceAhead, "$1");
|
|
466
|
-
}).join("\n");
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
};
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
// src/lib/asciidoc/converters/sourceCodeConverter.ts
|
|
473
|
-
var sourceCodeConverter = ({ nodeContext, transformers, template }) => {
|
|
474
|
-
return (options, highlighter) => {
|
|
475
|
-
return {
|
|
476
|
-
nodeContext: nodeContext ?? "listing",
|
|
477
|
-
convert(node, templateEngine) {
|
|
478
|
-
const input = node.getSourceLines().join("\n");
|
|
479
|
-
const lang = node.getAttribute("language");
|
|
480
|
-
const output = highlighter.codeToHtml(input, {
|
|
481
|
-
...options.syntaxHighlighting,
|
|
482
|
-
lang,
|
|
483
|
-
transformers: [
|
|
484
|
-
...transformers ?? [],
|
|
485
|
-
(0, import_transformers.transformerNotationDiff)(),
|
|
486
|
-
(0, import_transformers.transformerNotationHighlight)(),
|
|
487
|
-
(0, import_transformers.transformerNotationFocus)(),
|
|
488
|
-
transformAsciidocCallout({ node }),
|
|
489
|
-
transformConsoleCodeBlock()
|
|
490
|
-
]
|
|
491
|
-
});
|
|
492
|
-
if (templateEngine && template) {
|
|
493
|
-
const { extension } = splitFilenameComponents(template);
|
|
494
|
-
const engine = templateEngine.getEngineByExtension(
|
|
495
|
-
extension || ""
|
|
496
|
-
);
|
|
497
|
-
if (engine) {
|
|
498
|
-
const templateFile = (0, import_node_path2.resolve)(process.cwd(), template);
|
|
499
|
-
if (engine.canRenderFile) {
|
|
500
|
-
return engine.renderFile(templateFile, {
|
|
501
|
-
content: output,
|
|
502
|
-
lang
|
|
503
|
-
});
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
return output;
|
|
508
|
-
}
|
|
509
|
-
};
|
|
510
|
-
};
|
|
511
|
-
};
|
|
512
|
-
|
|
513
290
|
// src/lib/asciidoc/templates/engines/Handlebars.ts
|
|
514
291
|
var import_node_fs2 = require("fs");
|
|
515
292
|
|
|
@@ -639,69 +416,315 @@ var NunjucksEngine = class extends AbstractEngine {
|
|
|
639
416
|
}
|
|
640
417
|
};
|
|
641
418
|
|
|
642
|
-
// src/
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
419
|
+
// src/schemas/index.ts
|
|
420
|
+
var import_zod3 = require("astro/zod");
|
|
421
|
+
|
|
422
|
+
// src/schemas/document.ts
|
|
423
|
+
var import_node_path = require("path");
|
|
424
|
+
var import_zod = require("astro/zod");
|
|
425
|
+
var documentOptionsSchema = import_zod.z.object({
|
|
426
|
+
mode: import_zod.z.union([import_zod.z.literal("safe"), import_zod.z.literal("unsafe")]).default("safe"),
|
|
427
|
+
template: import_zod.z.string().default("").transform((val) => val ? (0, import_node_path.resolve)(process.cwd(), val) : ""),
|
|
428
|
+
recursive: import_zod.z.boolean().default(false)
|
|
429
|
+
}).passthrough().default({
|
|
430
|
+
mode: "safe",
|
|
431
|
+
template: "",
|
|
432
|
+
recursive: false
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
// src/schemas/shiki.ts
|
|
436
|
+
var import_zod2 = require("astro/zod");
|
|
437
|
+
var shikiOptionsSchema = import_zod2.z.object({
|
|
438
|
+
theme: import_zod2.z.union([
|
|
439
|
+
import_zod2.z.string(),
|
|
440
|
+
import_zod2.z.object({
|
|
441
|
+
light: import_zod2.z.string(),
|
|
442
|
+
dark: import_zod2.z.string()
|
|
443
|
+
}).catchall(import_zod2.z.string())
|
|
444
|
+
]).transform(transformThemeProp).default({
|
|
445
|
+
light: "catppuccin-latte",
|
|
446
|
+
dark: "catppuccin-macchiato"
|
|
447
|
+
}),
|
|
448
|
+
defaultColor: import_zod2.z.string().default("light-dark()"),
|
|
449
|
+
cssVariablePrefix: import_zod2.z.string().default("--shiki-"),
|
|
450
|
+
mergeWhitespaces: import_zod2.z.union([import_zod2.z.boolean(), import_zod2.z.literal("never")]).default(true),
|
|
451
|
+
tabindex: import_zod2.z.union([import_zod2.z.number(), import_zod2.z.string(), import_zod2.z.literal(false)]).default(false),
|
|
452
|
+
// transformers: z
|
|
453
|
+
// .array(
|
|
454
|
+
// z.object({
|
|
455
|
+
// name: z.string(),
|
|
456
|
+
// enforce: z.union([z.literal('pre'), z.literal('post')]),
|
|
457
|
+
// }),
|
|
458
|
+
// )
|
|
459
|
+
// .optional(),
|
|
460
|
+
callouts: import_zod2.z.object({
|
|
461
|
+
cssClasses: import_zod2.z.string().optional()
|
|
462
|
+
}).optional()
|
|
463
|
+
}).passthrough().transform(({ theme, ...rest }) => ({
|
|
464
|
+
themes: theme,
|
|
465
|
+
...rest
|
|
466
|
+
})).default({
|
|
467
|
+
mergeWhitespaces: true,
|
|
468
|
+
cssVariablePrefix: "--shiki-",
|
|
469
|
+
defaultColor: "light-dark()",
|
|
470
|
+
tabindex: false,
|
|
471
|
+
theme: {
|
|
472
|
+
light: "catppuccin-latte",
|
|
473
|
+
dark: "catppuccin-macchiato"
|
|
474
|
+
},
|
|
475
|
+
// transformers: undefined,
|
|
476
|
+
callouts: void 0
|
|
477
|
+
});
|
|
478
|
+
function transformThemeProp(value) {
|
|
479
|
+
return typeof value === "string" ? { light: value, dark: value } : value;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// src/schemas/index.ts
|
|
483
|
+
var preambleOptionsSchema = import_zod3.z.object({
|
|
484
|
+
tableOfContents: import_zod3.z.boolean().default(true),
|
|
485
|
+
maxLevel: import_zod3.z.number().max(6).min(1).default(3),
|
|
486
|
+
position: import_zod3.z.union([import_zod3.z.literal("before"), import_zod3.z.literal("after")]).default("after")
|
|
487
|
+
}).default({
|
|
488
|
+
tableOfContents: true,
|
|
489
|
+
maxLevel: 3,
|
|
490
|
+
position: "after"
|
|
491
|
+
});
|
|
492
|
+
var loaderOptionsSchema = import_zod3.z.object({
|
|
493
|
+
base: import_zod3.z.string(),
|
|
494
|
+
document: documentOptionsSchema,
|
|
495
|
+
syntaxHighlighting: shikiOptionsSchema,
|
|
496
|
+
preamble: preambleOptionsSchema
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
// src/lib/shiki/Highlighter.ts
|
|
500
|
+
var import_shiki2 = require("shiki");
|
|
501
|
+
async function createHighlighter(documents, themes) {
|
|
502
|
+
const langs = documents.reduce((acc, cur) => {
|
|
503
|
+
cur.languages.forEach((lang) => {
|
|
504
|
+
acc.add(lang);
|
|
505
|
+
});
|
|
506
|
+
return acc;
|
|
507
|
+
}, /* @__PURE__ */ new Set());
|
|
508
|
+
const highlighter = await (0, import_shiki2.createHighlighterCore)({
|
|
509
|
+
themes: Object.values(themes).map((theme) => {
|
|
510
|
+
return import(`@shikijs/themes/${theme}`);
|
|
511
|
+
}),
|
|
512
|
+
langs: Array.from(langs).map((lang) => {
|
|
513
|
+
return import(`@shikijs/langs/${lang}`);
|
|
514
|
+
}),
|
|
515
|
+
engine: (0, import_shiki2.createJavaScriptRegexEngine)()
|
|
516
|
+
});
|
|
517
|
+
return Object.freeze(highlighter);
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
// src/lib/asciidoc/converters/sourceCodeConverter.ts
|
|
521
|
+
var import_node_path2 = require("path");
|
|
522
|
+
var sourceCodeConverter = ({ transformers, template }) => {
|
|
523
|
+
return (options, highlighter) => {
|
|
524
|
+
return {
|
|
525
|
+
nodeContext: "listing",
|
|
526
|
+
nodeStyle: "source",
|
|
527
|
+
convert(node, templateEngine) {
|
|
528
|
+
const input = node.getSourceLines().join("\n");
|
|
529
|
+
const lang = node.getAttribute("language");
|
|
530
|
+
const output = highlighter.codeToHtml(input, {
|
|
531
|
+
...options.syntaxHighlighting,
|
|
532
|
+
lang,
|
|
533
|
+
transformers: (transformers ?? []).map((transformer) => {
|
|
534
|
+
return typeof transformer === "function" ? transformer(node) : transformer;
|
|
535
|
+
})
|
|
536
|
+
});
|
|
537
|
+
if (templateEngine && template) {
|
|
538
|
+
const { extension } = splitFilenameComponents(template);
|
|
539
|
+
const engine = templateEngine.getEngineByExtension(
|
|
540
|
+
extension || ""
|
|
541
|
+
);
|
|
542
|
+
if (engine) {
|
|
543
|
+
const templateFile = (0, import_node_path2.resolve)(process.cwd(), template);
|
|
544
|
+
if (engine.canRenderFile) {
|
|
545
|
+
return engine.renderFile(templateFile, {
|
|
546
|
+
content: output,
|
|
547
|
+
lang
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
return output;
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
};
|
|
556
|
+
};
|
|
557
|
+
|
|
558
|
+
// src/lib/shiki/transformers/transformAsciidocCallout.ts
|
|
559
|
+
var transformAsciidocCallout = (options) => {
|
|
560
|
+
return (node) => {
|
|
561
|
+
const lineComments = ["//", "#", ";;"];
|
|
562
|
+
const customLineComment = node.getAttribute("line-comment");
|
|
563
|
+
if (customLineComment) {
|
|
564
|
+
lineComments.push(escapeRegexCharacters(customLineComment));
|
|
565
|
+
}
|
|
566
|
+
const calloutReList = [
|
|
567
|
+
// Handles C-style and similar comments like Perl, Python...
|
|
568
|
+
new RegExp(`\\s+(?:${lineComments.join("|")})((?:\\s+<(\\d+)>)+)`),
|
|
569
|
+
// Handles XML comments
|
|
570
|
+
new RegExp(/((?:\s*<!--(\d+)-->)+)/)
|
|
648
571
|
];
|
|
572
|
+
const commentTokensRe = new RegExp(
|
|
573
|
+
`(?:${lineComments.join("|")}|<!--|-->|[<>])`,
|
|
574
|
+
"g"
|
|
575
|
+
);
|
|
576
|
+
const linesWithCallout = {};
|
|
577
|
+
return {
|
|
578
|
+
preprocess(code) {
|
|
579
|
+
return code.split("\n").map((line, idx) => {
|
|
580
|
+
for (const re of calloutReList) {
|
|
581
|
+
const match = line.match(re);
|
|
582
|
+
if (!match) continue;
|
|
583
|
+
const callouts = match[0].replaceAll(commentTokensRe, "").trim().split(" ");
|
|
584
|
+
linesWithCallout[idx + 1] = callouts;
|
|
585
|
+
return line.replace(re, "");
|
|
586
|
+
}
|
|
587
|
+
return line;
|
|
588
|
+
}).join("\n");
|
|
589
|
+
},
|
|
590
|
+
line(hast, line) {
|
|
591
|
+
const callouts = linesWithCallout[line];
|
|
592
|
+
if (!callouts) return;
|
|
593
|
+
callouts.forEach((calloutId) => {
|
|
594
|
+
hast.properties[`data-callout-${calloutId}`] = "";
|
|
595
|
+
hast.children.push({
|
|
596
|
+
type: "element",
|
|
597
|
+
tagName: "span",
|
|
598
|
+
properties: {
|
|
599
|
+
class: options?.cssClasses ?? "conum",
|
|
600
|
+
style: options?.cssClasses ? "" : "user-select:none; pointer-events:none; opacity:0.5; margin-inline:8px;",
|
|
601
|
+
"data-value": calloutId
|
|
602
|
+
},
|
|
603
|
+
children: [
|
|
604
|
+
{
|
|
605
|
+
type: "text",
|
|
606
|
+
value: calloutId
|
|
607
|
+
}
|
|
608
|
+
]
|
|
609
|
+
});
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
};
|
|
614
|
+
};
|
|
615
|
+
|
|
616
|
+
// src/loader.ts
|
|
617
|
+
function asciidocLoader(_options) {
|
|
618
|
+
const options = loaderOptionsSchema.parse(_options);
|
|
619
|
+
if (options.document.converters === void 0) {
|
|
620
|
+
options.document.converters = [];
|
|
649
621
|
}
|
|
650
|
-
if (
|
|
651
|
-
|
|
622
|
+
if (options.document.templateEngines === void 0) {
|
|
623
|
+
options.document.templateEngines = [
|
|
652
624
|
new HandlebarsEngine(),
|
|
653
625
|
new NunjucksEngine()
|
|
654
626
|
];
|
|
655
627
|
}
|
|
628
|
+
let highlighter;
|
|
629
|
+
let templateEngine;
|
|
656
630
|
return {
|
|
657
631
|
name: "asciidoc-loader",
|
|
658
|
-
async load(
|
|
632
|
+
async load(loaderContext) {
|
|
633
|
+
const { config, logger, watcher } = loaderContext;
|
|
659
634
|
const root = config.root.pathname;
|
|
660
|
-
const base =
|
|
635
|
+
const base = options.base.startsWith(".") ? (0, import_node_fs4.realpathSync)(options.base) : root + options.base;
|
|
661
636
|
const docs = (0, import_node_fs4.readdirSync)(base, "utf8").filter((file) => file.match(/(?:\.a(?:scii)?doc)$/)).map((filename) => new AsciidocDocument(`${base}/${filename}`));
|
|
662
637
|
if (docs.length === 0) {
|
|
663
638
|
logger.warn("No documents found for this collection.");
|
|
664
639
|
return;
|
|
665
640
|
}
|
|
666
|
-
|
|
667
|
-
if (parsedOpts.document.template) {
|
|
641
|
+
if (options.document.template) {
|
|
668
642
|
templateEngine = new TemplateEngineRegistry(
|
|
669
|
-
|
|
643
|
+
options.document.templateEngines,
|
|
670
644
|
{
|
|
671
|
-
rootDir:
|
|
672
|
-
recursive:
|
|
645
|
+
rootDir: options.document.template,
|
|
646
|
+
recursive: options.document.recursive
|
|
673
647
|
}
|
|
674
648
|
);
|
|
675
649
|
await templateEngine.loadEngines();
|
|
676
650
|
}
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
651
|
+
if (!highlighter) {
|
|
652
|
+
highlighter = await createHighlighter(
|
|
653
|
+
docs,
|
|
654
|
+
options.syntaxHighlighting.themes
|
|
655
|
+
);
|
|
656
|
+
}
|
|
657
|
+
const converters = options.document.converters.map(
|
|
658
|
+
(converter) => converter(options, highlighter)
|
|
680
659
|
);
|
|
681
|
-
const
|
|
682
|
-
(converter) => converter
|
|
660
|
+
const hasSourceCodeConverter = converters.find(
|
|
661
|
+
(converter) => converter.nodeContext === "listing" && converter?.nodeStyle === "source"
|
|
683
662
|
);
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
663
|
+
if (!hasSourceCodeConverter) {
|
|
664
|
+
converters.push(
|
|
665
|
+
sourceCodeConverter({
|
|
666
|
+
transformers: [
|
|
667
|
+
...options.syntaxHighlighting.transformers ?? [],
|
|
668
|
+
transformAsciidocCallout(
|
|
669
|
+
options.syntaxHighlighting.callouts
|
|
670
|
+
)
|
|
671
|
+
]
|
|
672
|
+
})(options, highlighter)
|
|
673
|
+
);
|
|
674
|
+
}
|
|
675
|
+
await Promise.all(
|
|
676
|
+
docs.map(
|
|
677
|
+
(doc) => setDocument(doc, converters, templateEngine, loaderContext)
|
|
678
|
+
)
|
|
679
|
+
);
|
|
680
|
+
if (watcher) {
|
|
681
|
+
let handle2 = function() {
|
|
682
|
+
logger.info("Shutting down highlighter instance");
|
|
683
|
+
highlighter.dispose();
|
|
684
|
+
process.exit(0);
|
|
685
|
+
};
|
|
686
|
+
var handle = handle2;
|
|
687
|
+
const watchedFileRegExp = new RegExp(
|
|
688
|
+
`^${base}.*.(a(?:scii)?doc)$`
|
|
689
|
+
);
|
|
690
|
+
watcher.on("change", async (changedPath) => {
|
|
691
|
+
if (changedPath.match(watchedFileRegExp)) {
|
|
692
|
+
const newDoc = new AsciidocDocument(changedPath);
|
|
693
|
+
await setDocument(
|
|
694
|
+
newDoc,
|
|
695
|
+
converters,
|
|
696
|
+
templateEngine,
|
|
697
|
+
loaderContext
|
|
698
|
+
);
|
|
698
699
|
}
|
|
699
700
|
});
|
|
700
|
-
|
|
701
|
-
|
|
701
|
+
if (highlighter) {
|
|
702
|
+
process.on("SIGINT", handle2);
|
|
703
|
+
process.on("SIGTERM", handle2);
|
|
704
|
+
}
|
|
705
|
+
} else {
|
|
706
|
+
(0, import_node_process.nextTick)(highlighter.dispose);
|
|
707
|
+
}
|
|
702
708
|
}
|
|
703
709
|
};
|
|
704
710
|
}
|
|
711
|
+
async function setDocument(doc, converters, templateEngine, { parseData, store }) {
|
|
712
|
+
const data = await parseData({
|
|
713
|
+
id: doc.slug,
|
|
714
|
+
data: {
|
|
715
|
+
title: doc.title,
|
|
716
|
+
createdAt: new Date(doc.createdAt),
|
|
717
|
+
description: doc.preamble
|
|
718
|
+
}
|
|
719
|
+
});
|
|
720
|
+
store.set({
|
|
721
|
+
id: doc.slug,
|
|
722
|
+
data,
|
|
723
|
+
rendered: {
|
|
724
|
+
html: doc.convert(converters, templateEngine)
|
|
725
|
+
}
|
|
726
|
+
});
|
|
727
|
+
}
|
|
705
728
|
// Annotate the CommonJS export names for ESM import in node:
|
|
706
729
|
0 && (module.exports = {
|
|
707
730
|
asciidocLoader
|
package/dist/index.d.cts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { LoaderContext } from 'astro/loaders';
|
|
2
|
-
import { A as AsciidocLoader } from './index-
|
|
3
|
-
export { a as AsciidocTemplate, C as CustomConverterFactoryFn, F as FilesystemTemplate, N as NodeContext, R as RawTemplate } from './index-
|
|
2
|
+
import { A as AsciidocLoader } from './index-sFlXF8Qm.cjs';
|
|
3
|
+
export { a as AsciidocTemplate, C as CustomConverterFactoryFn, F as FilesystemTemplate, N as NodeContext, R as RawTemplate } from './index-sFlXF8Qm.cjs';
|
|
4
4
|
import 'shiki';
|
|
5
5
|
import 'asciidoctor';
|
|
6
|
-
import 'zod';
|
|
6
|
+
import 'astro/zod';
|
|
7
7
|
|
|
8
|
-
declare function asciidocLoader(
|
|
8
|
+
declare function asciidocLoader(_options: AsciidocLoader): {
|
|
9
9
|
name: string;
|
|
10
|
-
load(
|
|
10
|
+
load(loaderContext: LoaderContext): Promise<void>;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
export { asciidocLoader };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { LoaderContext } from 'astro/loaders';
|
|
2
|
-
import { A as AsciidocLoader } from './index-
|
|
3
|
-
export { a as AsciidocTemplate, C as CustomConverterFactoryFn, F as FilesystemTemplate, N as NodeContext, R as RawTemplate } from './index-
|
|
2
|
+
import { A as AsciidocLoader } from './index-sFlXF8Qm.js';
|
|
3
|
+
export { a as AsciidocTemplate, C as CustomConverterFactoryFn, F as FilesystemTemplate, N as NodeContext, R as RawTemplate } from './index-sFlXF8Qm.js';
|
|
4
4
|
import 'shiki';
|
|
5
5
|
import 'asciidoctor';
|
|
6
|
-
import 'zod';
|
|
6
|
+
import 'astro/zod';
|
|
7
7
|
|
|
8
|
-
declare function asciidocLoader(
|
|
8
|
+
declare function asciidocLoader(_options: AsciidocLoader): {
|
|
9
9
|
name: string;
|
|
10
|
-
load(
|
|
10
|
+
load(loaderContext: LoaderContext): Promise<void>;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
export { asciidocLoader };
|