@d10f/asciidoc-astro-loader 0.0.1
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/LICENSE +21 -0
- package/README.md +286 -0
- package/dist/chunk-2F52PMNV.js +132 -0
- package/dist/chunk-DDIUST2Z.js +113 -0
- package/dist/chunk-HAZIHU2Y.js +56 -0
- package/dist/index-Cf7MF6tZ.d.cts +325 -0
- package/dist/index-Cf7MF6tZ.d.ts +325 -0
- package/dist/index.cjs +708 -0
- package/dist/index.d.cts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +402 -0
- package/dist/lib/asciidoc/converters/index.cjs +178 -0
- package/dist/lib/asciidoc/converters/index.d.cts +13 -0
- package/dist/lib/asciidoc/converters/index.d.ts +13 -0
- package/dist/lib/asciidoc/converters/index.js +7 -0
- package/dist/lib/asciidoc/templates/engines/index.cjs +191 -0
- package/dist/lib/asciidoc/templates/engines/index.d.cts +30 -0
- package/dist/lib/asciidoc/templates/engines/index.d.ts +30 -0
- package/dist/lib/asciidoc/templates/engines/index.js +30 -0
- package/dist/lib/shiki/transformers/index.cjs +127 -0
- package/dist/lib/shiki/transformers/index.d.cts +59 -0
- package/dist/lib/shiki/transformers/index.d.ts +59 -0
- package/dist/lib/shiki/transformers/index.js +8 -0
- package/package.json +58 -0
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import { HighlighterCore, CodeToHastOptions, CodeOptionsMultipleThemes, ThemeRegistrationAny, StringLiteralUnion, BundledTheme } from 'shiki';
|
|
2
|
+
import { AbstractNode } from 'asciidoctor';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
|
|
5
|
+
type RequiredOptions = z.output<typeof loaderOptionsSchema>;
|
|
6
|
+
type DocumentOptions = RequiredOptions['document'];
|
|
7
|
+
type PreambleOptions = RequiredOptions['preamble'];
|
|
8
|
+
declare const loaderOptionsSchema: z.ZodObject<{
|
|
9
|
+
base: z.ZodString;
|
|
10
|
+
document: z.ZodDefault<z.ZodObject<{
|
|
11
|
+
mode: z.ZodDefault<z.ZodUnion<readonly [z.ZodLiteral<"safe">, z.ZodLiteral<"unsafe">]>>;
|
|
12
|
+
template: z.ZodPipe<z.ZodDefault<z.ZodString>, z.ZodTransform<string, string>>;
|
|
13
|
+
recursive: z.ZodDefault<z.ZodBoolean>;
|
|
14
|
+
}, z.core.$loose>>;
|
|
15
|
+
syntaxHighlighting: z.ZodDefault<z.ZodPipe<z.ZodObject<{
|
|
16
|
+
theme: z.ZodDefault<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
17
|
+
light: z.ZodString;
|
|
18
|
+
dark: z.ZodString;
|
|
19
|
+
}, z.core.$catchall<z.ZodString>>]>, z.ZodTransform<{
|
|
20
|
+
light: string;
|
|
21
|
+
dark: string;
|
|
22
|
+
} & {
|
|
23
|
+
[other: string]: string;
|
|
24
|
+
}, string | {
|
|
25
|
+
[x: string]: string;
|
|
26
|
+
light: string;
|
|
27
|
+
dark: string;
|
|
28
|
+
}>>>;
|
|
29
|
+
defaultColor: z.ZodDefault<z.ZodString>;
|
|
30
|
+
cssVariablePrefix: z.ZodDefault<z.ZodString>;
|
|
31
|
+
mergeWhitespaces: z.ZodDefault<z.ZodUnion<readonly [z.ZodBoolean, z.ZodLiteral<"never">]>>;
|
|
32
|
+
tabindex: z.ZodDefault<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodLiteral<false>]>>;
|
|
33
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
34
|
+
defaultColor: string;
|
|
35
|
+
cssVariablePrefix: string;
|
|
36
|
+
mergeWhitespaces: boolean | "never";
|
|
37
|
+
tabindex: string | number | false;
|
|
38
|
+
themes: {
|
|
39
|
+
light: string;
|
|
40
|
+
dark: string;
|
|
41
|
+
} & {
|
|
42
|
+
[other: string]: string;
|
|
43
|
+
};
|
|
44
|
+
}, {
|
|
45
|
+
theme: {
|
|
46
|
+
light: string;
|
|
47
|
+
dark: string;
|
|
48
|
+
} & {
|
|
49
|
+
[other: string]: string;
|
|
50
|
+
};
|
|
51
|
+
defaultColor: string;
|
|
52
|
+
cssVariablePrefix: string;
|
|
53
|
+
mergeWhitespaces: boolean | "never";
|
|
54
|
+
tabindex: string | number | false;
|
|
55
|
+
}>>>;
|
|
56
|
+
preamble: z.ZodDefault<z.ZodObject<{
|
|
57
|
+
tableOfContents: z.ZodDefault<z.ZodBoolean>;
|
|
58
|
+
maxLevel: z.ZodDefault<z.ZodNumber>;
|
|
59
|
+
position: z.ZodDefault<z.ZodUnion<readonly [z.ZodLiteral<"before">, z.ZodLiteral<"after">]>>;
|
|
60
|
+
}, z.core.$strip>>;
|
|
61
|
+
}, z.core.$strip>;
|
|
62
|
+
|
|
63
|
+
declare abstract class AbstractEngine {
|
|
64
|
+
private _name;
|
|
65
|
+
private _extensions;
|
|
66
|
+
protected templateList: Map<NodeContext, string>;
|
|
67
|
+
constructor(_name: string, _extensions: string[]);
|
|
68
|
+
/**
|
|
69
|
+
* Returns the given name to this template engine.
|
|
70
|
+
*/
|
|
71
|
+
get name(): string;
|
|
72
|
+
/**
|
|
73
|
+
* Returns the list of extensions this template engine supports.
|
|
74
|
+
*/
|
|
75
|
+
get extensions(): string[];
|
|
76
|
+
/**
|
|
77
|
+
* Accessor method to check if instance implements the
|
|
78
|
+
* TemplateModule interface.
|
|
79
|
+
*/
|
|
80
|
+
get canLoad(): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Accessor method to check if instance implements the
|
|
83
|
+
* AsciidocTemplate interface.
|
|
84
|
+
*/
|
|
85
|
+
get canRenderNode(): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Accessor method to check if instance implements the
|
|
88
|
+
* FilesystemTemplate interface.
|
|
89
|
+
*/
|
|
90
|
+
get canRenderFile(): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Accessor method to check if instance implements the
|
|
93
|
+
* RawTemplate interface.
|
|
94
|
+
*/
|
|
95
|
+
get canRenderString(): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Appends a new context that this template engine will act upon.
|
|
98
|
+
*/
|
|
99
|
+
addContext(context: NodeContext, filepath: string): void;
|
|
100
|
+
/**
|
|
101
|
+
* Verifies whether the specified context is being tracked or not.
|
|
102
|
+
*/
|
|
103
|
+
hasContext(context: NodeContext | AbstractNode): boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Verifies if the specified file extension is supported
|
|
106
|
+
* by this template engine.
|
|
107
|
+
*/
|
|
108
|
+
supportsExt(extension: string): boolean;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* A custom template engine that works in-lieu of the default one, which
|
|
113
|
+
* doesn't seem to work when using custom converters.
|
|
114
|
+
*/
|
|
115
|
+
declare class TemplateEngineRegistry {
|
|
116
|
+
/**
|
|
117
|
+
* A list of supported templating engines, their associated extensions
|
|
118
|
+
* and associatied template files to render.
|
|
119
|
+
*/
|
|
120
|
+
private static modules;
|
|
121
|
+
/**
|
|
122
|
+
* A list of all the node existing contexts an Asciidoc node can have.
|
|
123
|
+
*/
|
|
124
|
+
private static nodeContexts;
|
|
125
|
+
constructor(templateEngines: Array<AbstractEngine & AsciidocTemplate>, options: TemplateEngineOptions);
|
|
126
|
+
/**
|
|
127
|
+
* Asynchronously loads the necessary third party modules.
|
|
128
|
+
*/
|
|
129
|
+
loadEngines(): Promise<void>;
|
|
130
|
+
/**
|
|
131
|
+
* Returns the module with the given name.
|
|
132
|
+
*/
|
|
133
|
+
getEngineByName(name: string): (AbstractEngine & AsciidocTemplate) | undefined;
|
|
134
|
+
/**
|
|
135
|
+
* Returns the module that supports the given extension.
|
|
136
|
+
*/
|
|
137
|
+
getEngineByExtension(ext: string): (AbstractEngine & AsciidocTemplate) | undefined;
|
|
138
|
+
/**
|
|
139
|
+
* Converts the provided node using one of the registered template
|
|
140
|
+
* engine modules. For more granular control, gain access to the
|
|
141
|
+
* engine itself with _getEngineByName_ or _getEngineByExtension_
|
|
142
|
+
* and use one of its render methods directly.
|
|
143
|
+
*/
|
|
144
|
+
convert(node: AbstractNode, options?: Record<string, unknown>): string | undefined;
|
|
145
|
+
/**
|
|
146
|
+
* Scans the templates directory and creates an index of all templates
|
|
147
|
+
* based on supported block names and extensions.
|
|
148
|
+
*
|
|
149
|
+
* @see https://docs.asciidoctor.org/asciidoctor.js/latest/extend/converter/template-converter/#naming-convention
|
|
150
|
+
*/
|
|
151
|
+
private loadTemplates;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
type CustomConverter = {
|
|
155
|
+
/**
|
|
156
|
+
* The node context, or node type, that this converter will act upon.
|
|
157
|
+
*/
|
|
158
|
+
readonly nodeContext: NodeContext;
|
|
159
|
+
readonly nodeStyle?: string;
|
|
160
|
+
/**
|
|
161
|
+
* Path location to a template to be used for the current converter. When
|
|
162
|
+
* provided, it will take precedence over any default templates found.
|
|
163
|
+
*/
|
|
164
|
+
template?: string;
|
|
165
|
+
/**
|
|
166
|
+
* Converts the given node.
|
|
167
|
+
*
|
|
168
|
+
* @param node the current node to convert
|
|
169
|
+
* @param templateEngine entrypoint to the template engine
|
|
170
|
+
* @returns an HTML string representing the node.
|
|
171
|
+
*/
|
|
172
|
+
convert(node: AbstractNode, templateEngine?: TemplateEngineRegistry): string | null | undefined;
|
|
173
|
+
};
|
|
174
|
+
type CustomConverterFactoryFn<T extends object | undefined> = (converterOptions: T) => CustomConverterFn;
|
|
175
|
+
type CustomConverterFn = (opts: RequiredOptions, highlighter: HighlighterCore) => CustomConverter;
|
|
176
|
+
type AsciidocLoader = {
|
|
177
|
+
/**
|
|
178
|
+
* Path to the Asciidoc documents to parse.
|
|
179
|
+
*/
|
|
180
|
+
base: string;
|
|
181
|
+
/**
|
|
182
|
+
* Options for the Asciidoctor parser.
|
|
183
|
+
*/
|
|
184
|
+
document?: Partial<{
|
|
185
|
+
/**
|
|
186
|
+
* The mode of operation for Asciidoctor.
|
|
187
|
+
*/
|
|
188
|
+
mode: DocumentOptions['mode'];
|
|
189
|
+
/**
|
|
190
|
+
* List of converters to use to parse the current document.
|
|
191
|
+
*/
|
|
192
|
+
converters: CustomConverterFn[];
|
|
193
|
+
/**
|
|
194
|
+
* List of file system locations to templates to use when converting an
|
|
195
|
+
* Asciidoc document.
|
|
196
|
+
*/
|
|
197
|
+
template: string;
|
|
198
|
+
/**
|
|
199
|
+
* Whether to search on sub-folders on the given template location
|
|
200
|
+
* for additional templates.
|
|
201
|
+
*/
|
|
202
|
+
recursive: boolean;
|
|
203
|
+
/**
|
|
204
|
+
* List of custom template engines to use when producing the HTML5
|
|
205
|
+
* output for a given block. By default, *handlebars* and *nunjucks*
|
|
206
|
+
* are available.
|
|
207
|
+
*
|
|
208
|
+
* @default [new HandlebarsEngine(), new NunjucksEngine()]
|
|
209
|
+
*/
|
|
210
|
+
templateEngines: Array<AbstractEngine & AsciidocTemplate>;
|
|
211
|
+
}>;
|
|
212
|
+
/**
|
|
213
|
+
* Options provided for the output of the preamble section, when
|
|
214
|
+
* there is one present in the parsed document.
|
|
215
|
+
*/
|
|
216
|
+
preamble?: Partial<{
|
|
217
|
+
/**
|
|
218
|
+
* Whether to display the table of contents or not.
|
|
219
|
+
*
|
|
220
|
+
* @default true
|
|
221
|
+
*/
|
|
222
|
+
tableOfContents: PreambleOptions['tableOfContents'];
|
|
223
|
+
/**
|
|
224
|
+
* How many levels of headings to include in the table of contents.
|
|
225
|
+
*
|
|
226
|
+
* @default 3
|
|
227
|
+
*/
|
|
228
|
+
maxLevel: PreambleOptions['maxLevel'];
|
|
229
|
+
/**
|
|
230
|
+
* Whether to place the table of contents before or after the preamble, if
|
|
231
|
+
* there is one.
|
|
232
|
+
*
|
|
233
|
+
* @default "after"
|
|
234
|
+
*/
|
|
235
|
+
position: PreambleOptions['position'];
|
|
236
|
+
}>;
|
|
237
|
+
/**
|
|
238
|
+
* Options for the Shiki highlighter.
|
|
239
|
+
*/
|
|
240
|
+
syntaxHighlighting?: Partial<Pick<CodeToHastOptions, 'mergeWhitespaces' | 'tabindex'> & Pick<CodeOptionsMultipleThemes, 'cssVariablePrefix'> & {
|
|
241
|
+
/**
|
|
242
|
+
* The default theme applied to the code (via inline `color` style).
|
|
243
|
+
* The rest of the themes are applied via CSS variables, and toggled by CSS overrides.
|
|
244
|
+
*
|
|
245
|
+
* For example, if `defaultColor` is `light`, then `light` theme is applied to the code,
|
|
246
|
+
* and the `dark` theme and other custom themes are applied via CSS variables:
|
|
247
|
+
*
|
|
248
|
+
* ```html
|
|
249
|
+
* <span style="color:#{light};--shiki-dark:#{dark};--shiki-custom:#{custom};">code</span>
|
|
250
|
+
* ```
|
|
251
|
+
*
|
|
252
|
+
* When set to `false`, no default styles will be applied, and totally up to users to apply the styles:
|
|
253
|
+
*
|
|
254
|
+
* ```html
|
|
255
|
+
* <span style="--shiki-light:#{light};--shiki-dark:#{dark};--shiki-custom:#{custom};">code</span>
|
|
256
|
+
* ```
|
|
257
|
+
*
|
|
258
|
+
* When set to `light-dark()`, the default color will be rendered as `light-dark(#{light}, #{dark})`.
|
|
259
|
+
*
|
|
260
|
+
* ```html
|
|
261
|
+
* <span style="color:light-dark(#{light}, #{dark});--shiki-dark:#{dark};--shiki-custom:#{custom};">code</span>
|
|
262
|
+
* ```
|
|
263
|
+
*
|
|
264
|
+
* @default 'light-dark()'
|
|
265
|
+
*/
|
|
266
|
+
defaultColor: Partial<Record<string, ThemeRegistrationAny | StringLiteralUnion<string>>>;
|
|
267
|
+
/**
|
|
268
|
+
* The syntax highlighter theme to use. It can be either a
|
|
269
|
+
* string that will apply for both light and dark mode by
|
|
270
|
+
* default (see defaultColor option), or an object with both
|
|
271
|
+
* "light" and "dark" properties. When passed as an object, it
|
|
272
|
+
* can have any arbitrary number of additional properties used
|
|
273
|
+
* to define custom themes.
|
|
274
|
+
*
|
|
275
|
+
* @default { light: 'catppuccin-latte', dark: 'catppuccin-macchiato' }
|
|
276
|
+
*/
|
|
277
|
+
theme: BundledTheme | {
|
|
278
|
+
light: BundledTheme;
|
|
279
|
+
dark: BundledTheme;
|
|
280
|
+
[customTheme: string]: BundledTheme;
|
|
281
|
+
};
|
|
282
|
+
}>;
|
|
283
|
+
};
|
|
284
|
+
/**
|
|
285
|
+
* The types of context that an Asciidoc block can be.
|
|
286
|
+
*/
|
|
287
|
+
type NodeContext = 'admonition' | 'audio' | 'colist' | 'dlist' | 'document' | 'embedded' | 'example' | 'floating-title' | 'image' | 'inline_anchor' | 'inline_break' | 'inline_button' | 'inline_callout' | 'inline_footnote' | 'inline_image' | 'inline_indexterm' | 'inline_kbd' | 'inline_menu' | 'inline_quoted' | 'listing' | 'literal' | 'olist' | 'open' | 'outline' | 'page_break' | 'paragraph' | 'preamble' | 'quote' | 'section' | 'sidebar' | 'stem' | 'table' | 'thematic_break' | 'toc' | 'ulist' | 'verse' | 'video';
|
|
288
|
+
type TemplateEngineOptions = {
|
|
289
|
+
rootDir: string;
|
|
290
|
+
recursive: boolean;
|
|
291
|
+
};
|
|
292
|
+
/**
|
|
293
|
+
* For engines that are modular and require third-party libraries like
|
|
294
|
+
* handlebars, nunjucks, etc.
|
|
295
|
+
*/
|
|
296
|
+
interface TemplateModule {
|
|
297
|
+
/**
|
|
298
|
+
* Loader function to import third-party modules asynchronously.
|
|
299
|
+
*/
|
|
300
|
+
load(): Promise<void>;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Interface used by the default template engine, which can handle
|
|
304
|
+
* Asciidoctor.js' blocks directly. It should be the main entrypoint
|
|
305
|
+
* to the template rendering process.
|
|
306
|
+
*/
|
|
307
|
+
interface AsciidocTemplate {
|
|
308
|
+
renderNode(node: AbstractNode, options?: Record<string, unknown>): string;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Designates that the template will receive a file location that points
|
|
312
|
+
* to the template to render.
|
|
313
|
+
*/
|
|
314
|
+
interface FilesystemTemplate {
|
|
315
|
+
renderFile(filepath: string, options?: Record<string, unknown>): string;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Designates that the template will receive a string with the contents
|
|
319
|
+
* of the template, instead of a location to the template itself.
|
|
320
|
+
*/
|
|
321
|
+
interface RawTemplate {
|
|
322
|
+
renderString(content: string, options?: Record<string, unknown>): string;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
export { type AsciidocLoader as A, type CustomConverterFactoryFn as C, type FilesystemTemplate as F, type NodeContext as N, type RawTemplate as R, type TemplateModule as T, type AsciidocTemplate as a, AbstractEngine as b };
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import { HighlighterCore, CodeToHastOptions, CodeOptionsMultipleThemes, ThemeRegistrationAny, StringLiteralUnion, BundledTheme } from 'shiki';
|
|
2
|
+
import { AbstractNode } from 'asciidoctor';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
|
|
5
|
+
type RequiredOptions = z.output<typeof loaderOptionsSchema>;
|
|
6
|
+
type DocumentOptions = RequiredOptions['document'];
|
|
7
|
+
type PreambleOptions = RequiredOptions['preamble'];
|
|
8
|
+
declare const loaderOptionsSchema: z.ZodObject<{
|
|
9
|
+
base: z.ZodString;
|
|
10
|
+
document: z.ZodDefault<z.ZodObject<{
|
|
11
|
+
mode: z.ZodDefault<z.ZodUnion<readonly [z.ZodLiteral<"safe">, z.ZodLiteral<"unsafe">]>>;
|
|
12
|
+
template: z.ZodPipe<z.ZodDefault<z.ZodString>, z.ZodTransform<string, string>>;
|
|
13
|
+
recursive: z.ZodDefault<z.ZodBoolean>;
|
|
14
|
+
}, z.core.$loose>>;
|
|
15
|
+
syntaxHighlighting: z.ZodDefault<z.ZodPipe<z.ZodObject<{
|
|
16
|
+
theme: z.ZodDefault<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
17
|
+
light: z.ZodString;
|
|
18
|
+
dark: z.ZodString;
|
|
19
|
+
}, z.core.$catchall<z.ZodString>>]>, z.ZodTransform<{
|
|
20
|
+
light: string;
|
|
21
|
+
dark: string;
|
|
22
|
+
} & {
|
|
23
|
+
[other: string]: string;
|
|
24
|
+
}, string | {
|
|
25
|
+
[x: string]: string;
|
|
26
|
+
light: string;
|
|
27
|
+
dark: string;
|
|
28
|
+
}>>>;
|
|
29
|
+
defaultColor: z.ZodDefault<z.ZodString>;
|
|
30
|
+
cssVariablePrefix: z.ZodDefault<z.ZodString>;
|
|
31
|
+
mergeWhitespaces: z.ZodDefault<z.ZodUnion<readonly [z.ZodBoolean, z.ZodLiteral<"never">]>>;
|
|
32
|
+
tabindex: z.ZodDefault<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodLiteral<false>]>>;
|
|
33
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
34
|
+
defaultColor: string;
|
|
35
|
+
cssVariablePrefix: string;
|
|
36
|
+
mergeWhitespaces: boolean | "never";
|
|
37
|
+
tabindex: string | number | false;
|
|
38
|
+
themes: {
|
|
39
|
+
light: string;
|
|
40
|
+
dark: string;
|
|
41
|
+
} & {
|
|
42
|
+
[other: string]: string;
|
|
43
|
+
};
|
|
44
|
+
}, {
|
|
45
|
+
theme: {
|
|
46
|
+
light: string;
|
|
47
|
+
dark: string;
|
|
48
|
+
} & {
|
|
49
|
+
[other: string]: string;
|
|
50
|
+
};
|
|
51
|
+
defaultColor: string;
|
|
52
|
+
cssVariablePrefix: string;
|
|
53
|
+
mergeWhitespaces: boolean | "never";
|
|
54
|
+
tabindex: string | number | false;
|
|
55
|
+
}>>>;
|
|
56
|
+
preamble: z.ZodDefault<z.ZodObject<{
|
|
57
|
+
tableOfContents: z.ZodDefault<z.ZodBoolean>;
|
|
58
|
+
maxLevel: z.ZodDefault<z.ZodNumber>;
|
|
59
|
+
position: z.ZodDefault<z.ZodUnion<readonly [z.ZodLiteral<"before">, z.ZodLiteral<"after">]>>;
|
|
60
|
+
}, z.core.$strip>>;
|
|
61
|
+
}, z.core.$strip>;
|
|
62
|
+
|
|
63
|
+
declare abstract class AbstractEngine {
|
|
64
|
+
private _name;
|
|
65
|
+
private _extensions;
|
|
66
|
+
protected templateList: Map<NodeContext, string>;
|
|
67
|
+
constructor(_name: string, _extensions: string[]);
|
|
68
|
+
/**
|
|
69
|
+
* Returns the given name to this template engine.
|
|
70
|
+
*/
|
|
71
|
+
get name(): string;
|
|
72
|
+
/**
|
|
73
|
+
* Returns the list of extensions this template engine supports.
|
|
74
|
+
*/
|
|
75
|
+
get extensions(): string[];
|
|
76
|
+
/**
|
|
77
|
+
* Accessor method to check if instance implements the
|
|
78
|
+
* TemplateModule interface.
|
|
79
|
+
*/
|
|
80
|
+
get canLoad(): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Accessor method to check if instance implements the
|
|
83
|
+
* AsciidocTemplate interface.
|
|
84
|
+
*/
|
|
85
|
+
get canRenderNode(): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Accessor method to check if instance implements the
|
|
88
|
+
* FilesystemTemplate interface.
|
|
89
|
+
*/
|
|
90
|
+
get canRenderFile(): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Accessor method to check if instance implements the
|
|
93
|
+
* RawTemplate interface.
|
|
94
|
+
*/
|
|
95
|
+
get canRenderString(): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Appends a new context that this template engine will act upon.
|
|
98
|
+
*/
|
|
99
|
+
addContext(context: NodeContext, filepath: string): void;
|
|
100
|
+
/**
|
|
101
|
+
* Verifies whether the specified context is being tracked or not.
|
|
102
|
+
*/
|
|
103
|
+
hasContext(context: NodeContext | AbstractNode): boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Verifies if the specified file extension is supported
|
|
106
|
+
* by this template engine.
|
|
107
|
+
*/
|
|
108
|
+
supportsExt(extension: string): boolean;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* A custom template engine that works in-lieu of the default one, which
|
|
113
|
+
* doesn't seem to work when using custom converters.
|
|
114
|
+
*/
|
|
115
|
+
declare class TemplateEngineRegistry {
|
|
116
|
+
/**
|
|
117
|
+
* A list of supported templating engines, their associated extensions
|
|
118
|
+
* and associatied template files to render.
|
|
119
|
+
*/
|
|
120
|
+
private static modules;
|
|
121
|
+
/**
|
|
122
|
+
* A list of all the node existing contexts an Asciidoc node can have.
|
|
123
|
+
*/
|
|
124
|
+
private static nodeContexts;
|
|
125
|
+
constructor(templateEngines: Array<AbstractEngine & AsciidocTemplate>, options: TemplateEngineOptions);
|
|
126
|
+
/**
|
|
127
|
+
* Asynchronously loads the necessary third party modules.
|
|
128
|
+
*/
|
|
129
|
+
loadEngines(): Promise<void>;
|
|
130
|
+
/**
|
|
131
|
+
* Returns the module with the given name.
|
|
132
|
+
*/
|
|
133
|
+
getEngineByName(name: string): (AbstractEngine & AsciidocTemplate) | undefined;
|
|
134
|
+
/**
|
|
135
|
+
* Returns the module that supports the given extension.
|
|
136
|
+
*/
|
|
137
|
+
getEngineByExtension(ext: string): (AbstractEngine & AsciidocTemplate) | undefined;
|
|
138
|
+
/**
|
|
139
|
+
* Converts the provided node using one of the registered template
|
|
140
|
+
* engine modules. For more granular control, gain access to the
|
|
141
|
+
* engine itself with _getEngineByName_ or _getEngineByExtension_
|
|
142
|
+
* and use one of its render methods directly.
|
|
143
|
+
*/
|
|
144
|
+
convert(node: AbstractNode, options?: Record<string, unknown>): string | undefined;
|
|
145
|
+
/**
|
|
146
|
+
* Scans the templates directory and creates an index of all templates
|
|
147
|
+
* based on supported block names and extensions.
|
|
148
|
+
*
|
|
149
|
+
* @see https://docs.asciidoctor.org/asciidoctor.js/latest/extend/converter/template-converter/#naming-convention
|
|
150
|
+
*/
|
|
151
|
+
private loadTemplates;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
type CustomConverter = {
|
|
155
|
+
/**
|
|
156
|
+
* The node context, or node type, that this converter will act upon.
|
|
157
|
+
*/
|
|
158
|
+
readonly nodeContext: NodeContext;
|
|
159
|
+
readonly nodeStyle?: string;
|
|
160
|
+
/**
|
|
161
|
+
* Path location to a template to be used for the current converter. When
|
|
162
|
+
* provided, it will take precedence over any default templates found.
|
|
163
|
+
*/
|
|
164
|
+
template?: string;
|
|
165
|
+
/**
|
|
166
|
+
* Converts the given node.
|
|
167
|
+
*
|
|
168
|
+
* @param node the current node to convert
|
|
169
|
+
* @param templateEngine entrypoint to the template engine
|
|
170
|
+
* @returns an HTML string representing the node.
|
|
171
|
+
*/
|
|
172
|
+
convert(node: AbstractNode, templateEngine?: TemplateEngineRegistry): string | null | undefined;
|
|
173
|
+
};
|
|
174
|
+
type CustomConverterFactoryFn<T extends object | undefined> = (converterOptions: T) => CustomConverterFn;
|
|
175
|
+
type CustomConverterFn = (opts: RequiredOptions, highlighter: HighlighterCore) => CustomConverter;
|
|
176
|
+
type AsciidocLoader = {
|
|
177
|
+
/**
|
|
178
|
+
* Path to the Asciidoc documents to parse.
|
|
179
|
+
*/
|
|
180
|
+
base: string;
|
|
181
|
+
/**
|
|
182
|
+
* Options for the Asciidoctor parser.
|
|
183
|
+
*/
|
|
184
|
+
document?: Partial<{
|
|
185
|
+
/**
|
|
186
|
+
* The mode of operation for Asciidoctor.
|
|
187
|
+
*/
|
|
188
|
+
mode: DocumentOptions['mode'];
|
|
189
|
+
/**
|
|
190
|
+
* List of converters to use to parse the current document.
|
|
191
|
+
*/
|
|
192
|
+
converters: CustomConverterFn[];
|
|
193
|
+
/**
|
|
194
|
+
* List of file system locations to templates to use when converting an
|
|
195
|
+
* Asciidoc document.
|
|
196
|
+
*/
|
|
197
|
+
template: string;
|
|
198
|
+
/**
|
|
199
|
+
* Whether to search on sub-folders on the given template location
|
|
200
|
+
* for additional templates.
|
|
201
|
+
*/
|
|
202
|
+
recursive: boolean;
|
|
203
|
+
/**
|
|
204
|
+
* List of custom template engines to use when producing the HTML5
|
|
205
|
+
* output for a given block. By default, *handlebars* and *nunjucks*
|
|
206
|
+
* are available.
|
|
207
|
+
*
|
|
208
|
+
* @default [new HandlebarsEngine(), new NunjucksEngine()]
|
|
209
|
+
*/
|
|
210
|
+
templateEngines: Array<AbstractEngine & AsciidocTemplate>;
|
|
211
|
+
}>;
|
|
212
|
+
/**
|
|
213
|
+
* Options provided for the output of the preamble section, when
|
|
214
|
+
* there is one present in the parsed document.
|
|
215
|
+
*/
|
|
216
|
+
preamble?: Partial<{
|
|
217
|
+
/**
|
|
218
|
+
* Whether to display the table of contents or not.
|
|
219
|
+
*
|
|
220
|
+
* @default true
|
|
221
|
+
*/
|
|
222
|
+
tableOfContents: PreambleOptions['tableOfContents'];
|
|
223
|
+
/**
|
|
224
|
+
* How many levels of headings to include in the table of contents.
|
|
225
|
+
*
|
|
226
|
+
* @default 3
|
|
227
|
+
*/
|
|
228
|
+
maxLevel: PreambleOptions['maxLevel'];
|
|
229
|
+
/**
|
|
230
|
+
* Whether to place the table of contents before or after the preamble, if
|
|
231
|
+
* there is one.
|
|
232
|
+
*
|
|
233
|
+
* @default "after"
|
|
234
|
+
*/
|
|
235
|
+
position: PreambleOptions['position'];
|
|
236
|
+
}>;
|
|
237
|
+
/**
|
|
238
|
+
* Options for the Shiki highlighter.
|
|
239
|
+
*/
|
|
240
|
+
syntaxHighlighting?: Partial<Pick<CodeToHastOptions, 'mergeWhitespaces' | 'tabindex'> & Pick<CodeOptionsMultipleThemes, 'cssVariablePrefix'> & {
|
|
241
|
+
/**
|
|
242
|
+
* The default theme applied to the code (via inline `color` style).
|
|
243
|
+
* The rest of the themes are applied via CSS variables, and toggled by CSS overrides.
|
|
244
|
+
*
|
|
245
|
+
* For example, if `defaultColor` is `light`, then `light` theme is applied to the code,
|
|
246
|
+
* and the `dark` theme and other custom themes are applied via CSS variables:
|
|
247
|
+
*
|
|
248
|
+
* ```html
|
|
249
|
+
* <span style="color:#{light};--shiki-dark:#{dark};--shiki-custom:#{custom};">code</span>
|
|
250
|
+
* ```
|
|
251
|
+
*
|
|
252
|
+
* When set to `false`, no default styles will be applied, and totally up to users to apply the styles:
|
|
253
|
+
*
|
|
254
|
+
* ```html
|
|
255
|
+
* <span style="--shiki-light:#{light};--shiki-dark:#{dark};--shiki-custom:#{custom};">code</span>
|
|
256
|
+
* ```
|
|
257
|
+
*
|
|
258
|
+
* When set to `light-dark()`, the default color will be rendered as `light-dark(#{light}, #{dark})`.
|
|
259
|
+
*
|
|
260
|
+
* ```html
|
|
261
|
+
* <span style="color:light-dark(#{light}, #{dark});--shiki-dark:#{dark};--shiki-custom:#{custom};">code</span>
|
|
262
|
+
* ```
|
|
263
|
+
*
|
|
264
|
+
* @default 'light-dark()'
|
|
265
|
+
*/
|
|
266
|
+
defaultColor: Partial<Record<string, ThemeRegistrationAny | StringLiteralUnion<string>>>;
|
|
267
|
+
/**
|
|
268
|
+
* The syntax highlighter theme to use. It can be either a
|
|
269
|
+
* string that will apply for both light and dark mode by
|
|
270
|
+
* default (see defaultColor option), or an object with both
|
|
271
|
+
* "light" and "dark" properties. When passed as an object, it
|
|
272
|
+
* can have any arbitrary number of additional properties used
|
|
273
|
+
* to define custom themes.
|
|
274
|
+
*
|
|
275
|
+
* @default { light: 'catppuccin-latte', dark: 'catppuccin-macchiato' }
|
|
276
|
+
*/
|
|
277
|
+
theme: BundledTheme | {
|
|
278
|
+
light: BundledTheme;
|
|
279
|
+
dark: BundledTheme;
|
|
280
|
+
[customTheme: string]: BundledTheme;
|
|
281
|
+
};
|
|
282
|
+
}>;
|
|
283
|
+
};
|
|
284
|
+
/**
|
|
285
|
+
* The types of context that an Asciidoc block can be.
|
|
286
|
+
*/
|
|
287
|
+
type NodeContext = 'admonition' | 'audio' | 'colist' | 'dlist' | 'document' | 'embedded' | 'example' | 'floating-title' | 'image' | 'inline_anchor' | 'inline_break' | 'inline_button' | 'inline_callout' | 'inline_footnote' | 'inline_image' | 'inline_indexterm' | 'inline_kbd' | 'inline_menu' | 'inline_quoted' | 'listing' | 'literal' | 'olist' | 'open' | 'outline' | 'page_break' | 'paragraph' | 'preamble' | 'quote' | 'section' | 'sidebar' | 'stem' | 'table' | 'thematic_break' | 'toc' | 'ulist' | 'verse' | 'video';
|
|
288
|
+
type TemplateEngineOptions = {
|
|
289
|
+
rootDir: string;
|
|
290
|
+
recursive: boolean;
|
|
291
|
+
};
|
|
292
|
+
/**
|
|
293
|
+
* For engines that are modular and require third-party libraries like
|
|
294
|
+
* handlebars, nunjucks, etc.
|
|
295
|
+
*/
|
|
296
|
+
interface TemplateModule {
|
|
297
|
+
/**
|
|
298
|
+
* Loader function to import third-party modules asynchronously.
|
|
299
|
+
*/
|
|
300
|
+
load(): Promise<void>;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Interface used by the default template engine, which can handle
|
|
304
|
+
* Asciidoctor.js' blocks directly. It should be the main entrypoint
|
|
305
|
+
* to the template rendering process.
|
|
306
|
+
*/
|
|
307
|
+
interface AsciidocTemplate {
|
|
308
|
+
renderNode(node: AbstractNode, options?: Record<string, unknown>): string;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Designates that the template will receive a file location that points
|
|
312
|
+
* to the template to render.
|
|
313
|
+
*/
|
|
314
|
+
interface FilesystemTemplate {
|
|
315
|
+
renderFile(filepath: string, options?: Record<string, unknown>): string;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Designates that the template will receive a string with the contents
|
|
319
|
+
* of the template, instead of a location to the template itself.
|
|
320
|
+
*/
|
|
321
|
+
interface RawTemplate {
|
|
322
|
+
renderString(content: string, options?: Record<string, unknown>): string;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
export { type AsciidocLoader as A, type CustomConverterFactoryFn as C, type FilesystemTemplate as F, type NodeContext as N, type RawTemplate as R, type TemplateModule as T, type AsciidocTemplate as a, AbstractEngine as b };
|