@d10f/asciidoc-astro-loader 0.0.9 → 0.0.11
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 +51 -6
- package/dist/{chunk-IWQC3MJM.js → chunk-KPEWXJBE.js} +12 -2
- package/dist/{chunk-NC6IZHLR.js → chunk-SUQERYPQ.js} +12 -11
- package/dist/{index-DwboxIUQ.d.cts → index-C1F2jTPD.d.cts} +6 -2
- package/dist/{index-DwboxIUQ.d.ts → index-C1F2jTPD.d.ts} +6 -2
- package/dist/index.cjs +49 -26
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +27 -15
- package/dist/lib/asciidoc/converters/index.cjs +12 -11
- package/dist/lib/asciidoc/converters/index.d.cts +1 -1
- package/dist/lib/asciidoc/converters/index.d.ts +1 -1
- package/dist/lib/asciidoc/converters/index.js +1 -1
- 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 +12 -2
- package/dist/lib/shiki/transformers/index.d.cts +1 -1
- package/dist/lib/shiki/transformers/index.d.ts +1 -1
- package/dist/lib/shiki/transformers/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -35,10 +35,9 @@ const blog = defineCollection({
|
|
|
35
35
|
base: ".src/content/blog",
|
|
36
36
|
}),
|
|
37
37
|
schema: z.object({
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
updatedAt: z.coerce.date().optional(),
|
|
38
|
+
doctitle: z.string(),
|
|
39
|
+
description: z.string(),
|
|
40
|
+
revdate: z.coerce.date(),
|
|
42
41
|
}),
|
|
43
42
|
});
|
|
44
43
|
```
|
|
@@ -317,7 +316,12 @@ A custom converter is declared as a factory function that accepts a configuratio
|
|
|
317
316
|
```ts
|
|
318
317
|
import type { CustomConverterFactoryFn, NodeContext } from '@d10f/asciidoc-astro-loader';
|
|
319
318
|
|
|
320
|
-
|
|
319
|
+
type MyConverterOpts = {
|
|
320
|
+
name?: string;
|
|
321
|
+
description?: string;
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
export const myCustomConverter: CustomConverterFactoryFn<MyConverterOpts> = ({ name, description }) => {
|
|
321
325
|
return (options, highlighter) => {
|
|
322
326
|
return {
|
|
323
327
|
|
|
@@ -325,7 +329,7 @@ export const myCustomConverter: CustomConverterFactoryFn = ({ nodeContext }) =>
|
|
|
325
329
|
* The type of node that this converter will act upon. It
|
|
326
330
|
* can either be hard-coded here, or passed as an option.
|
|
327
331
|
*/
|
|
328
|
-
nodeContext,
|
|
332
|
+
nodeContext: 'admonition',
|
|
329
333
|
|
|
330
334
|
/**
|
|
331
335
|
* The convert function that will produce the HTML output.
|
|
@@ -343,3 +347,44 @@ export const myCustomConverter: CustomConverterFactoryFn = ({ nodeContext }) =>
|
|
|
343
347
|
```
|
|
344
348
|
|
|
345
349
|
In addition, the `convert` method receives the node that is being processed, as well as an instance of the template engine registry. You can use this to render the HTML from a template as well, combining both to get the best of both worlds.
|
|
350
|
+
|
|
351
|
+
Using a converter might make more sense if you need to keep some state as the document is being processed. With templates, each invocation is a brand-new state for each block. A converter encapsulates variables declared within it and this can be used to do things like count how many blocks of a given type there are in the whole document. A more practical example might be if you need to position (through CSS styles) an element left or right based on whether it's even or odd. This can be tricky to do with CSS alone because the `:nth-child()` selector accounts only for elements under the same parent, and not the whole document.
|
|
352
|
+
|
|
353
|
+
## Example
|
|
354
|
+
|
|
355
|
+
This is an example taken from my own website to showcase how to use it in a real world setting. This configuration uses a custom converter, a custom Shiki transformer and points to a folder where custom templates are found:
|
|
356
|
+
|
|
357
|
+
```ts
|
|
358
|
+
const blog = defineCollection({
|
|
359
|
+
loader: asciidocLoader({
|
|
360
|
+
base: 'src/content/blog',
|
|
361
|
+
document: {
|
|
362
|
+
template: './src/templates',
|
|
363
|
+
converters: [admonitionConverter()],
|
|
364
|
+
},
|
|
365
|
+
syntaxHighlighting: {
|
|
366
|
+
theme: 'catppuccin-frappe',
|
|
367
|
+
transformers: [
|
|
368
|
+
transformerNotationDiff(),
|
|
369
|
+
transformerNotationErrorLevel(),
|
|
370
|
+
transformerNotationFocus(),
|
|
371
|
+
transformerNotationHighlight(),
|
|
372
|
+
transformerPrompt({
|
|
373
|
+
langs: {
|
|
374
|
+
console: '$',
|
|
375
|
+
},
|
|
376
|
+
cssClasses: 'unselectable mr-2 opacity-50',
|
|
377
|
+
}),
|
|
378
|
+
],
|
|
379
|
+
callouts: {
|
|
380
|
+
cssClasses: 'conum unselectable',
|
|
381
|
+
},
|
|
382
|
+
},
|
|
383
|
+
}),
|
|
384
|
+
schema: z.object({
|
|
385
|
+
doctitle: z.string(),
|
|
386
|
+
description: z.string(),
|
|
387
|
+
revdate: z.coerce.date(),
|
|
388
|
+
}),
|
|
389
|
+
});
|
|
390
|
+
```
|
|
@@ -5,14 +5,14 @@ import {
|
|
|
5
5
|
// src/lib/shiki/transformers/transformAsciidocCallout.ts
|
|
6
6
|
var transformAsciidocCallout = (options) => {
|
|
7
7
|
return (node) => {
|
|
8
|
-
const lineComments = ["//", "#", ";;"];
|
|
8
|
+
const lineComments = ["//", "#", ";;", "%"];
|
|
9
9
|
const customLineComment = node.getAttribute("line-comment");
|
|
10
10
|
if (customLineComment) {
|
|
11
11
|
lineComments.push(escapeRegexCharacters(customLineComment));
|
|
12
12
|
}
|
|
13
13
|
const calloutReList = [
|
|
14
14
|
// Handles C-style and similar comments like Perl, Python...
|
|
15
|
-
new RegExp(`\\s
|
|
15
|
+
new RegExp(`\\s*(?:${lineComments.join("|")})((?:\\s+<(\\d+)>)+)`),
|
|
16
16
|
// Handles XML comments
|
|
17
17
|
new RegExp(/((?:\s*<!--(\d+)-->)+)/)
|
|
18
18
|
];
|
|
@@ -72,9 +72,19 @@ var transformerPrompt = (options) => {
|
|
|
72
72
|
if (customPrompt && options?.langs && typeof options.langs[language] === "object") {
|
|
73
73
|
cssClasses = options.langs[language].cssClasses;
|
|
74
74
|
}
|
|
75
|
+
let skipNext = false;
|
|
75
76
|
return {
|
|
77
|
+
enforce: "pre",
|
|
76
78
|
line(hast) {
|
|
77
79
|
if (!promptToAdd) return;
|
|
80
|
+
const skipCurrent = skipNext;
|
|
81
|
+
skipNext = false;
|
|
82
|
+
const lastChild = hast.children.at(-1);
|
|
83
|
+
if (lastChild && // @ts-expect-error property "children" does exist
|
|
84
|
+
lastChild.children[0].value.match(/\s+\\(?:\\)?\s*$/)) {
|
|
85
|
+
skipNext = true;
|
|
86
|
+
}
|
|
87
|
+
if (skipCurrent) return;
|
|
78
88
|
hast.children.unshift({
|
|
79
89
|
type: "element",
|
|
80
90
|
tagName: "span",
|
|
@@ -21,19 +21,20 @@ var sourceCodeConverter = (converterOptions) => {
|
|
|
21
21
|
return typeof transformer === "function" ? transformer(node) : transformer;
|
|
22
22
|
})
|
|
23
23
|
});
|
|
24
|
-
if (templateEngine
|
|
25
|
-
const { extension } = splitFilenameComponents(
|
|
26
|
-
|
|
27
|
-
extension || ""
|
|
24
|
+
if (templateEngine) {
|
|
25
|
+
const { extension } = splitFilenameComponents(
|
|
26
|
+
template ?? ""
|
|
28
27
|
);
|
|
29
|
-
|
|
28
|
+
const engine = extension ? templateEngine.getEngineByExtension(extension ?? "") : templateEngine.getEngineByContext(this.nodeContext);
|
|
29
|
+
if (template) {
|
|
30
30
|
const templateFile = resolve(process.cwd(), template);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
engine?.addContext(this.nodeContext, templateFile);
|
|
32
|
+
}
|
|
33
|
+
if (engine) {
|
|
34
|
+
return engine.renderNode(node, {
|
|
35
|
+
content: output,
|
|
36
|
+
lang
|
|
37
|
+
});
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
40
|
return output;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HighlighterCore, CodeToHastOptions, CodeOptionsMultipleThemes,
|
|
1
|
+
import { HighlighterCore, CodeToHastOptions, CodeOptionsMultipleThemes, StringLiteralUnion, BundledTheme, ShikiTransformer } from 'shiki';
|
|
2
2
|
import { AbstractNode, AbstractBlock } from 'asciidoctor';
|
|
3
3
|
import { z } from 'astro/zod';
|
|
4
4
|
|
|
@@ -317,6 +317,10 @@ declare class TemplateEngineRegistry {
|
|
|
317
317
|
* Returns the module that supports the given extension.
|
|
318
318
|
*/
|
|
319
319
|
getEngineByExtension(ext: string): (AbstractEngine & AsciidocTemplate) | undefined;
|
|
320
|
+
/**
|
|
321
|
+
* Returns the first module that supports the given context.
|
|
322
|
+
*/
|
|
323
|
+
getEngineByContext(context: NodeContext): (AbstractEngine & AsciidocTemplate) | undefined;
|
|
320
324
|
/**
|
|
321
325
|
* Converts the provided node using one of the registered template
|
|
322
326
|
* engine modules. For more granular control, gain access to the
|
|
@@ -470,7 +474,7 @@ type AsciidocLoader = {
|
|
|
470
474
|
*
|
|
471
475
|
* @default 'light-dark()'
|
|
472
476
|
*/
|
|
473
|
-
defaultColor
|
|
477
|
+
defaultColor?: StringLiteralUnion<'light' | 'dark'> | 'light-dark()' | false;
|
|
474
478
|
/**
|
|
475
479
|
* The syntax highlighter theme to use. It can be either a
|
|
476
480
|
* string that will apply for both light and dark mode by
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HighlighterCore, CodeToHastOptions, CodeOptionsMultipleThemes,
|
|
1
|
+
import { HighlighterCore, CodeToHastOptions, CodeOptionsMultipleThemes, StringLiteralUnion, BundledTheme, ShikiTransformer } from 'shiki';
|
|
2
2
|
import { AbstractNode, AbstractBlock } from 'asciidoctor';
|
|
3
3
|
import { z } from 'astro/zod';
|
|
4
4
|
|
|
@@ -317,6 +317,10 @@ declare class TemplateEngineRegistry {
|
|
|
317
317
|
* Returns the module that supports the given extension.
|
|
318
318
|
*/
|
|
319
319
|
getEngineByExtension(ext: string): (AbstractEngine & AsciidocTemplate) | undefined;
|
|
320
|
+
/**
|
|
321
|
+
* Returns the first module that supports the given context.
|
|
322
|
+
*/
|
|
323
|
+
getEngineByContext(context: NodeContext): (AbstractEngine & AsciidocTemplate) | undefined;
|
|
320
324
|
/**
|
|
321
325
|
* Converts the provided node using one of the registered template
|
|
322
326
|
* engine modules. For more granular control, gain access to the
|
|
@@ -470,7 +474,7 @@ type AsciidocLoader = {
|
|
|
470
474
|
*
|
|
471
475
|
* @default 'light-dark()'
|
|
472
476
|
*/
|
|
473
|
-
defaultColor
|
|
477
|
+
defaultColor?: StringLiteralUnion<'light' | 'dark'> | 'light-dark()' | false;
|
|
474
478
|
/**
|
|
475
479
|
* The syntax highlighter theme to use. It can be either a
|
|
476
480
|
* string that will apply for both light and dark mode by
|
package/dist/index.cjs
CHANGED
|
@@ -193,6 +193,14 @@ var TemplateEngineRegistry = class _TemplateEngineRegistry {
|
|
|
193
193
|
(m) => m.extensions.includes(ext)
|
|
194
194
|
);
|
|
195
195
|
}
|
|
196
|
+
/**
|
|
197
|
+
* Returns the first module that supports the given context.
|
|
198
|
+
*/
|
|
199
|
+
getEngineByContext(context) {
|
|
200
|
+
return _TemplateEngineRegistry.modules.find(
|
|
201
|
+
(m) => m.hasContext(context)
|
|
202
|
+
);
|
|
203
|
+
}
|
|
196
204
|
/**
|
|
197
205
|
* Converts the provided node using one of the registered template
|
|
198
206
|
* engine modules. For more granular control, gain access to the
|
|
@@ -247,6 +255,9 @@ var AsciidocDocument = class {
|
|
|
247
255
|
partition: true
|
|
248
256
|
});
|
|
249
257
|
}
|
|
258
|
+
get attributes() {
|
|
259
|
+
return this.document.getAttributes();
|
|
260
|
+
}
|
|
250
261
|
get title() {
|
|
251
262
|
return this.documentTitle.getMain();
|
|
252
263
|
}
|
|
@@ -570,19 +581,20 @@ var sourceCodeConverter = (converterOptions) => {
|
|
|
570
581
|
return typeof transformer === "function" ? transformer(node) : transformer;
|
|
571
582
|
})
|
|
572
583
|
});
|
|
573
|
-
if (templateEngine
|
|
574
|
-
const { extension } = splitFilenameComponents(
|
|
575
|
-
|
|
576
|
-
extension || ""
|
|
584
|
+
if (templateEngine) {
|
|
585
|
+
const { extension } = splitFilenameComponents(
|
|
586
|
+
template ?? ""
|
|
577
587
|
);
|
|
578
|
-
|
|
588
|
+
const engine = extension ? templateEngine.getEngineByExtension(extension ?? "") : templateEngine.getEngineByContext(this.nodeContext);
|
|
589
|
+
if (template) {
|
|
579
590
|
const templateFile = (0, import_node_path2.resolve)(process.cwd(), template);
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
591
|
+
engine?.addContext(this.nodeContext, templateFile);
|
|
592
|
+
}
|
|
593
|
+
if (engine) {
|
|
594
|
+
return engine.renderNode(node, {
|
|
595
|
+
content: output,
|
|
596
|
+
lang
|
|
597
|
+
});
|
|
586
598
|
}
|
|
587
599
|
}
|
|
588
600
|
return output;
|
|
@@ -594,14 +606,14 @@ var sourceCodeConverter = (converterOptions) => {
|
|
|
594
606
|
// src/lib/shiki/transformers/transformAsciidocCallout.ts
|
|
595
607
|
var transformAsciidocCallout = (options) => {
|
|
596
608
|
return (node) => {
|
|
597
|
-
const lineComments = ["//", "#", ";;"];
|
|
609
|
+
const lineComments = ["//", "#", ";;", "%"];
|
|
598
610
|
const customLineComment = node.getAttribute("line-comment");
|
|
599
611
|
if (customLineComment) {
|
|
600
612
|
lineComments.push(escapeRegexCharacters(customLineComment));
|
|
601
613
|
}
|
|
602
614
|
const calloutReList = [
|
|
603
615
|
// Handles C-style and similar comments like Perl, Python...
|
|
604
|
-
new RegExp(`\\s
|
|
616
|
+
new RegExp(`\\s*(?:${lineComments.join("|")})((?:\\s+<(\\d+)>)+)`),
|
|
605
617
|
// Handles XML comments
|
|
606
618
|
new RegExp(/((?:\s*<!--(\d+)-->)+)/)
|
|
607
619
|
];
|
|
@@ -748,19 +760,20 @@ function asciidocLoader(_options) {
|
|
|
748
760
|
async function setDocument(doc, converters, templateEngine, { parseData, store }) {
|
|
749
761
|
const data = await parseData({
|
|
750
762
|
id: doc.slug,
|
|
751
|
-
data:
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
763
|
+
data: doc.attributes
|
|
764
|
+
// data: {
|
|
765
|
+
// title: doc.title,
|
|
766
|
+
// subtitle: doc.subtitle,
|
|
767
|
+
// author: doc.author,
|
|
768
|
+
// authors: doc.authors,
|
|
769
|
+
// version: doc.version,
|
|
770
|
+
// createdAt: new Date(doc.createdAt),
|
|
771
|
+
// email: doc.authors.at(0)?.getEmail(),
|
|
772
|
+
// description: doc.description,
|
|
773
|
+
// slug: doc.slug,
|
|
774
|
+
// preamble: doc.preamble,
|
|
775
|
+
// keywords: doc.keywords,
|
|
776
|
+
// },
|
|
764
777
|
});
|
|
765
778
|
store.set({
|
|
766
779
|
id: doc.slug,
|
|
@@ -783,9 +796,19 @@ var transformerPrompt = (options) => {
|
|
|
783
796
|
if (customPrompt && options?.langs && typeof options.langs[language] === "object") {
|
|
784
797
|
cssClasses = options.langs[language].cssClasses;
|
|
785
798
|
}
|
|
799
|
+
let skipNext = false;
|
|
786
800
|
return {
|
|
801
|
+
enforce: "pre",
|
|
787
802
|
line(hast) {
|
|
788
803
|
if (!promptToAdd) return;
|
|
804
|
+
const skipCurrent = skipNext;
|
|
805
|
+
skipNext = false;
|
|
806
|
+
const lastChild = hast.children.at(-1);
|
|
807
|
+
if (lastChild && // @ts-expect-error property "children" does exist
|
|
808
|
+
lastChild.children[0].value.match(/\s+\\(?:\\)?\s*$/)) {
|
|
809
|
+
skipNext = true;
|
|
810
|
+
}
|
|
811
|
+
if (skipCurrent) return;
|
|
789
812
|
hast.children.unshift({
|
|
790
813
|
type: "element",
|
|
791
814
|
tagName: "span",
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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-C1F2jTPD.cjs';
|
|
3
|
+
export { a as AsciidocTemplate, C as CustomConverterFactoryFn, F as FilesystemTemplate, N as NodeContext, R as RawTemplate } from './index-C1F2jTPD.cjs';
|
|
4
4
|
export { transformAsciidocCallout, transformerPrompt } from './lib/shiki/transformers/index.cjs';
|
|
5
5
|
import 'shiki';
|
|
6
6
|
import 'asciidoctor';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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-C1F2jTPD.js';
|
|
3
|
+
export { a as AsciidocTemplate, C as CustomConverterFactoryFn, F as FilesystemTemplate, N as NodeContext, R as RawTemplate } from './index-C1F2jTPD.js';
|
|
4
4
|
export { transformAsciidocCallout, transformerPrompt } from './lib/shiki/transformers/index.js';
|
|
5
5
|
import 'shiki';
|
|
6
6
|
import 'asciidoctor';
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
sourceCodeConverter
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-SUQERYPQ.js";
|
|
4
4
|
import {
|
|
5
5
|
transformAsciidocCallout,
|
|
6
6
|
transformerPrompt
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-KPEWXJBE.js";
|
|
8
8
|
import {
|
|
9
9
|
slugify,
|
|
10
10
|
splitFilenameComponents
|
|
@@ -155,6 +155,14 @@ var TemplateEngineRegistry = class _TemplateEngineRegistry {
|
|
|
155
155
|
(m) => m.extensions.includes(ext)
|
|
156
156
|
);
|
|
157
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Returns the first module that supports the given context.
|
|
160
|
+
*/
|
|
161
|
+
getEngineByContext(context) {
|
|
162
|
+
return _TemplateEngineRegistry.modules.find(
|
|
163
|
+
(m) => m.hasContext(context)
|
|
164
|
+
);
|
|
165
|
+
}
|
|
158
166
|
/**
|
|
159
167
|
* Converts the provided node using one of the registered template
|
|
160
168
|
* engine modules. For more granular control, gain access to the
|
|
@@ -209,6 +217,9 @@ var AsciidocDocument = class {
|
|
|
209
217
|
partition: true
|
|
210
218
|
});
|
|
211
219
|
}
|
|
220
|
+
get attributes() {
|
|
221
|
+
return this.document.getAttributes();
|
|
222
|
+
}
|
|
212
223
|
get title() {
|
|
213
224
|
return this.documentTitle.getMain();
|
|
214
225
|
}
|
|
@@ -459,19 +470,20 @@ function asciidocLoader(_options) {
|
|
|
459
470
|
async function setDocument(doc, converters, templateEngine, { parseData, store }) {
|
|
460
471
|
const data = await parseData({
|
|
461
472
|
id: doc.slug,
|
|
462
|
-
data:
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
473
|
+
data: doc.attributes
|
|
474
|
+
// data: {
|
|
475
|
+
// title: doc.title,
|
|
476
|
+
// subtitle: doc.subtitle,
|
|
477
|
+
// author: doc.author,
|
|
478
|
+
// authors: doc.authors,
|
|
479
|
+
// version: doc.version,
|
|
480
|
+
// createdAt: new Date(doc.createdAt),
|
|
481
|
+
// email: doc.authors.at(0)?.getEmail(),
|
|
482
|
+
// description: doc.description,
|
|
483
|
+
// slug: doc.slug,
|
|
484
|
+
// preamble: doc.preamble,
|
|
485
|
+
// keywords: doc.keywords,
|
|
486
|
+
// },
|
|
475
487
|
});
|
|
476
488
|
store.set({
|
|
477
489
|
id: doc.slug,
|
|
@@ -55,19 +55,20 @@ var sourceCodeConverter = (converterOptions) => {
|
|
|
55
55
|
return typeof transformer === "function" ? transformer(node) : transformer;
|
|
56
56
|
})
|
|
57
57
|
});
|
|
58
|
-
if (templateEngine
|
|
59
|
-
const { extension } = splitFilenameComponents(
|
|
60
|
-
|
|
61
|
-
extension || ""
|
|
58
|
+
if (templateEngine) {
|
|
59
|
+
const { extension } = splitFilenameComponents(
|
|
60
|
+
template ?? ""
|
|
62
61
|
);
|
|
63
|
-
|
|
62
|
+
const engine = extension ? templateEngine.getEngineByExtension(extension ?? "") : templateEngine.getEngineByContext(this.nodeContext);
|
|
63
|
+
if (template) {
|
|
64
64
|
const templateFile = (0, import_node_path.resolve)(process.cwd(), template);
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
engine?.addContext(this.nodeContext, templateFile);
|
|
66
|
+
}
|
|
67
|
+
if (engine) {
|
|
68
|
+
return engine.renderNode(node, {
|
|
69
|
+
content: output,
|
|
70
|
+
lang
|
|
71
|
+
});
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
74
|
return output;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ShikiTransformer } from 'shiki';
|
|
2
|
-
import { C as CustomConverterFactoryFn, S as ShikiTransformerFactoryFn } from '../../../index-
|
|
2
|
+
import { C as CustomConverterFactoryFn, S as ShikiTransformerFactoryFn } from '../../../index-C1F2jTPD.cjs';
|
|
3
3
|
import 'asciidoctor';
|
|
4
4
|
import 'astro/zod';
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ShikiTransformer } from 'shiki';
|
|
2
|
-
import { C as CustomConverterFactoryFn, S as ShikiTransformerFactoryFn } from '../../../index-
|
|
2
|
+
import { C as CustomConverterFactoryFn, S as ShikiTransformerFactoryFn } from '../../../index-C1F2jTPD.js';
|
|
3
3
|
import 'asciidoctor';
|
|
4
4
|
import 'astro/zod';
|
|
5
5
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { b as AbstractEngine, a as AsciidocTemplate, T as TemplateModule, F as FilesystemTemplate, R as RawTemplate } from '../../../../index-
|
|
1
|
+
import { b as AbstractEngine, a as AsciidocTemplate, T as TemplateModule, F as FilesystemTemplate, R as RawTemplate } from '../../../../index-C1F2jTPD.cjs';
|
|
2
2
|
import { AbstractBlock } from 'asciidoctor';
|
|
3
3
|
import 'shiki';
|
|
4
4
|
import 'astro/zod';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { b as AbstractEngine, a as AsciidocTemplate, T as TemplateModule, F as FilesystemTemplate, R as RawTemplate } from '../../../../index-
|
|
1
|
+
import { b as AbstractEngine, a as AsciidocTemplate, T as TemplateModule, F as FilesystemTemplate, R as RawTemplate } from '../../../../index-C1F2jTPD.js';
|
|
2
2
|
import { AbstractBlock } from 'asciidoctor';
|
|
3
3
|
import 'shiki';
|
|
4
4
|
import 'astro/zod';
|
|
@@ -34,14 +34,14 @@ function escapeRegexCharacters(str) {
|
|
|
34
34
|
// src/lib/shiki/transformers/transformAsciidocCallout.ts
|
|
35
35
|
var transformAsciidocCallout = (options) => {
|
|
36
36
|
return (node) => {
|
|
37
|
-
const lineComments = ["//", "#", ";;"];
|
|
37
|
+
const lineComments = ["//", "#", ";;", "%"];
|
|
38
38
|
const customLineComment = node.getAttribute("line-comment");
|
|
39
39
|
if (customLineComment) {
|
|
40
40
|
lineComments.push(escapeRegexCharacters(customLineComment));
|
|
41
41
|
}
|
|
42
42
|
const calloutReList = [
|
|
43
43
|
// Handles C-style and similar comments like Perl, Python...
|
|
44
|
-
new RegExp(`\\s
|
|
44
|
+
new RegExp(`\\s*(?:${lineComments.join("|")})((?:\\s+<(\\d+)>)+)`),
|
|
45
45
|
// Handles XML comments
|
|
46
46
|
new RegExp(/((?:\s*<!--(\d+)-->)+)/)
|
|
47
47
|
];
|
|
@@ -101,9 +101,19 @@ var transformerPrompt = (options) => {
|
|
|
101
101
|
if (customPrompt && options?.langs && typeof options.langs[language] === "object") {
|
|
102
102
|
cssClasses = options.langs[language].cssClasses;
|
|
103
103
|
}
|
|
104
|
+
let skipNext = false;
|
|
104
105
|
return {
|
|
106
|
+
enforce: "pre",
|
|
105
107
|
line(hast) {
|
|
106
108
|
if (!promptToAdd) return;
|
|
109
|
+
const skipCurrent = skipNext;
|
|
110
|
+
skipNext = false;
|
|
111
|
+
const lastChild = hast.children.at(-1);
|
|
112
|
+
if (lastChild && // @ts-expect-error property "children" does exist
|
|
113
|
+
lastChild.children[0].value.match(/\s+\\(?:\\)?\s*$/)) {
|
|
114
|
+
skipNext = true;
|
|
115
|
+
}
|
|
116
|
+
if (skipCurrent) return;
|
|
107
117
|
hast.children.unshift({
|
|
108
118
|
type: "element",
|
|
109
119
|
tagName: "span",
|