@d10f/asciidoc-astro-loader 0.0.1 → 0.0.2
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/{chunk-HAZIHU2Y.js → chunk-BRMWIQA2.js} +3 -10
- package/dist/{index-Cf7MF6tZ.d.cts → index-BNxO58s3.d.cts} +158 -31
- package/dist/{index-Cf7MF6tZ.d.ts → index-BNxO58s3.d.ts} +158 -31
- package/dist/index.cjs +91 -39
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +89 -34
- package/dist/lib/asciidoc/converters/index.cjs +3 -6
- package/dist/lib/asciidoc/converters/index.d.cts +2 -3
- package/dist/lib/asciidoc/converters/index.d.ts +2 -3
- package/dist/lib/asciidoc/converters/index.js +1 -1
- 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/package.json +6 -5
|
@@ -5,16 +5,12 @@ import {
|
|
|
5
5
|
} from "./chunk-DDIUST2Z.js";
|
|
6
6
|
|
|
7
7
|
// src/lib/asciidoc/converters/sourceCodeConverter.ts
|
|
8
|
-
import {
|
|
9
|
-
transformerNotationDiff,
|
|
10
|
-
transformerNotationFocus,
|
|
11
|
-
transformerNotationHighlight
|
|
12
|
-
} from "@shikijs/transformers";
|
|
13
8
|
import { resolve } from "path";
|
|
14
|
-
var sourceCodeConverter = ({
|
|
9
|
+
var sourceCodeConverter = ({ transformers, template }) => {
|
|
15
10
|
return (options, highlighter) => {
|
|
16
11
|
return {
|
|
17
|
-
nodeContext:
|
|
12
|
+
nodeContext: "listing",
|
|
13
|
+
nodeStyle: "source",
|
|
18
14
|
convert(node, templateEngine) {
|
|
19
15
|
const input = node.getSourceLines().join("\n");
|
|
20
16
|
const lang = node.getAttribute("language");
|
|
@@ -23,9 +19,6 @@ var sourceCodeConverter = ({ nodeContext, transformers, template }) => {
|
|
|
23
19
|
lang,
|
|
24
20
|
transformers: [
|
|
25
21
|
...transformers ?? [],
|
|
26
|
-
transformerNotationDiff(),
|
|
27
|
-
transformerNotationHighlight(),
|
|
28
|
-
transformerNotationFocus(),
|
|
29
22
|
transformAsciidocCallout({ node }),
|
|
30
23
|
transformConsoleCodeBlock()
|
|
31
24
|
]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { HighlighterCore, CodeToHastOptions, CodeOptionsMultipleThemes, ThemeRegistrationAny, StringLiteralUnion, BundledTheme } from 'shiki';
|
|
2
|
-
import { AbstractNode } from 'asciidoctor';
|
|
3
|
-
import { z } from 'zod';
|
|
1
|
+
import { HighlighterCore, CodeToHastOptions, CodeOptionsMultipleThemes, ThemeRegistrationAny, StringLiteralUnion, BundledTheme, ShikiTransformer } from 'shiki';
|
|
2
|
+
import { AbstractNode, AbstractBlock } from 'asciidoctor';
|
|
3
|
+
import { z } from 'astro/zod';
|
|
4
4
|
|
|
5
5
|
type RequiredOptions = z.output<typeof loaderOptionsSchema>;
|
|
6
6
|
type DocumentOptions = RequiredOptions['document'];
|
|
@@ -8,33 +8,88 @@ type PreambleOptions = RequiredOptions['preamble'];
|
|
|
8
8
|
declare const loaderOptionsSchema: z.ZodObject<{
|
|
9
9
|
base: z.ZodString;
|
|
10
10
|
document: z.ZodDefault<z.ZodObject<{
|
|
11
|
-
mode: z.ZodDefault<z.ZodUnion<
|
|
12
|
-
template: z.
|
|
11
|
+
mode: z.ZodDefault<z.ZodUnion<[z.ZodLiteral<"safe">, z.ZodLiteral<"unsafe">]>>;
|
|
12
|
+
template: z.ZodEffects<z.ZodDefault<z.ZodString>, string, string | undefined>;
|
|
13
13
|
recursive: z.ZodDefault<z.ZodBoolean>;
|
|
14
|
-
}, z.
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
15
|
+
mode: z.ZodDefault<z.ZodUnion<[z.ZodLiteral<"safe">, z.ZodLiteral<"unsafe">]>>;
|
|
16
|
+
template: z.ZodEffects<z.ZodDefault<z.ZodString>, string, string | undefined>;
|
|
17
|
+
recursive: z.ZodDefault<z.ZodBoolean>;
|
|
18
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
19
|
+
mode: z.ZodDefault<z.ZodUnion<[z.ZodLiteral<"safe">, z.ZodLiteral<"unsafe">]>>;
|
|
20
|
+
template: z.ZodEffects<z.ZodDefault<z.ZodString>, string, string | undefined>;
|
|
21
|
+
recursive: z.ZodDefault<z.ZodBoolean>;
|
|
22
|
+
}, z.ZodTypeAny, "passthrough">>>;
|
|
23
|
+
syntaxHighlighting: z.ZodDefault<z.ZodEffects<z.ZodObject<{
|
|
24
|
+
theme: z.ZodDefault<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodObject<{
|
|
25
|
+
light: z.ZodString;
|
|
26
|
+
dark: z.ZodString;
|
|
27
|
+
}, "strip", z.ZodString, z.objectOutputType<{
|
|
17
28
|
light: z.ZodString;
|
|
18
29
|
dark: z.ZodString;
|
|
19
|
-
}, z.
|
|
30
|
+
}, z.ZodString, "strip">, z.objectInputType<{
|
|
31
|
+
light: z.ZodString;
|
|
32
|
+
dark: z.ZodString;
|
|
33
|
+
}, z.ZodString, "strip">>]>, {
|
|
20
34
|
light: string;
|
|
21
35
|
dark: string;
|
|
22
36
|
} & {
|
|
23
37
|
[other: string]: string;
|
|
24
|
-
}, string | {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}>>>;
|
|
38
|
+
}, string | z.objectInputType<{
|
|
39
|
+
light: z.ZodString;
|
|
40
|
+
dark: z.ZodString;
|
|
41
|
+
}, z.ZodString, "strip">>>;
|
|
29
42
|
defaultColor: z.ZodDefault<z.ZodString>;
|
|
30
43
|
cssVariablePrefix: z.ZodDefault<z.ZodString>;
|
|
31
|
-
mergeWhitespaces: z.ZodDefault<z.ZodUnion<
|
|
32
|
-
tabindex: z.ZodDefault<z.ZodUnion<
|
|
33
|
-
|
|
44
|
+
mergeWhitespaces: z.ZodDefault<z.ZodUnion<[z.ZodBoolean, z.ZodLiteral<"never">]>>;
|
|
45
|
+
tabindex: z.ZodDefault<z.ZodUnion<[z.ZodNumber, z.ZodString, z.ZodLiteral<false>]>>;
|
|
46
|
+
transformers: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
47
|
+
name: z.ZodString;
|
|
48
|
+
enforce: z.ZodUnion<[z.ZodLiteral<"pre">, z.ZodLiteral<"post">]>;
|
|
49
|
+
}, "strip", z.ZodTypeAny, {
|
|
50
|
+
name: string;
|
|
51
|
+
enforce: "pre" | "post";
|
|
52
|
+
}, {
|
|
53
|
+
name: string;
|
|
54
|
+
enforce: "pre" | "post";
|
|
55
|
+
}>, "many">>;
|
|
56
|
+
}, "strip", z.ZodTypeAny, {
|
|
57
|
+
theme: {
|
|
58
|
+
light: string;
|
|
59
|
+
dark: string;
|
|
60
|
+
} & {
|
|
61
|
+
[other: string]: string;
|
|
62
|
+
};
|
|
34
63
|
defaultColor: string;
|
|
35
64
|
cssVariablePrefix: string;
|
|
36
65
|
mergeWhitespaces: boolean | "never";
|
|
37
66
|
tabindex: string | number | false;
|
|
67
|
+
transformers?: {
|
|
68
|
+
name: string;
|
|
69
|
+
enforce: "pre" | "post";
|
|
70
|
+
}[] | undefined;
|
|
71
|
+
}, {
|
|
72
|
+
theme?: string | z.objectInputType<{
|
|
73
|
+
light: z.ZodString;
|
|
74
|
+
dark: z.ZodString;
|
|
75
|
+
}, z.ZodString, "strip"> | undefined;
|
|
76
|
+
defaultColor?: string | undefined;
|
|
77
|
+
cssVariablePrefix?: string | undefined;
|
|
78
|
+
mergeWhitespaces?: boolean | "never" | undefined;
|
|
79
|
+
tabindex?: string | number | false | undefined;
|
|
80
|
+
transformers?: {
|
|
81
|
+
name: string;
|
|
82
|
+
enforce: "pre" | "post";
|
|
83
|
+
}[] | undefined;
|
|
84
|
+
}>, {
|
|
85
|
+
defaultColor: string;
|
|
86
|
+
cssVariablePrefix: string;
|
|
87
|
+
mergeWhitespaces: boolean | "never";
|
|
88
|
+
tabindex: string | number | false;
|
|
89
|
+
transformers?: {
|
|
90
|
+
name: string;
|
|
91
|
+
enforce: "pre" | "post";
|
|
92
|
+
}[] | undefined;
|
|
38
93
|
themes: {
|
|
39
94
|
light: string;
|
|
40
95
|
dark: string;
|
|
@@ -42,23 +97,89 @@ declare const loaderOptionsSchema: z.ZodObject<{
|
|
|
42
97
|
[other: string]: string;
|
|
43
98
|
};
|
|
44
99
|
}, {
|
|
45
|
-
theme
|
|
100
|
+
theme?: string | z.objectInputType<{
|
|
101
|
+
light: z.ZodString;
|
|
102
|
+
dark: z.ZodString;
|
|
103
|
+
}, z.ZodString, "strip"> | undefined;
|
|
104
|
+
defaultColor?: string | undefined;
|
|
105
|
+
cssVariablePrefix?: string | undefined;
|
|
106
|
+
mergeWhitespaces?: boolean | "never" | undefined;
|
|
107
|
+
tabindex?: string | number | false | undefined;
|
|
108
|
+
transformers?: {
|
|
109
|
+
name: string;
|
|
110
|
+
enforce: "pre" | "post";
|
|
111
|
+
}[] | undefined;
|
|
112
|
+
}>>;
|
|
113
|
+
preamble: z.ZodDefault<z.ZodObject<{
|
|
114
|
+
tableOfContents: z.ZodDefault<z.ZodBoolean>;
|
|
115
|
+
maxLevel: z.ZodDefault<z.ZodNumber>;
|
|
116
|
+
position: z.ZodDefault<z.ZodUnion<[z.ZodLiteral<"before">, z.ZodLiteral<"after">]>>;
|
|
117
|
+
}, "strip", z.ZodTypeAny, {
|
|
118
|
+
tableOfContents: boolean;
|
|
119
|
+
maxLevel: number;
|
|
120
|
+
position: "before" | "after";
|
|
121
|
+
}, {
|
|
122
|
+
tableOfContents?: boolean | undefined;
|
|
123
|
+
maxLevel?: number | undefined;
|
|
124
|
+
position?: "before" | "after" | undefined;
|
|
125
|
+
}>>;
|
|
126
|
+
}, "strip", z.ZodTypeAny, {
|
|
127
|
+
base: string;
|
|
128
|
+
document: {
|
|
129
|
+
mode: "safe" | "unsafe";
|
|
130
|
+
template: string;
|
|
131
|
+
recursive: boolean;
|
|
132
|
+
} & {
|
|
133
|
+
[k: string]: unknown;
|
|
134
|
+
};
|
|
135
|
+
syntaxHighlighting: {
|
|
136
|
+
defaultColor: string;
|
|
137
|
+
cssVariablePrefix: string;
|
|
138
|
+
mergeWhitespaces: boolean | "never";
|
|
139
|
+
tabindex: string | number | false;
|
|
140
|
+
transformers?: {
|
|
141
|
+
name: string;
|
|
142
|
+
enforce: "pre" | "post";
|
|
143
|
+
}[] | undefined;
|
|
144
|
+
themes: {
|
|
46
145
|
light: string;
|
|
47
146
|
dark: string;
|
|
48
147
|
} & {
|
|
49
148
|
[other: string]: string;
|
|
50
149
|
};
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
150
|
+
};
|
|
151
|
+
preamble: {
|
|
152
|
+
tableOfContents: boolean;
|
|
153
|
+
maxLevel: number;
|
|
154
|
+
position: "before" | "after";
|
|
155
|
+
};
|
|
156
|
+
}, {
|
|
157
|
+
base: string;
|
|
158
|
+
document?: z.objectInputType<{
|
|
159
|
+
mode: z.ZodDefault<z.ZodUnion<[z.ZodLiteral<"safe">, z.ZodLiteral<"unsafe">]>>;
|
|
160
|
+
template: z.ZodEffects<z.ZodDefault<z.ZodString>, string, string | undefined>;
|
|
161
|
+
recursive: z.ZodDefault<z.ZodBoolean>;
|
|
162
|
+
}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
163
|
+
syntaxHighlighting?: {
|
|
164
|
+
theme?: string | z.objectInputType<{
|
|
165
|
+
light: z.ZodString;
|
|
166
|
+
dark: z.ZodString;
|
|
167
|
+
}, z.ZodString, "strip"> | undefined;
|
|
168
|
+
defaultColor?: string | undefined;
|
|
169
|
+
cssVariablePrefix?: string | undefined;
|
|
170
|
+
mergeWhitespaces?: boolean | "never" | undefined;
|
|
171
|
+
tabindex?: string | number | false | undefined;
|
|
172
|
+
transformers?: {
|
|
173
|
+
name: string;
|
|
174
|
+
enforce: "pre" | "post";
|
|
175
|
+
}[] | undefined;
|
|
176
|
+
} | undefined;
|
|
177
|
+
preamble?: {
|
|
178
|
+
tableOfContents?: boolean | undefined;
|
|
179
|
+
maxLevel?: number | undefined;
|
|
180
|
+
position?: "before" | "after" | undefined;
|
|
181
|
+
} | undefined;
|
|
182
|
+
}>;
|
|
62
183
|
|
|
63
184
|
declare abstract class AbstractEngine {
|
|
64
185
|
private _name;
|
|
@@ -141,7 +262,7 @@ declare class TemplateEngineRegistry {
|
|
|
141
262
|
* engine itself with _getEngineByName_ or _getEngineByExtension_
|
|
142
263
|
* and use one of its render methods directly.
|
|
143
264
|
*/
|
|
144
|
-
convert(node:
|
|
265
|
+
convert(node: AbstractBlock, options?: Record<string, unknown>): string | undefined;
|
|
145
266
|
/**
|
|
146
267
|
* Scans the templates directory and creates an index of all templates
|
|
147
268
|
* based on supported block names and extensions.
|
|
@@ -279,6 +400,12 @@ type AsciidocLoader = {
|
|
|
279
400
|
dark: BundledTheme;
|
|
280
401
|
[customTheme: string]: BundledTheme;
|
|
281
402
|
};
|
|
403
|
+
/**
|
|
404
|
+
* A list of transformers to apply for source code blocks.
|
|
405
|
+
*
|
|
406
|
+
* @default [ transformerNotationDiff, transformerNotationHighlight, transformerNotationFocus ]
|
|
407
|
+
*/
|
|
408
|
+
transformers: ShikiTransformer[];
|
|
282
409
|
}>;
|
|
283
410
|
};
|
|
284
411
|
/**
|
|
@@ -305,7 +432,7 @@ interface TemplateModule {
|
|
|
305
432
|
* to the template rendering process.
|
|
306
433
|
*/
|
|
307
434
|
interface AsciidocTemplate {
|
|
308
|
-
renderNode(node:
|
|
435
|
+
renderNode(node: AbstractBlock, options?: Record<string, unknown>): string;
|
|
309
436
|
}
|
|
310
437
|
/**
|
|
311
438
|
* Designates that the template will receive a file location that points
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { HighlighterCore, CodeToHastOptions, CodeOptionsMultipleThemes, ThemeRegistrationAny, StringLiteralUnion, BundledTheme } from 'shiki';
|
|
2
|
-
import { AbstractNode } from 'asciidoctor';
|
|
3
|
-
import { z } from 'zod';
|
|
1
|
+
import { HighlighterCore, CodeToHastOptions, CodeOptionsMultipleThemes, ThemeRegistrationAny, StringLiteralUnion, BundledTheme, ShikiTransformer } from 'shiki';
|
|
2
|
+
import { AbstractNode, AbstractBlock } from 'asciidoctor';
|
|
3
|
+
import { z } from 'astro/zod';
|
|
4
4
|
|
|
5
5
|
type RequiredOptions = z.output<typeof loaderOptionsSchema>;
|
|
6
6
|
type DocumentOptions = RequiredOptions['document'];
|
|
@@ -8,33 +8,88 @@ type PreambleOptions = RequiredOptions['preamble'];
|
|
|
8
8
|
declare const loaderOptionsSchema: z.ZodObject<{
|
|
9
9
|
base: z.ZodString;
|
|
10
10
|
document: z.ZodDefault<z.ZodObject<{
|
|
11
|
-
mode: z.ZodDefault<z.ZodUnion<
|
|
12
|
-
template: z.
|
|
11
|
+
mode: z.ZodDefault<z.ZodUnion<[z.ZodLiteral<"safe">, z.ZodLiteral<"unsafe">]>>;
|
|
12
|
+
template: z.ZodEffects<z.ZodDefault<z.ZodString>, string, string | undefined>;
|
|
13
13
|
recursive: z.ZodDefault<z.ZodBoolean>;
|
|
14
|
-
}, z.
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
15
|
+
mode: z.ZodDefault<z.ZodUnion<[z.ZodLiteral<"safe">, z.ZodLiteral<"unsafe">]>>;
|
|
16
|
+
template: z.ZodEffects<z.ZodDefault<z.ZodString>, string, string | undefined>;
|
|
17
|
+
recursive: z.ZodDefault<z.ZodBoolean>;
|
|
18
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
19
|
+
mode: z.ZodDefault<z.ZodUnion<[z.ZodLiteral<"safe">, z.ZodLiteral<"unsafe">]>>;
|
|
20
|
+
template: z.ZodEffects<z.ZodDefault<z.ZodString>, string, string | undefined>;
|
|
21
|
+
recursive: z.ZodDefault<z.ZodBoolean>;
|
|
22
|
+
}, z.ZodTypeAny, "passthrough">>>;
|
|
23
|
+
syntaxHighlighting: z.ZodDefault<z.ZodEffects<z.ZodObject<{
|
|
24
|
+
theme: z.ZodDefault<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodObject<{
|
|
25
|
+
light: z.ZodString;
|
|
26
|
+
dark: z.ZodString;
|
|
27
|
+
}, "strip", z.ZodString, z.objectOutputType<{
|
|
17
28
|
light: z.ZodString;
|
|
18
29
|
dark: z.ZodString;
|
|
19
|
-
}, z.
|
|
30
|
+
}, z.ZodString, "strip">, z.objectInputType<{
|
|
31
|
+
light: z.ZodString;
|
|
32
|
+
dark: z.ZodString;
|
|
33
|
+
}, z.ZodString, "strip">>]>, {
|
|
20
34
|
light: string;
|
|
21
35
|
dark: string;
|
|
22
36
|
} & {
|
|
23
37
|
[other: string]: string;
|
|
24
|
-
}, string | {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}>>>;
|
|
38
|
+
}, string | z.objectInputType<{
|
|
39
|
+
light: z.ZodString;
|
|
40
|
+
dark: z.ZodString;
|
|
41
|
+
}, z.ZodString, "strip">>>;
|
|
29
42
|
defaultColor: z.ZodDefault<z.ZodString>;
|
|
30
43
|
cssVariablePrefix: z.ZodDefault<z.ZodString>;
|
|
31
|
-
mergeWhitespaces: z.ZodDefault<z.ZodUnion<
|
|
32
|
-
tabindex: z.ZodDefault<z.ZodUnion<
|
|
33
|
-
|
|
44
|
+
mergeWhitespaces: z.ZodDefault<z.ZodUnion<[z.ZodBoolean, z.ZodLiteral<"never">]>>;
|
|
45
|
+
tabindex: z.ZodDefault<z.ZodUnion<[z.ZodNumber, z.ZodString, z.ZodLiteral<false>]>>;
|
|
46
|
+
transformers: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
47
|
+
name: z.ZodString;
|
|
48
|
+
enforce: z.ZodUnion<[z.ZodLiteral<"pre">, z.ZodLiteral<"post">]>;
|
|
49
|
+
}, "strip", z.ZodTypeAny, {
|
|
50
|
+
name: string;
|
|
51
|
+
enforce: "pre" | "post";
|
|
52
|
+
}, {
|
|
53
|
+
name: string;
|
|
54
|
+
enforce: "pre" | "post";
|
|
55
|
+
}>, "many">>;
|
|
56
|
+
}, "strip", z.ZodTypeAny, {
|
|
57
|
+
theme: {
|
|
58
|
+
light: string;
|
|
59
|
+
dark: string;
|
|
60
|
+
} & {
|
|
61
|
+
[other: string]: string;
|
|
62
|
+
};
|
|
34
63
|
defaultColor: string;
|
|
35
64
|
cssVariablePrefix: string;
|
|
36
65
|
mergeWhitespaces: boolean | "never";
|
|
37
66
|
tabindex: string | number | false;
|
|
67
|
+
transformers?: {
|
|
68
|
+
name: string;
|
|
69
|
+
enforce: "pre" | "post";
|
|
70
|
+
}[] | undefined;
|
|
71
|
+
}, {
|
|
72
|
+
theme?: string | z.objectInputType<{
|
|
73
|
+
light: z.ZodString;
|
|
74
|
+
dark: z.ZodString;
|
|
75
|
+
}, z.ZodString, "strip"> | undefined;
|
|
76
|
+
defaultColor?: string | undefined;
|
|
77
|
+
cssVariablePrefix?: string | undefined;
|
|
78
|
+
mergeWhitespaces?: boolean | "never" | undefined;
|
|
79
|
+
tabindex?: string | number | false | undefined;
|
|
80
|
+
transformers?: {
|
|
81
|
+
name: string;
|
|
82
|
+
enforce: "pre" | "post";
|
|
83
|
+
}[] | undefined;
|
|
84
|
+
}>, {
|
|
85
|
+
defaultColor: string;
|
|
86
|
+
cssVariablePrefix: string;
|
|
87
|
+
mergeWhitespaces: boolean | "never";
|
|
88
|
+
tabindex: string | number | false;
|
|
89
|
+
transformers?: {
|
|
90
|
+
name: string;
|
|
91
|
+
enforce: "pre" | "post";
|
|
92
|
+
}[] | undefined;
|
|
38
93
|
themes: {
|
|
39
94
|
light: string;
|
|
40
95
|
dark: string;
|
|
@@ -42,23 +97,89 @@ declare const loaderOptionsSchema: z.ZodObject<{
|
|
|
42
97
|
[other: string]: string;
|
|
43
98
|
};
|
|
44
99
|
}, {
|
|
45
|
-
theme
|
|
100
|
+
theme?: string | z.objectInputType<{
|
|
101
|
+
light: z.ZodString;
|
|
102
|
+
dark: z.ZodString;
|
|
103
|
+
}, z.ZodString, "strip"> | undefined;
|
|
104
|
+
defaultColor?: string | undefined;
|
|
105
|
+
cssVariablePrefix?: string | undefined;
|
|
106
|
+
mergeWhitespaces?: boolean | "never" | undefined;
|
|
107
|
+
tabindex?: string | number | false | undefined;
|
|
108
|
+
transformers?: {
|
|
109
|
+
name: string;
|
|
110
|
+
enforce: "pre" | "post";
|
|
111
|
+
}[] | undefined;
|
|
112
|
+
}>>;
|
|
113
|
+
preamble: z.ZodDefault<z.ZodObject<{
|
|
114
|
+
tableOfContents: z.ZodDefault<z.ZodBoolean>;
|
|
115
|
+
maxLevel: z.ZodDefault<z.ZodNumber>;
|
|
116
|
+
position: z.ZodDefault<z.ZodUnion<[z.ZodLiteral<"before">, z.ZodLiteral<"after">]>>;
|
|
117
|
+
}, "strip", z.ZodTypeAny, {
|
|
118
|
+
tableOfContents: boolean;
|
|
119
|
+
maxLevel: number;
|
|
120
|
+
position: "before" | "after";
|
|
121
|
+
}, {
|
|
122
|
+
tableOfContents?: boolean | undefined;
|
|
123
|
+
maxLevel?: number | undefined;
|
|
124
|
+
position?: "before" | "after" | undefined;
|
|
125
|
+
}>>;
|
|
126
|
+
}, "strip", z.ZodTypeAny, {
|
|
127
|
+
base: string;
|
|
128
|
+
document: {
|
|
129
|
+
mode: "safe" | "unsafe";
|
|
130
|
+
template: string;
|
|
131
|
+
recursive: boolean;
|
|
132
|
+
} & {
|
|
133
|
+
[k: string]: unknown;
|
|
134
|
+
};
|
|
135
|
+
syntaxHighlighting: {
|
|
136
|
+
defaultColor: string;
|
|
137
|
+
cssVariablePrefix: string;
|
|
138
|
+
mergeWhitespaces: boolean | "never";
|
|
139
|
+
tabindex: string | number | false;
|
|
140
|
+
transformers?: {
|
|
141
|
+
name: string;
|
|
142
|
+
enforce: "pre" | "post";
|
|
143
|
+
}[] | undefined;
|
|
144
|
+
themes: {
|
|
46
145
|
light: string;
|
|
47
146
|
dark: string;
|
|
48
147
|
} & {
|
|
49
148
|
[other: string]: string;
|
|
50
149
|
};
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
150
|
+
};
|
|
151
|
+
preamble: {
|
|
152
|
+
tableOfContents: boolean;
|
|
153
|
+
maxLevel: number;
|
|
154
|
+
position: "before" | "after";
|
|
155
|
+
};
|
|
156
|
+
}, {
|
|
157
|
+
base: string;
|
|
158
|
+
document?: z.objectInputType<{
|
|
159
|
+
mode: z.ZodDefault<z.ZodUnion<[z.ZodLiteral<"safe">, z.ZodLiteral<"unsafe">]>>;
|
|
160
|
+
template: z.ZodEffects<z.ZodDefault<z.ZodString>, string, string | undefined>;
|
|
161
|
+
recursive: z.ZodDefault<z.ZodBoolean>;
|
|
162
|
+
}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
163
|
+
syntaxHighlighting?: {
|
|
164
|
+
theme?: string | z.objectInputType<{
|
|
165
|
+
light: z.ZodString;
|
|
166
|
+
dark: z.ZodString;
|
|
167
|
+
}, z.ZodString, "strip"> | undefined;
|
|
168
|
+
defaultColor?: string | undefined;
|
|
169
|
+
cssVariablePrefix?: string | undefined;
|
|
170
|
+
mergeWhitespaces?: boolean | "never" | undefined;
|
|
171
|
+
tabindex?: string | number | false | undefined;
|
|
172
|
+
transformers?: {
|
|
173
|
+
name: string;
|
|
174
|
+
enforce: "pre" | "post";
|
|
175
|
+
}[] | undefined;
|
|
176
|
+
} | undefined;
|
|
177
|
+
preamble?: {
|
|
178
|
+
tableOfContents?: boolean | undefined;
|
|
179
|
+
maxLevel?: number | undefined;
|
|
180
|
+
position?: "before" | "after" | undefined;
|
|
181
|
+
} | undefined;
|
|
182
|
+
}>;
|
|
62
183
|
|
|
63
184
|
declare abstract class AbstractEngine {
|
|
64
185
|
private _name;
|
|
@@ -141,7 +262,7 @@ declare class TemplateEngineRegistry {
|
|
|
141
262
|
* engine itself with _getEngineByName_ or _getEngineByExtension_
|
|
142
263
|
* and use one of its render methods directly.
|
|
143
264
|
*/
|
|
144
|
-
convert(node:
|
|
265
|
+
convert(node: AbstractBlock, options?: Record<string, unknown>): string | undefined;
|
|
145
266
|
/**
|
|
146
267
|
* Scans the templates directory and creates an index of all templates
|
|
147
268
|
* based on supported block names and extensions.
|
|
@@ -279,6 +400,12 @@ type AsciidocLoader = {
|
|
|
279
400
|
dark: BundledTheme;
|
|
280
401
|
[customTheme: string]: BundledTheme;
|
|
281
402
|
};
|
|
403
|
+
/**
|
|
404
|
+
* A list of transformers to apply for source code blocks.
|
|
405
|
+
*
|
|
406
|
+
* @default [ transformerNotationDiff, transformerNotationHighlight, transformerNotationFocus ]
|
|
407
|
+
*/
|
|
408
|
+
transformers: ShikiTransformer[];
|
|
282
409
|
}>;
|
|
283
410
|
};
|
|
284
411
|
/**
|
|
@@ -305,7 +432,7 @@ interface TemplateModule {
|
|
|
305
432
|
* to the template rendering process.
|
|
306
433
|
*/
|
|
307
434
|
interface AsciidocTemplate {
|
|
308
|
-
renderNode(node:
|
|
435
|
+
renderNode(node: AbstractBlock, options?: Record<string, unknown>): string;
|
|
309
436
|
}
|
|
310
437
|
/**
|
|
311
438
|
* Designates that the template will receive a file location that points
|
package/dist/index.cjs
CHANGED
|
@@ -288,23 +288,23 @@ var AsciidocDocument = class {
|
|
|
288
288
|
};
|
|
289
289
|
|
|
290
290
|
// src/schemas/index.ts
|
|
291
|
-
var import_zod3 = require("zod");
|
|
291
|
+
var import_zod3 = require("astro/zod");
|
|
292
292
|
|
|
293
293
|
// src/schemas/document.ts
|
|
294
294
|
var import_node_path = require("path");
|
|
295
|
-
var import_zod = require("zod");
|
|
296
|
-
var documentOptionsSchema = import_zod.z.
|
|
295
|
+
var import_zod = require("astro/zod");
|
|
296
|
+
var documentOptionsSchema = import_zod.z.object({
|
|
297
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)),
|
|
298
|
+
template: import_zod.z.string().default("").transform((val) => val ? (0, import_node_path.resolve)(process.cwd(), val) : ""),
|
|
299
299
|
recursive: import_zod.z.boolean().default(false)
|
|
300
|
-
}).default({
|
|
300
|
+
}).passthrough().default({
|
|
301
301
|
mode: "safe",
|
|
302
302
|
template: "",
|
|
303
303
|
recursive: false
|
|
304
304
|
});
|
|
305
305
|
|
|
306
306
|
// src/schemas/shiki.ts
|
|
307
|
-
var import_zod2 = require("zod");
|
|
307
|
+
var import_zod2 = require("astro/zod");
|
|
308
308
|
var shikiOptionsSchema = import_zod2.z.object({
|
|
309
309
|
theme: import_zod2.z.union([
|
|
310
310
|
import_zod2.z.string(),
|
|
@@ -319,7 +319,13 @@ var shikiOptionsSchema = import_zod2.z.object({
|
|
|
319
319
|
defaultColor: import_zod2.z.string().default("light-dark()"),
|
|
320
320
|
cssVariablePrefix: import_zod2.z.string().default("--shiki-"),
|
|
321
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)
|
|
322
|
+
tabindex: import_zod2.z.union([import_zod2.z.number(), import_zod2.z.string(), import_zod2.z.literal(false)]).default(false),
|
|
323
|
+
transformers: import_zod2.z.array(
|
|
324
|
+
import_zod2.z.object({
|
|
325
|
+
name: import_zod2.z.string(),
|
|
326
|
+
enforce: import_zod2.z.union([import_zod2.z.literal("pre"), import_zod2.z.literal("post")])
|
|
327
|
+
})
|
|
328
|
+
).optional()
|
|
323
329
|
}).transform(({ theme, ...rest }) => ({
|
|
324
330
|
themes: theme,
|
|
325
331
|
...rest
|
|
@@ -331,7 +337,8 @@ var shikiOptionsSchema = import_zod2.z.object({
|
|
|
331
337
|
theme: {
|
|
332
338
|
light: "catppuccin-latte",
|
|
333
339
|
dark: "catppuccin-macchiato"
|
|
334
|
-
}
|
|
340
|
+
},
|
|
341
|
+
transformers: void 0
|
|
335
342
|
});
|
|
336
343
|
function transformThemeProp(value) {
|
|
337
344
|
return typeof value === "string" ? { light: value, dark: value } : value;
|
|
@@ -376,7 +383,6 @@ async function createHighlighter(documents, themes) {
|
|
|
376
383
|
}
|
|
377
384
|
|
|
378
385
|
// src/lib/asciidoc/converters/sourceCodeConverter.ts
|
|
379
|
-
var import_transformers = require("@shikijs/transformers");
|
|
380
386
|
var import_node_path2 = require("path");
|
|
381
387
|
|
|
382
388
|
// src/lib/shiki/transformers/transformAsciidocCallout.ts
|
|
@@ -470,10 +476,11 @@ function transformConsoleCodeBlock(options = {
|
|
|
470
476
|
}
|
|
471
477
|
|
|
472
478
|
// src/lib/asciidoc/converters/sourceCodeConverter.ts
|
|
473
|
-
var sourceCodeConverter = ({
|
|
479
|
+
var sourceCodeConverter = ({ transformers, template }) => {
|
|
474
480
|
return (options, highlighter) => {
|
|
475
481
|
return {
|
|
476
|
-
nodeContext:
|
|
482
|
+
nodeContext: "listing",
|
|
483
|
+
nodeStyle: "source",
|
|
477
484
|
convert(node, templateEngine) {
|
|
478
485
|
const input = node.getSourceLines().join("\n");
|
|
479
486
|
const lang = node.getAttribute("language");
|
|
@@ -482,9 +489,6 @@ var sourceCodeConverter = ({ nodeContext, transformers, template }) => {
|
|
|
482
489
|
lang,
|
|
483
490
|
transformers: [
|
|
484
491
|
...transformers ?? [],
|
|
485
|
-
(0, import_transformers.transformerNotationDiff)(),
|
|
486
|
-
(0, import_transformers.transformerNotationHighlight)(),
|
|
487
|
-
(0, import_transformers.transformerNotationFocus)(),
|
|
488
492
|
transformAsciidocCallout({ node }),
|
|
489
493
|
transformConsoleCodeBlock()
|
|
490
494
|
]
|
|
@@ -643,9 +647,7 @@ var NunjucksEngine = class extends AbstractEngine {
|
|
|
643
647
|
function asciidocLoader(options) {
|
|
644
648
|
const parsedOpts = loaderOptionsSchema.parse(options);
|
|
645
649
|
if (parsedOpts.document.converters === void 0) {
|
|
646
|
-
parsedOpts.document.converters = [
|
|
647
|
-
sourceCodeConverter({ nodeContext: "listing" })
|
|
648
|
-
];
|
|
650
|
+
parsedOpts.document.converters = [];
|
|
649
651
|
}
|
|
650
652
|
if (parsedOpts.document.templateEngines === void 0) {
|
|
651
653
|
parsedOpts.document.templateEngines = [
|
|
@@ -653,9 +655,12 @@ function asciidocLoader(options) {
|
|
|
653
655
|
new NunjucksEngine()
|
|
654
656
|
];
|
|
655
657
|
}
|
|
658
|
+
let highlighter;
|
|
659
|
+
let templateEngine;
|
|
656
660
|
return {
|
|
657
661
|
name: "asciidoc-loader",
|
|
658
|
-
async load(
|
|
662
|
+
async load(loaderContext) {
|
|
663
|
+
const { config, logger, watcher } = loaderContext;
|
|
659
664
|
const root = config.root.pathname;
|
|
660
665
|
const base = parsedOpts.base.startsWith(".") ? (0, import_node_fs4.realpathSync)(options.base) : root + options.base;
|
|
661
666
|
const docs = (0, import_node_fs4.readdirSync)(base, "utf8").filter((file) => file.match(/(?:\.a(?:scii)?doc)$/)).map((filename) => new AsciidocDocument(`${base}/${filename}`));
|
|
@@ -663,7 +668,6 @@ function asciidocLoader(options) {
|
|
|
663
668
|
logger.warn("No documents found for this collection.");
|
|
664
669
|
return;
|
|
665
670
|
}
|
|
666
|
-
let templateEngine = void 0;
|
|
667
671
|
if (parsedOpts.document.template) {
|
|
668
672
|
templateEngine = new TemplateEngineRegistry(
|
|
669
673
|
parsedOpts.document.templateEngines,
|
|
@@ -674,34 +678,82 @@ function asciidocLoader(options) {
|
|
|
674
678
|
);
|
|
675
679
|
await templateEngine.loadEngines();
|
|
676
680
|
}
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
+
if (!highlighter) {
|
|
682
|
+
highlighter = await createHighlighter(
|
|
683
|
+
docs,
|
|
684
|
+
parsedOpts.syntaxHighlighting.themes
|
|
685
|
+
);
|
|
686
|
+
}
|
|
681
687
|
const converters = parsedOpts.document.converters.map(
|
|
682
688
|
(converter) => converter(parsedOpts, highlighter)
|
|
683
689
|
);
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
690
|
+
const hasSourceCodeConverter = converters.find(
|
|
691
|
+
(converter) => converter.nodeContext === "listing" && converter?.nodeStyle === "source"
|
|
692
|
+
);
|
|
693
|
+
if (!hasSourceCodeConverter) {
|
|
694
|
+
converters.push(
|
|
695
|
+
sourceCodeConverter({
|
|
696
|
+
transformers: parsedOpts.syntaxHighlighting.transformers
|
|
697
|
+
})(parsedOpts, highlighter)
|
|
698
|
+
);
|
|
699
|
+
}
|
|
700
|
+
await Promise.all(
|
|
701
|
+
docs.map(
|
|
702
|
+
(doc) => syncDocument(
|
|
703
|
+
doc,
|
|
704
|
+
converters,
|
|
705
|
+
templateEngine,
|
|
706
|
+
loaderContext
|
|
707
|
+
)
|
|
708
|
+
)
|
|
709
|
+
);
|
|
710
|
+
if (watcher) {
|
|
711
|
+
let handle2 = function() {
|
|
712
|
+
logger.info("Shutting down highlighter instance");
|
|
713
|
+
highlighter.dispose();
|
|
714
|
+
process.exit(0);
|
|
715
|
+
};
|
|
716
|
+
var handle = handle2;
|
|
717
|
+
const watchedFileRegExp = new RegExp(
|
|
718
|
+
`^${base}.*.(a(?:scii)?doc)$`
|
|
719
|
+
);
|
|
720
|
+
console.log(this.name);
|
|
721
|
+
watcher.on("change", async (changedPath) => {
|
|
722
|
+
if (changedPath.match(watchedFileRegExp)) {
|
|
723
|
+
const newDoc = new AsciidocDocument(changedPath);
|
|
724
|
+
await syncDocument(
|
|
725
|
+
newDoc,
|
|
726
|
+
converters,
|
|
727
|
+
templateEngine,
|
|
728
|
+
loaderContext
|
|
729
|
+
);
|
|
698
730
|
}
|
|
699
731
|
});
|
|
700
|
-
|
|
701
|
-
|
|
732
|
+
process.on("SIGINT", handle2);
|
|
733
|
+
process.on("SIGTERM", handle2);
|
|
734
|
+
} else {
|
|
735
|
+
(0, import_node_process.nextTick)(highlighter.dispose);
|
|
736
|
+
}
|
|
702
737
|
}
|
|
703
738
|
};
|
|
704
739
|
}
|
|
740
|
+
async function syncDocument(doc, converters, templateEngine, { parseData, store }) {
|
|
741
|
+
const data = await parseData({
|
|
742
|
+
id: doc.slug,
|
|
743
|
+
data: {
|
|
744
|
+
title: doc.title,
|
|
745
|
+
createdAt: new Date(doc.createdAt),
|
|
746
|
+
description: doc.preamble
|
|
747
|
+
}
|
|
748
|
+
});
|
|
749
|
+
store.set({
|
|
750
|
+
id: doc.slug,
|
|
751
|
+
data,
|
|
752
|
+
rendered: {
|
|
753
|
+
html: doc.convert(converters, templateEngine)
|
|
754
|
+
}
|
|
755
|
+
});
|
|
756
|
+
}
|
|
705
757
|
// Annotate the CommonJS export names for ESM import in node:
|
|
706
758
|
0 && (module.exports = {
|
|
707
759
|
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-BNxO58s3.cjs';
|
|
3
|
+
export { a as AsciidocTemplate, C as CustomConverterFactoryFn, F as FilesystemTemplate, N as NodeContext, R as RawTemplate } from './index-BNxO58s3.cjs';
|
|
4
4
|
import 'shiki';
|
|
5
5
|
import 'asciidoctor';
|
|
6
|
-
import 'zod';
|
|
6
|
+
import 'astro/zod';
|
|
7
7
|
|
|
8
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-BNxO58s3.js';
|
|
3
|
+
export { a as AsciidocTemplate, C as CustomConverterFactoryFn, F as FilesystemTemplate, N as NodeContext, R as RawTemplate } from './index-BNxO58s3.js';
|
|
4
4
|
import 'shiki';
|
|
5
5
|
import 'asciidoctor';
|
|
6
|
-
import 'zod';
|
|
6
|
+
import 'astro/zod';
|
|
7
7
|
|
|
8
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.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
sourceCodeConverter
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-BRMWIQA2.js";
|
|
4
4
|
import {
|
|
5
5
|
slugify,
|
|
6
6
|
splitFilenameComponents
|
|
@@ -247,23 +247,23 @@ var AsciidocDocument = class {
|
|
|
247
247
|
};
|
|
248
248
|
|
|
249
249
|
// src/schemas/index.ts
|
|
250
|
-
import { z as z3 } from "zod";
|
|
250
|
+
import { z as z3 } from "astro/zod";
|
|
251
251
|
|
|
252
252
|
// src/schemas/document.ts
|
|
253
253
|
import { resolve } from "path";
|
|
254
|
-
import { z } from "zod";
|
|
255
|
-
var documentOptionsSchema = z.
|
|
254
|
+
import { z } from "astro/zod";
|
|
255
|
+
var documentOptionsSchema = z.object({
|
|
256
256
|
mode: z.union([z.literal("safe"), z.literal("unsafe")]).default("safe"),
|
|
257
|
-
template: z.string().default("").transform((val) => resolve(process.cwd(), val)),
|
|
257
|
+
template: z.string().default("").transform((val) => val ? resolve(process.cwd(), val) : ""),
|
|
258
258
|
recursive: z.boolean().default(false)
|
|
259
|
-
}).default({
|
|
259
|
+
}).passthrough().default({
|
|
260
260
|
mode: "safe",
|
|
261
261
|
template: "",
|
|
262
262
|
recursive: false
|
|
263
263
|
});
|
|
264
264
|
|
|
265
265
|
// src/schemas/shiki.ts
|
|
266
|
-
import { z as z2 } from "zod";
|
|
266
|
+
import { z as z2 } from "astro/zod";
|
|
267
267
|
var shikiOptionsSchema = z2.object({
|
|
268
268
|
theme: z2.union([
|
|
269
269
|
z2.string(),
|
|
@@ -278,7 +278,13 @@ var shikiOptionsSchema = z2.object({
|
|
|
278
278
|
defaultColor: z2.string().default("light-dark()"),
|
|
279
279
|
cssVariablePrefix: z2.string().default("--shiki-"),
|
|
280
280
|
mergeWhitespaces: z2.union([z2.boolean(), z2.literal("never")]).default(true),
|
|
281
|
-
tabindex: z2.union([z2.number(), z2.string(), z2.literal(false)]).default(false)
|
|
281
|
+
tabindex: z2.union([z2.number(), z2.string(), z2.literal(false)]).default(false),
|
|
282
|
+
transformers: z2.array(
|
|
283
|
+
z2.object({
|
|
284
|
+
name: z2.string(),
|
|
285
|
+
enforce: z2.union([z2.literal("pre"), z2.literal("post")])
|
|
286
|
+
})
|
|
287
|
+
).optional()
|
|
282
288
|
}).transform(({ theme, ...rest }) => ({
|
|
283
289
|
themes: theme,
|
|
284
290
|
...rest
|
|
@@ -290,7 +296,8 @@ var shikiOptionsSchema = z2.object({
|
|
|
290
296
|
theme: {
|
|
291
297
|
light: "catppuccin-latte",
|
|
292
298
|
dark: "catppuccin-macchiato"
|
|
293
|
-
}
|
|
299
|
+
},
|
|
300
|
+
transformers: void 0
|
|
294
301
|
});
|
|
295
302
|
function transformThemeProp(value) {
|
|
296
303
|
return typeof value === "string" ? { light: value, dark: value } : value;
|
|
@@ -338,9 +345,7 @@ async function createHighlighter(documents, themes) {
|
|
|
338
345
|
function asciidocLoader(options) {
|
|
339
346
|
const parsedOpts = loaderOptionsSchema.parse(options);
|
|
340
347
|
if (parsedOpts.document.converters === void 0) {
|
|
341
|
-
parsedOpts.document.converters = [
|
|
342
|
-
sourceCodeConverter({ nodeContext: "listing" })
|
|
343
|
-
];
|
|
348
|
+
parsedOpts.document.converters = [];
|
|
344
349
|
}
|
|
345
350
|
if (parsedOpts.document.templateEngines === void 0) {
|
|
346
351
|
parsedOpts.document.templateEngines = [
|
|
@@ -348,9 +353,12 @@ function asciidocLoader(options) {
|
|
|
348
353
|
new NunjucksEngine()
|
|
349
354
|
];
|
|
350
355
|
}
|
|
356
|
+
let highlighter;
|
|
357
|
+
let templateEngine;
|
|
351
358
|
return {
|
|
352
359
|
name: "asciidoc-loader",
|
|
353
|
-
async load(
|
|
360
|
+
async load(loaderContext) {
|
|
361
|
+
const { config, logger, watcher } = loaderContext;
|
|
354
362
|
const root = config.root.pathname;
|
|
355
363
|
const base = parsedOpts.base.startsWith(".") ? realpathSync(options.base) : root + options.base;
|
|
356
364
|
const docs = readdirSync2(base, "utf8").filter((file) => file.match(/(?:\.a(?:scii)?doc)$/)).map((filename) => new AsciidocDocument(`${base}/${filename}`));
|
|
@@ -358,7 +366,6 @@ function asciidocLoader(options) {
|
|
|
358
366
|
logger.warn("No documents found for this collection.");
|
|
359
367
|
return;
|
|
360
368
|
}
|
|
361
|
-
let templateEngine = void 0;
|
|
362
369
|
if (parsedOpts.document.template) {
|
|
363
370
|
templateEngine = new TemplateEngineRegistry(
|
|
364
371
|
parsedOpts.document.templateEngines,
|
|
@@ -369,34 +376,82 @@ function asciidocLoader(options) {
|
|
|
369
376
|
);
|
|
370
377
|
await templateEngine.loadEngines();
|
|
371
378
|
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
379
|
+
if (!highlighter) {
|
|
380
|
+
highlighter = await createHighlighter(
|
|
381
|
+
docs,
|
|
382
|
+
parsedOpts.syntaxHighlighting.themes
|
|
383
|
+
);
|
|
384
|
+
}
|
|
376
385
|
const converters = parsedOpts.document.converters.map(
|
|
377
386
|
(converter) => converter(parsedOpts, highlighter)
|
|
378
387
|
);
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
388
|
+
const hasSourceCodeConverter = converters.find(
|
|
389
|
+
(converter) => converter.nodeContext === "listing" && converter?.nodeStyle === "source"
|
|
390
|
+
);
|
|
391
|
+
if (!hasSourceCodeConverter) {
|
|
392
|
+
converters.push(
|
|
393
|
+
sourceCodeConverter({
|
|
394
|
+
transformers: parsedOpts.syntaxHighlighting.transformers
|
|
395
|
+
})(parsedOpts, highlighter)
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
await Promise.all(
|
|
399
|
+
docs.map(
|
|
400
|
+
(doc) => syncDocument(
|
|
401
|
+
doc,
|
|
402
|
+
converters,
|
|
403
|
+
templateEngine,
|
|
404
|
+
loaderContext
|
|
405
|
+
)
|
|
406
|
+
)
|
|
407
|
+
);
|
|
408
|
+
if (watcher) {
|
|
409
|
+
let handle2 = function() {
|
|
410
|
+
logger.info("Shutting down highlighter instance");
|
|
411
|
+
highlighter.dispose();
|
|
412
|
+
process.exit(0);
|
|
413
|
+
};
|
|
414
|
+
var handle = handle2;
|
|
415
|
+
const watchedFileRegExp = new RegExp(
|
|
416
|
+
`^${base}.*.(a(?:scii)?doc)$`
|
|
417
|
+
);
|
|
418
|
+
console.log(this.name);
|
|
419
|
+
watcher.on("change", async (changedPath) => {
|
|
420
|
+
if (changedPath.match(watchedFileRegExp)) {
|
|
421
|
+
const newDoc = new AsciidocDocument(changedPath);
|
|
422
|
+
await syncDocument(
|
|
423
|
+
newDoc,
|
|
424
|
+
converters,
|
|
425
|
+
templateEngine,
|
|
426
|
+
loaderContext
|
|
427
|
+
);
|
|
393
428
|
}
|
|
394
429
|
});
|
|
395
|
-
|
|
396
|
-
|
|
430
|
+
process.on("SIGINT", handle2);
|
|
431
|
+
process.on("SIGTERM", handle2);
|
|
432
|
+
} else {
|
|
433
|
+
nextTick(highlighter.dispose);
|
|
434
|
+
}
|
|
397
435
|
}
|
|
398
436
|
};
|
|
399
437
|
}
|
|
438
|
+
async function syncDocument(doc, converters, templateEngine, { parseData, store }) {
|
|
439
|
+
const data = await parseData({
|
|
440
|
+
id: doc.slug,
|
|
441
|
+
data: {
|
|
442
|
+
title: doc.title,
|
|
443
|
+
createdAt: new Date(doc.createdAt),
|
|
444
|
+
description: doc.preamble
|
|
445
|
+
}
|
|
446
|
+
});
|
|
447
|
+
store.set({
|
|
448
|
+
id: doc.slug,
|
|
449
|
+
data,
|
|
450
|
+
rendered: {
|
|
451
|
+
html: doc.convert(converters, templateEngine)
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
}
|
|
400
455
|
export {
|
|
401
456
|
asciidocLoader
|
|
402
457
|
};
|
|
@@ -25,7 +25,6 @@ __export(converters_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(converters_exports);
|
|
26
26
|
|
|
27
27
|
// src/lib/asciidoc/converters/sourceCodeConverter.ts
|
|
28
|
-
var import_transformers = require("@shikijs/transformers");
|
|
29
28
|
var import_node_path = require("path");
|
|
30
29
|
|
|
31
30
|
// src/lib/utils.ts
|
|
@@ -133,10 +132,11 @@ function transformConsoleCodeBlock(options = {
|
|
|
133
132
|
}
|
|
134
133
|
|
|
135
134
|
// src/lib/asciidoc/converters/sourceCodeConverter.ts
|
|
136
|
-
var sourceCodeConverter = ({
|
|
135
|
+
var sourceCodeConverter = ({ transformers, template }) => {
|
|
137
136
|
return (options, highlighter) => {
|
|
138
137
|
return {
|
|
139
|
-
nodeContext:
|
|
138
|
+
nodeContext: "listing",
|
|
139
|
+
nodeStyle: "source",
|
|
140
140
|
convert(node, templateEngine) {
|
|
141
141
|
const input = node.getSourceLines().join("\n");
|
|
142
142
|
const lang = node.getAttribute("language");
|
|
@@ -145,9 +145,6 @@ var sourceCodeConverter = ({ nodeContext, transformers, template }) => {
|
|
|
145
145
|
lang,
|
|
146
146
|
transformers: [
|
|
147
147
|
...transformers ?? [],
|
|
148
|
-
(0, import_transformers.transformerNotationDiff)(),
|
|
149
|
-
(0, import_transformers.transformerNotationHighlight)(),
|
|
150
|
-
(0, import_transformers.transformerNotationFocus)(),
|
|
151
148
|
transformAsciidocCallout({ node }),
|
|
152
149
|
transformConsoleCodeBlock()
|
|
153
150
|
]
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { ShikiTransformer } from 'shiki';
|
|
2
|
-
import { C as CustomConverterFactoryFn
|
|
2
|
+
import { C as CustomConverterFactoryFn } from '../../../index-BNxO58s3.cjs';
|
|
3
3
|
import 'asciidoctor';
|
|
4
|
-
import 'zod';
|
|
4
|
+
import 'astro/zod';
|
|
5
5
|
|
|
6
6
|
type CodeBlockConverterOptions = {
|
|
7
|
-
nodeContext: NodeContext;
|
|
8
7
|
transformers: ShikiTransformer[];
|
|
9
8
|
template: string;
|
|
10
9
|
};
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { ShikiTransformer } from 'shiki';
|
|
2
|
-
import { C as CustomConverterFactoryFn
|
|
2
|
+
import { C as CustomConverterFactoryFn } from '../../../index-BNxO58s3.js';
|
|
3
3
|
import 'asciidoctor';
|
|
4
|
-
import 'zod';
|
|
4
|
+
import 'astro/zod';
|
|
5
5
|
|
|
6
6
|
type CodeBlockConverterOptions = {
|
|
7
|
-
nodeContext: NodeContext;
|
|
8
7
|
transformers: ShikiTransformer[];
|
|
9
8
|
template: string;
|
|
10
9
|
};
|
|
@@ -32,8 +32,7 @@ var engines_exports = {};
|
|
|
32
32
|
__export(engines_exports, {
|
|
33
33
|
AbstractEngine: () => AbstractEngine,
|
|
34
34
|
HandlebarsEngine: () => HandlebarsEngine,
|
|
35
|
-
NunjucksEngine: () => NunjucksEngine
|
|
36
|
-
PhpEngine: () => PhpEngine
|
|
35
|
+
NunjucksEngine: () => NunjucksEngine
|
|
37
36
|
});
|
|
38
37
|
module.exports = __toCommonJS(engines_exports);
|
|
39
38
|
|
|
@@ -163,29 +162,9 @@ var NunjucksEngine = class extends AbstractEngine {
|
|
|
163
162
|
return this.render(str, options);
|
|
164
163
|
}
|
|
165
164
|
};
|
|
166
|
-
|
|
167
|
-
// src/lib/asciidoc/templates/engines/Php.ts
|
|
168
|
-
var import_php_node = require("@platformatic/php-node");
|
|
169
|
-
var PhpEngine = class extends AbstractEngine {
|
|
170
|
-
server;
|
|
171
|
-
constructor(name = "php", extensions = ["php"], docroot) {
|
|
172
|
-
super(name, extensions);
|
|
173
|
-
this.server = new import_php_node.Php({ docroot });
|
|
174
|
-
}
|
|
175
|
-
renderFile(filepath, options) {
|
|
176
|
-
const request = new import_php_node.Request({
|
|
177
|
-
method: "POST",
|
|
178
|
-
url: "http://localhost/" + filepath,
|
|
179
|
-
body: Buffer.from(JSON.stringify(options))
|
|
180
|
-
});
|
|
181
|
-
const response = this.server.handleRequestSync(request);
|
|
182
|
-
return response.body.toString();
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
165
|
// Annotate the CommonJS export names for ESM import in node:
|
|
186
166
|
0 && (module.exports = {
|
|
187
167
|
AbstractEngine,
|
|
188
168
|
HandlebarsEngine,
|
|
189
|
-
NunjucksEngine
|
|
190
|
-
PhpEngine
|
|
169
|
+
NunjucksEngine
|
|
191
170
|
});
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { b as AbstractEngine, a as AsciidocTemplate, T as TemplateModule, F as FilesystemTemplate, R as RawTemplate } from '../../../../index-
|
|
2
|
-
import {
|
|
1
|
+
import { b as AbstractEngine, a as AsciidocTemplate, T as TemplateModule, F as FilesystemTemplate, R as RawTemplate } from '../../../../index-BNxO58s3.cjs';
|
|
2
|
+
import { AbstractBlock } from 'asciidoctor';
|
|
3
3
|
import 'shiki';
|
|
4
|
-
import 'zod';
|
|
4
|
+
import 'astro/zod';
|
|
5
5
|
|
|
6
6
|
declare class HandlebarsEngine extends AbstractEngine implements AsciidocTemplate, TemplateModule, FilesystemTemplate, RawTemplate {
|
|
7
7
|
private render;
|
|
8
8
|
constructor(name?: string, extensions?: string[]);
|
|
9
9
|
load(): Promise<void>;
|
|
10
|
-
renderNode(node:
|
|
10
|
+
renderNode(node: AbstractBlock, options?: Record<string, unknown>): string;
|
|
11
11
|
renderFile(filepath: string, options?: Record<string, unknown>): string;
|
|
12
12
|
renderString(str: string, options?: Record<string, unknown>): string;
|
|
13
13
|
}
|
|
@@ -16,15 +16,9 @@ declare class NunjucksEngine extends AbstractEngine implements AsciidocTemplate,
|
|
|
16
16
|
private render;
|
|
17
17
|
constructor(name?: string, extensions?: string[]);
|
|
18
18
|
load(): Promise<void>;
|
|
19
|
-
renderNode(node:
|
|
19
|
+
renderNode(node: AbstractBlock, options?: Record<string, unknown>): string;
|
|
20
20
|
renderFile(filepath: string, options?: Record<string, unknown>): string;
|
|
21
21
|
renderString(str: string, options?: Record<string, unknown>): string;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
private server;
|
|
26
|
-
constructor(name: string | undefined, extensions: string[] | undefined, docroot: string);
|
|
27
|
-
renderFile(filepath: string, options?: Record<string, unknown>): string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export { AbstractEngine, HandlebarsEngine, NunjucksEngine, PhpEngine };
|
|
24
|
+
export { AbstractEngine, HandlebarsEngine, NunjucksEngine };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { b as AbstractEngine, a as AsciidocTemplate, T as TemplateModule, F as FilesystemTemplate, R as RawTemplate } from '../../../../index-
|
|
2
|
-
import {
|
|
1
|
+
import { b as AbstractEngine, a as AsciidocTemplate, T as TemplateModule, F as FilesystemTemplate, R as RawTemplate } from '../../../../index-BNxO58s3.js';
|
|
2
|
+
import { AbstractBlock } from 'asciidoctor';
|
|
3
3
|
import 'shiki';
|
|
4
|
-
import 'zod';
|
|
4
|
+
import 'astro/zod';
|
|
5
5
|
|
|
6
6
|
declare class HandlebarsEngine extends AbstractEngine implements AsciidocTemplate, TemplateModule, FilesystemTemplate, RawTemplate {
|
|
7
7
|
private render;
|
|
8
8
|
constructor(name?: string, extensions?: string[]);
|
|
9
9
|
load(): Promise<void>;
|
|
10
|
-
renderNode(node:
|
|
10
|
+
renderNode(node: AbstractBlock, options?: Record<string, unknown>): string;
|
|
11
11
|
renderFile(filepath: string, options?: Record<string, unknown>): string;
|
|
12
12
|
renderString(str: string, options?: Record<string, unknown>): string;
|
|
13
13
|
}
|
|
@@ -16,15 +16,9 @@ declare class NunjucksEngine extends AbstractEngine implements AsciidocTemplate,
|
|
|
16
16
|
private render;
|
|
17
17
|
constructor(name?: string, extensions?: string[]);
|
|
18
18
|
load(): Promise<void>;
|
|
19
|
-
renderNode(node:
|
|
19
|
+
renderNode(node: AbstractBlock, options?: Record<string, unknown>): string;
|
|
20
20
|
renderFile(filepath: string, options?: Record<string, unknown>): string;
|
|
21
21
|
renderString(str: string, options?: Record<string, unknown>): string;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
private server;
|
|
26
|
-
constructor(name: string | undefined, extensions: string[] | undefined, docroot: string);
|
|
27
|
-
renderFile(filepath: string, options?: Record<string, unknown>): string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export { AbstractEngine, HandlebarsEngine, NunjucksEngine, PhpEngine };
|
|
24
|
+
export { AbstractEngine, HandlebarsEngine, NunjucksEngine };
|
|
@@ -3,28 +3,8 @@ import {
|
|
|
3
3
|
HandlebarsEngine,
|
|
4
4
|
NunjucksEngine
|
|
5
5
|
} from "../../../../chunk-2F52PMNV.js";
|
|
6
|
-
|
|
7
|
-
// src/lib/asciidoc/templates/engines/Php.ts
|
|
8
|
-
import { Php, Request } from "@platformatic/php-node";
|
|
9
|
-
var PhpEngine = class extends AbstractEngine {
|
|
10
|
-
server;
|
|
11
|
-
constructor(name = "php", extensions = ["php"], docroot) {
|
|
12
|
-
super(name, extensions);
|
|
13
|
-
this.server = new Php({ docroot });
|
|
14
|
-
}
|
|
15
|
-
renderFile(filepath, options) {
|
|
16
|
-
const request = new Request({
|
|
17
|
-
method: "POST",
|
|
18
|
-
url: "http://localhost/" + filepath,
|
|
19
|
-
body: Buffer.from(JSON.stringify(options))
|
|
20
|
-
});
|
|
21
|
-
const response = this.server.handleRequestSync(request);
|
|
22
|
-
return response.body.toString();
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
6
|
export {
|
|
26
7
|
AbstractEngine,
|
|
27
8
|
HandlebarsEngine,
|
|
28
|
-
NunjucksEngine
|
|
29
|
-
PhpEngine
|
|
9
|
+
NunjucksEngine
|
|
30
10
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d10f/asciidoc-astro-loader",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "An Astro collections loader for Asciidoc files",
|
|
5
5
|
"author": "D10f",
|
|
6
6
|
"license": "MIT",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"./transformers": "./dist/lib/shiki/transformers/index.js"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
+
"astro": "^5.15.3",
|
|
39
40
|
"eslint": "^9.36.0",
|
|
40
41
|
"eslint-plugin-prettier": "^5.5.4",
|
|
41
42
|
"globals": "^16.4.0",
|
|
@@ -50,9 +51,9 @@
|
|
|
50
51
|
"dependencies": {
|
|
51
52
|
"@shikijs/transformers": "^3.13.0",
|
|
52
53
|
"asciidoctor": "^3.0.4",
|
|
53
|
-
"
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
"
|
|
54
|
+
"shiki": "^3.13.0"
|
|
55
|
+
},
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"astro": "^5.0.0"
|
|
57
58
|
}
|
|
58
59
|
}
|