@d10f/asciidoc-astro-loader 0.2.0 → 0.3.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/dist/{chunk-2UGTFP4R.js → chunk-37PTJDHV.js} +14 -2
- package/dist/{chunk-TCLZUBH3.js → chunk-FVYBQ3D5.js} +2 -2
- package/dist/{chunk-SUQERYPQ.js → chunk-YJTKOSBY.js} +1 -1
- package/dist/{index-B1d5alka.d.ts → index-CA5P6VBa.d.cts} +35 -4
- package/dist/{index-B1d5alka.d.cts → index-CA5P6VBa.d.ts} +35 -4
- package/dist/index.cjs +43 -16
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +36 -19
- package/dist/lib/asciidoc/converters/index.cjs +5 -3
- 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 +2 -2
- package/dist/lib/asciidoc/templates/engines/index.d.cts +1 -1
- package/dist/lib/asciidoc/templates/engines/index.d.ts +1 -1
- package/dist/lib/shiki/transformers/index.cjs +4 -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 +2 -2
- package/package.json +3 -2
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
// src/
|
|
1
|
+
// src/utils.ts
|
|
2
|
+
import { resolve } from "path";
|
|
3
|
+
import { glob } from "tinyglobby";
|
|
2
4
|
function slugify(text) {
|
|
3
5
|
return text.trim().normalize().toLowerCase().replace(/\s+/g, "-").replace(/[^\w-]+/g, "").replace(/--+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
|
|
4
6
|
}
|
|
@@ -14,9 +16,19 @@ function splitFilenameComponents(filename) {
|
|
|
14
16
|
extension: match?.groups?.ext ?? null
|
|
15
17
|
};
|
|
16
18
|
}
|
|
19
|
+
function walk(root, pattern) {
|
|
20
|
+
const dirPath = resolve(root);
|
|
21
|
+
return glob(pattern, {
|
|
22
|
+
cwd: dirPath,
|
|
23
|
+
absolute: true,
|
|
24
|
+
expandDirectories: false,
|
|
25
|
+
followSymbolicLinks: true
|
|
26
|
+
});
|
|
27
|
+
}
|
|
17
28
|
|
|
18
29
|
export {
|
|
19
30
|
slugify,
|
|
20
31
|
escapeRegexCharacters,
|
|
21
|
-
splitFilenameComponents
|
|
32
|
+
splitFilenameComponents,
|
|
33
|
+
walk
|
|
22
34
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
escapeRegexCharacters
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-37PTJDHV.js";
|
|
4
4
|
|
|
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));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { HighlighterCore, CodeToHastOptions, CodeOptionsMultipleThemes, StringLiteralUnion, BundledTheme, ShikiTransformer } from 'shiki';
|
|
2
|
-
import { AbstractNode, AbstractBlock } from 'asciidoctor';
|
|
1
|
+
import { BundledLanguage, HighlighterCore, CodeToHastOptions, CodeOptionsMultipleThemes, StringLiteralUnion, BundledTheme, ShikiTransformer } from 'shiki';
|
|
2
|
+
import { AbstractNode, AbstractBlock, Document } from 'asciidoctor';
|
|
3
3
|
import { z } from 'astro/zod';
|
|
4
4
|
|
|
5
5
|
type RequiredOptions = z.output<typeof loaderOptionsSchema>;
|
|
@@ -7,6 +7,7 @@ type DocumentOptions = RequiredOptions['document'];
|
|
|
7
7
|
type PreambleOptions = RequiredOptions['preamble'];
|
|
8
8
|
declare const loaderOptionsSchema: z.ZodObject<{
|
|
9
9
|
base: z.ZodString;
|
|
10
|
+
pattern: z.ZodDefault<z.ZodString>;
|
|
10
11
|
images: z.ZodOptional<z.ZodObject<{
|
|
11
12
|
imageDir: z.ZodOptional<z.ZodString>;
|
|
12
13
|
imageUrl: z.ZodOptional<z.ZodString>;
|
|
@@ -169,6 +170,27 @@ declare class TemplateEngineRegistry {
|
|
|
169
170
|
private loadTemplates;
|
|
170
171
|
}
|
|
171
172
|
|
|
173
|
+
declare class AsciidocDocument {
|
|
174
|
+
private document;
|
|
175
|
+
private baseConverter;
|
|
176
|
+
constructor(filepath: string);
|
|
177
|
+
private get documentTitle();
|
|
178
|
+
get attributes(): any;
|
|
179
|
+
get title(): string;
|
|
180
|
+
get subtitle(): string;
|
|
181
|
+
get slug(): string;
|
|
182
|
+
get preamble(): string | undefined;
|
|
183
|
+
get description(): string;
|
|
184
|
+
get author(): string;
|
|
185
|
+
get authors(): Document.Author[];
|
|
186
|
+
get version(): string;
|
|
187
|
+
get createdAt(): string;
|
|
188
|
+
get keywords(): any;
|
|
189
|
+
get languages(): Set<BundledLanguage>;
|
|
190
|
+
setAttribute(attribute: string, value: string): void;
|
|
191
|
+
convert(converters?: CustomConverter[], templateEngine?: TemplateEngineRegistry): string;
|
|
192
|
+
}
|
|
193
|
+
|
|
172
194
|
/**
|
|
173
195
|
* Checks if the given property K is required in object T.
|
|
174
196
|
*
|
|
@@ -206,7 +228,7 @@ type CustomConverter = {
|
|
|
206
228
|
convert(node: AbstractNode, templateEngine?: TemplateEngineRegistry): string | null | undefined;
|
|
207
229
|
};
|
|
208
230
|
type CustomConverterFactoryFn<T extends object> = HasRequiredKeys<T> extends true ? (converterOptions: T) => CustomConverterFn : (converterOptions?: T) => CustomConverterFn;
|
|
209
|
-
type CustomConverterFn = (opts: RequiredOptions, highlighter: HighlighterCore) => CustomConverter;
|
|
231
|
+
type CustomConverterFn = (opts: RequiredOptions, highlighter: HighlighterCore, docs: AsciidocDocument[]) => CustomConverter;
|
|
210
232
|
type ShikiTransformerFactory<T extends object> = HasRequiredKeys<T> extends true ? (options: T) => ShikiTransformerFactoryFn : (options?: T) => ShikiTransformerFactoryFn;
|
|
211
233
|
type ShikiTransformerFactoryFn = (node: AbstractNode) => ShikiTransformer;
|
|
212
234
|
type CalloutOptions = Partial<{
|
|
@@ -218,9 +240,18 @@ type CalloutOptions = Partial<{
|
|
|
218
240
|
}>;
|
|
219
241
|
type AsciidocLoader = {
|
|
220
242
|
/**
|
|
221
|
-
* Path to the
|
|
243
|
+
* Path to the directory containing the AsciiDoc files to parse.
|
|
244
|
+
* It resolves relative to the root of the project.
|
|
245
|
+
*
|
|
246
|
+
* @example ./src/content/blog
|
|
247
|
+
* @example src/content/blog
|
|
222
248
|
*/
|
|
223
249
|
base: string;
|
|
250
|
+
/**
|
|
251
|
+
* A glob pattern to match files against. Can be used to recursively
|
|
252
|
+
* descent.
|
|
253
|
+
*/
|
|
254
|
+
pattern?: string;
|
|
224
255
|
/**
|
|
225
256
|
* Options for the Asciidoctor parser.
|
|
226
257
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { HighlighterCore, CodeToHastOptions, CodeOptionsMultipleThemes, StringLiteralUnion, BundledTheme, ShikiTransformer } from 'shiki';
|
|
2
|
-
import { AbstractNode, AbstractBlock } from 'asciidoctor';
|
|
1
|
+
import { BundledLanguage, HighlighterCore, CodeToHastOptions, CodeOptionsMultipleThemes, StringLiteralUnion, BundledTheme, ShikiTransformer } from 'shiki';
|
|
2
|
+
import { AbstractNode, AbstractBlock, Document } from 'asciidoctor';
|
|
3
3
|
import { z } from 'astro/zod';
|
|
4
4
|
|
|
5
5
|
type RequiredOptions = z.output<typeof loaderOptionsSchema>;
|
|
@@ -7,6 +7,7 @@ type DocumentOptions = RequiredOptions['document'];
|
|
|
7
7
|
type PreambleOptions = RequiredOptions['preamble'];
|
|
8
8
|
declare const loaderOptionsSchema: z.ZodObject<{
|
|
9
9
|
base: z.ZodString;
|
|
10
|
+
pattern: z.ZodDefault<z.ZodString>;
|
|
10
11
|
images: z.ZodOptional<z.ZodObject<{
|
|
11
12
|
imageDir: z.ZodOptional<z.ZodString>;
|
|
12
13
|
imageUrl: z.ZodOptional<z.ZodString>;
|
|
@@ -169,6 +170,27 @@ declare class TemplateEngineRegistry {
|
|
|
169
170
|
private loadTemplates;
|
|
170
171
|
}
|
|
171
172
|
|
|
173
|
+
declare class AsciidocDocument {
|
|
174
|
+
private document;
|
|
175
|
+
private baseConverter;
|
|
176
|
+
constructor(filepath: string);
|
|
177
|
+
private get documentTitle();
|
|
178
|
+
get attributes(): any;
|
|
179
|
+
get title(): string;
|
|
180
|
+
get subtitle(): string;
|
|
181
|
+
get slug(): string;
|
|
182
|
+
get preamble(): string | undefined;
|
|
183
|
+
get description(): string;
|
|
184
|
+
get author(): string;
|
|
185
|
+
get authors(): Document.Author[];
|
|
186
|
+
get version(): string;
|
|
187
|
+
get createdAt(): string;
|
|
188
|
+
get keywords(): any;
|
|
189
|
+
get languages(): Set<BundledLanguage>;
|
|
190
|
+
setAttribute(attribute: string, value: string): void;
|
|
191
|
+
convert(converters?: CustomConverter[], templateEngine?: TemplateEngineRegistry): string;
|
|
192
|
+
}
|
|
193
|
+
|
|
172
194
|
/**
|
|
173
195
|
* Checks if the given property K is required in object T.
|
|
174
196
|
*
|
|
@@ -206,7 +228,7 @@ type CustomConverter = {
|
|
|
206
228
|
convert(node: AbstractNode, templateEngine?: TemplateEngineRegistry): string | null | undefined;
|
|
207
229
|
};
|
|
208
230
|
type CustomConverterFactoryFn<T extends object> = HasRequiredKeys<T> extends true ? (converterOptions: T) => CustomConverterFn : (converterOptions?: T) => CustomConverterFn;
|
|
209
|
-
type CustomConverterFn = (opts: RequiredOptions, highlighter: HighlighterCore) => CustomConverter;
|
|
231
|
+
type CustomConverterFn = (opts: RequiredOptions, highlighter: HighlighterCore, docs: AsciidocDocument[]) => CustomConverter;
|
|
210
232
|
type ShikiTransformerFactory<T extends object> = HasRequiredKeys<T> extends true ? (options: T) => ShikiTransformerFactoryFn : (options?: T) => ShikiTransformerFactoryFn;
|
|
211
233
|
type ShikiTransformerFactoryFn = (node: AbstractNode) => ShikiTransformer;
|
|
212
234
|
type CalloutOptions = Partial<{
|
|
@@ -218,9 +240,18 @@ type CalloutOptions = Partial<{
|
|
|
218
240
|
}>;
|
|
219
241
|
type AsciidocLoader = {
|
|
220
242
|
/**
|
|
221
|
-
* Path to the
|
|
243
|
+
* Path to the directory containing the AsciiDoc files to parse.
|
|
244
|
+
* It resolves relative to the root of the project.
|
|
245
|
+
*
|
|
246
|
+
* @example ./src/content/blog
|
|
247
|
+
* @example src/content/blog
|
|
222
248
|
*/
|
|
223
249
|
base: string;
|
|
250
|
+
/**
|
|
251
|
+
* A glob pattern to match files against. Can be used to recursively
|
|
252
|
+
* descent.
|
|
253
|
+
*/
|
|
254
|
+
pattern?: string;
|
|
224
255
|
/**
|
|
225
256
|
* Options for the Asciidoctor parser.
|
|
226
257
|
*/
|
package/dist/index.cjs
CHANGED
|
@@ -37,13 +37,15 @@ __export(index_exports, {
|
|
|
37
37
|
module.exports = __toCommonJS(index_exports);
|
|
38
38
|
|
|
39
39
|
// src/loader.ts
|
|
40
|
-
var
|
|
40
|
+
var import_node_path4 = require("path");
|
|
41
41
|
var import_node_process = require("process");
|
|
42
42
|
|
|
43
43
|
// src/lib/asciidoc/AsciidocDocument.ts
|
|
44
44
|
var import_asciidoctor = __toESM(require("asciidoctor"), 1);
|
|
45
45
|
|
|
46
|
-
// src/
|
|
46
|
+
// src/utils.ts
|
|
47
|
+
var import_node_path = require("path");
|
|
48
|
+
var import_tinyglobby = require("tinyglobby");
|
|
47
49
|
function slugify(text) {
|
|
48
50
|
return text.trim().normalize().toLowerCase().replace(/\s+/g, "-").replace(/[^\w-]+/g, "").replace(/--+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
|
|
49
51
|
}
|
|
@@ -59,6 +61,15 @@ function splitFilenameComponents(filename) {
|
|
|
59
61
|
extension: match?.groups?.ext ?? null
|
|
60
62
|
};
|
|
61
63
|
}
|
|
64
|
+
function walk(root, pattern) {
|
|
65
|
+
const dirPath = (0, import_node_path.resolve)(root);
|
|
66
|
+
return (0, import_tinyglobby.glob)(pattern, {
|
|
67
|
+
cwd: dirPath,
|
|
68
|
+
absolute: true,
|
|
69
|
+
expandDirectories: false,
|
|
70
|
+
followSymbolicLinks: true
|
|
71
|
+
});
|
|
72
|
+
}
|
|
62
73
|
|
|
63
74
|
// src/lib/asciidoc/BaseConverter.ts
|
|
64
75
|
var BaseConverter = class {
|
|
@@ -471,11 +482,11 @@ var TemplateStr = class extends AbstractEngine {
|
|
|
471
482
|
var import_zod3 = require("astro/zod");
|
|
472
483
|
|
|
473
484
|
// src/schemas/document.ts
|
|
474
|
-
var
|
|
485
|
+
var import_node_path2 = require("path");
|
|
475
486
|
var import_zod = require("astro/zod");
|
|
476
487
|
var documentOptionsSchema = import_zod.z.object({
|
|
477
488
|
mode: import_zod.z.union([import_zod.z.literal("safe"), import_zod.z.literal("unsafe")]).default("safe"),
|
|
478
|
-
template: import_zod.z.string().default("").transform((val) => val ? (0,
|
|
489
|
+
template: import_zod.z.string().default("").transform((val) => val ? (0, import_node_path2.resolve)(process.cwd(), val) : ""),
|
|
479
490
|
recursive: import_zod.z.boolean().default(false)
|
|
480
491
|
}).passthrough().default({
|
|
481
492
|
mode: "safe",
|
|
@@ -546,6 +557,7 @@ var imagesOptionsSchema = import_zod3.z.object({
|
|
|
546
557
|
}).optional();
|
|
547
558
|
var loaderOptionsSchema = import_zod3.z.object({
|
|
548
559
|
base: import_zod3.z.string(),
|
|
560
|
+
pattern: import_zod3.z.string().default("**/*.{adoc,asciidoc}"),
|
|
549
561
|
images: imagesOptionsSchema,
|
|
550
562
|
document: documentOptionsSchema,
|
|
551
563
|
syntaxHighlighting: shikiOptionsSchema,
|
|
@@ -563,10 +575,16 @@ async function createHighlighter(documents, themes) {
|
|
|
563
575
|
}, /* @__PURE__ */ new Set());
|
|
564
576
|
const highlighter = await (0, import_shiki2.createHighlighterCore)({
|
|
565
577
|
themes: Object.values(themes).map((theme) => {
|
|
566
|
-
return import(
|
|
578
|
+
return import(
|
|
579
|
+
/* @vite-ignore */
|
|
580
|
+
`@shikijs/themes/${theme}`
|
|
581
|
+
);
|
|
567
582
|
}),
|
|
568
583
|
langs: Array.from(langs).map((lang) => {
|
|
569
|
-
return import(
|
|
584
|
+
return import(
|
|
585
|
+
/* @vite-ignore */
|
|
586
|
+
`@shikijs/langs/${lang}`
|
|
587
|
+
);
|
|
570
588
|
}),
|
|
571
589
|
engine: (0, import_shiki2.createJavaScriptRegexEngine)()
|
|
572
590
|
});
|
|
@@ -574,7 +592,7 @@ async function createHighlighter(documents, themes) {
|
|
|
574
592
|
}
|
|
575
593
|
|
|
576
594
|
// src/lib/asciidoc/converters/sourceCodeConverter.ts
|
|
577
|
-
var
|
|
595
|
+
var import_node_path3 = require("path");
|
|
578
596
|
var sourceCodeConverter = (converterOptions) => {
|
|
579
597
|
const transformers = converterOptions?.transformers;
|
|
580
598
|
const template = converterOptions?.template;
|
|
@@ -598,7 +616,7 @@ var sourceCodeConverter = (converterOptions) => {
|
|
|
598
616
|
);
|
|
599
617
|
const engine = extension ? templateEngine.getEngineByExtension(extension ?? "") : templateEngine.getEngineByContext(this.nodeContext);
|
|
600
618
|
if (template) {
|
|
601
|
-
const templateFile = (0,
|
|
619
|
+
const templateFile = (0, import_node_path3.resolve)(process.cwd(), template);
|
|
602
620
|
engine?.addContext(this.nodeContext, templateFile);
|
|
603
621
|
}
|
|
604
622
|
if (engine) {
|
|
@@ -617,7 +635,7 @@ var sourceCodeConverter = (converterOptions) => {
|
|
|
617
635
|
// src/lib/shiki/transformers/transformAsciidocCallout.ts
|
|
618
636
|
var transformAsciidocCallout = (options) => {
|
|
619
637
|
return (node) => {
|
|
620
|
-
const lineComments = ["//", "#", ";;", "%"];
|
|
638
|
+
const lineComments = ["//", "#", ";;", "%", "--"];
|
|
621
639
|
const customLineComment = node.getAttribute("line-comment");
|
|
622
640
|
if (customLineComment) {
|
|
623
641
|
lineComments.push(escapeRegexCharacters(customLineComment));
|
|
@@ -691,10 +709,19 @@ function asciidocLoader(_options) {
|
|
|
691
709
|
name: "asciidoc-loader",
|
|
692
710
|
async load(loaderContext) {
|
|
693
711
|
const { config, logger, watcher } = loaderContext;
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
712
|
+
if (options.base.includes("../")) {
|
|
713
|
+
throw new Error(
|
|
714
|
+
"Base path cannot traverse outwards of project directory."
|
|
715
|
+
);
|
|
716
|
+
}
|
|
717
|
+
if (options.base.startsWith("/") && !options.base.includes(config.root.pathname)) {
|
|
718
|
+
throw new Error(
|
|
719
|
+
"Base path must be contained within project directory."
|
|
720
|
+
);
|
|
721
|
+
}
|
|
722
|
+
const root = (0, import_node_path4.resolve)(config.root.pathname, options.base);
|
|
723
|
+
const docs = (await walk(root, options.pattern)).map((file) => {
|
|
724
|
+
const doc = new AsciidocDocument(file);
|
|
698
725
|
if (options.images?.imageUrl) {
|
|
699
726
|
doc.setAttribute("imagesdir", options.images.imageUrl);
|
|
700
727
|
}
|
|
@@ -721,7 +748,7 @@ function asciidocLoader(_options) {
|
|
|
721
748
|
);
|
|
722
749
|
}
|
|
723
750
|
const converters = options.document.converters.map(
|
|
724
|
-
(converter) => converter(options, highlighter)
|
|
751
|
+
(converter) => converter(options, highlighter, docs)
|
|
725
752
|
);
|
|
726
753
|
const hasSourceCodeConverter = converters.find(
|
|
727
754
|
(converter) => converter.nodeContext === "listing" && converter?.nodeStyle === "source"
|
|
@@ -735,7 +762,7 @@ function asciidocLoader(_options) {
|
|
|
735
762
|
options.syntaxHighlighting.callouts
|
|
736
763
|
)
|
|
737
764
|
]
|
|
738
|
-
})(options, highlighter)
|
|
765
|
+
})(options, highlighter, docs)
|
|
739
766
|
);
|
|
740
767
|
}
|
|
741
768
|
await Promise.all(
|
|
@@ -751,7 +778,7 @@ function asciidocLoader(_options) {
|
|
|
751
778
|
};
|
|
752
779
|
var handle = handle2;
|
|
753
780
|
const watchedFileRegExp = new RegExp(
|
|
754
|
-
`^${
|
|
781
|
+
`^${root}.*.(a(?:scii)?doc)$`
|
|
755
782
|
);
|
|
756
783
|
watcher.on("change", async (changedPath) => {
|
|
757
784
|
if (changedPath.match(watchedFileRegExp)) {
|
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 { b as AsciidocTemplate, C as CustomConverterFactoryFn, F as FilesystemTemplate, N as NodeContext, R as RawTemplate } from './index-
|
|
2
|
+
import { a as AsciidocLoader } from './index-CA5P6VBa.cjs';
|
|
3
|
+
export { b as AsciidocTemplate, C as CustomConverterFactoryFn, F as FilesystemTemplate, N as NodeContext, R as RawTemplate } from './index-CA5P6VBa.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 { b as AsciidocTemplate, C as CustomConverterFactoryFn, F as FilesystemTemplate, N as NodeContext, R as RawTemplate } from './index-
|
|
2
|
+
import { a as AsciidocLoader } from './index-CA5P6VBa.js';
|
|
3
|
+
export { b as AsciidocTemplate, C as CustomConverterFactoryFn, F as FilesystemTemplate, N as NodeContext, R as RawTemplate } from './index-CA5P6VBa.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,22 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
2
|
sourceCodeConverter
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import {
|
|
5
|
-
transformAsciidocCallout,
|
|
6
|
-
transformerPrompt
|
|
7
|
-
} from "./chunk-TCLZUBH3.js";
|
|
8
|
-
import {
|
|
9
|
-
slugify,
|
|
10
|
-
splitFilenameComponents
|
|
11
|
-
} from "./chunk-2UGTFP4R.js";
|
|
3
|
+
} from "./chunk-YJTKOSBY.js";
|
|
12
4
|
import {
|
|
13
5
|
HandlebarsEngine,
|
|
14
6
|
NunjucksEngine,
|
|
15
7
|
TemplateStr
|
|
16
8
|
} from "./chunk-S7W7VGV4.js";
|
|
9
|
+
import {
|
|
10
|
+
transformAsciidocCallout,
|
|
11
|
+
transformerPrompt
|
|
12
|
+
} from "./chunk-FVYBQ3D5.js";
|
|
13
|
+
import {
|
|
14
|
+
slugify,
|
|
15
|
+
splitFilenameComponents,
|
|
16
|
+
walk
|
|
17
|
+
} from "./chunk-37PTJDHV.js";
|
|
17
18
|
|
|
18
19
|
// src/loader.ts
|
|
19
|
-
import {
|
|
20
|
+
import { resolve as resolve2 } from "path";
|
|
20
21
|
import { nextTick } from "process";
|
|
21
22
|
|
|
22
23
|
// src/lib/asciidoc/AsciidocDocument.ts
|
|
@@ -353,6 +354,7 @@ var imagesOptionsSchema = z3.object({
|
|
|
353
354
|
}).optional();
|
|
354
355
|
var loaderOptionsSchema = z3.object({
|
|
355
356
|
base: z3.string(),
|
|
357
|
+
pattern: z3.string().default("**/*.{adoc,asciidoc}"),
|
|
356
358
|
images: imagesOptionsSchema,
|
|
357
359
|
document: documentOptionsSchema,
|
|
358
360
|
syntaxHighlighting: shikiOptionsSchema,
|
|
@@ -370,10 +372,16 @@ async function createHighlighter(documents, themes) {
|
|
|
370
372
|
}, /* @__PURE__ */ new Set());
|
|
371
373
|
const highlighter = await createHighlighterCore({
|
|
372
374
|
themes: Object.values(themes).map((theme) => {
|
|
373
|
-
return import(
|
|
375
|
+
return import(
|
|
376
|
+
/* @vite-ignore */
|
|
377
|
+
`@shikijs/themes/${theme}`
|
|
378
|
+
);
|
|
374
379
|
}),
|
|
375
380
|
langs: Array.from(langs).map((lang) => {
|
|
376
|
-
return import(
|
|
381
|
+
return import(
|
|
382
|
+
/* @vite-ignore */
|
|
383
|
+
`@shikijs/langs/${lang}`
|
|
384
|
+
);
|
|
377
385
|
}),
|
|
378
386
|
engine: createJavaScriptRegexEngine()
|
|
379
387
|
});
|
|
@@ -399,10 +407,19 @@ function asciidocLoader(_options) {
|
|
|
399
407
|
name: "asciidoc-loader",
|
|
400
408
|
async load(loaderContext) {
|
|
401
409
|
const { config, logger, watcher } = loaderContext;
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
410
|
+
if (options.base.includes("../")) {
|
|
411
|
+
throw new Error(
|
|
412
|
+
"Base path cannot traverse outwards of project directory."
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
if (options.base.startsWith("/") && !options.base.includes(config.root.pathname)) {
|
|
416
|
+
throw new Error(
|
|
417
|
+
"Base path must be contained within project directory."
|
|
418
|
+
);
|
|
419
|
+
}
|
|
420
|
+
const root = resolve2(config.root.pathname, options.base);
|
|
421
|
+
const docs = (await walk(root, options.pattern)).map((file) => {
|
|
422
|
+
const doc = new AsciidocDocument(file);
|
|
406
423
|
if (options.images?.imageUrl) {
|
|
407
424
|
doc.setAttribute("imagesdir", options.images.imageUrl);
|
|
408
425
|
}
|
|
@@ -429,7 +446,7 @@ function asciidocLoader(_options) {
|
|
|
429
446
|
);
|
|
430
447
|
}
|
|
431
448
|
const converters = options.document.converters.map(
|
|
432
|
-
(converter) => converter(options, highlighter)
|
|
449
|
+
(converter) => converter(options, highlighter, docs)
|
|
433
450
|
);
|
|
434
451
|
const hasSourceCodeConverter = converters.find(
|
|
435
452
|
(converter) => converter.nodeContext === "listing" && converter?.nodeStyle === "source"
|
|
@@ -443,7 +460,7 @@ function asciidocLoader(_options) {
|
|
|
443
460
|
options.syntaxHighlighting.callouts
|
|
444
461
|
)
|
|
445
462
|
]
|
|
446
|
-
})(options, highlighter)
|
|
463
|
+
})(options, highlighter, docs)
|
|
447
464
|
);
|
|
448
465
|
}
|
|
449
466
|
await Promise.all(
|
|
@@ -459,7 +476,7 @@ function asciidocLoader(_options) {
|
|
|
459
476
|
};
|
|
460
477
|
var handle = handle2;
|
|
461
478
|
const watchedFileRegExp = new RegExp(
|
|
462
|
-
`^${
|
|
479
|
+
`^${root}.*.(a(?:scii)?doc)$`
|
|
463
480
|
);
|
|
464
481
|
watcher.on("change", async (changedPath) => {
|
|
465
482
|
if (changedPath.match(watchedFileRegExp)) {
|
|
@@ -25,9 +25,11 @@ __export(converters_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(converters_exports);
|
|
26
26
|
|
|
27
27
|
// src/lib/asciidoc/converters/sourceCodeConverter.ts
|
|
28
|
-
var
|
|
28
|
+
var import_node_path2 = require("path");
|
|
29
29
|
|
|
30
|
-
// src/
|
|
30
|
+
// src/utils.ts
|
|
31
|
+
var import_node_path = require("path");
|
|
32
|
+
var import_tinyglobby = require("tinyglobby");
|
|
31
33
|
function splitFilenameComponents(filename) {
|
|
32
34
|
const match = filename.match(/^(?<path>.*\/)*(?<name>[^\.]+)\.(?<ext>.*)$/);
|
|
33
35
|
return {
|
|
@@ -61,7 +63,7 @@ var sourceCodeConverter = (converterOptions) => {
|
|
|
61
63
|
);
|
|
62
64
|
const engine = extension ? templateEngine.getEngineByExtension(extension ?? "") : templateEngine.getEngineByContext(this.nodeContext);
|
|
63
65
|
if (template) {
|
|
64
|
-
const templateFile = (0,
|
|
66
|
+
const templateFile = (0, import_node_path2.resolve)(process.cwd(), template);
|
|
65
67
|
engine?.addContext(this.nodeContext, templateFile);
|
|
66
68
|
}
|
|
67
69
|
if (engine) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ShikiTransformer } from 'shiki';
|
|
2
|
-
import { C as CustomConverterFactoryFn, c as ShikiTransformerFactoryFn } from '../../../index-
|
|
2
|
+
import { C as CustomConverterFactoryFn, c as ShikiTransformerFactoryFn } from '../../../index-CA5P6VBa.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, c as ShikiTransformerFactoryFn } from '../../../index-
|
|
2
|
+
import { C as CustomConverterFactoryFn, c as ShikiTransformerFactoryFn } from '../../../index-CA5P6VBa.js';
|
|
3
3
|
import 'asciidoctor';
|
|
4
4
|
import 'astro/zod';
|
|
5
5
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as AbstractEngine, b as AsciidocTemplate, T as TemplateModule, F as FilesystemTemplate, R as RawTemplate } from '../../../../index-
|
|
1
|
+
import { A as AbstractEngine, b as AsciidocTemplate, T as TemplateModule, F as FilesystemTemplate, R as RawTemplate } from '../../../../index-CA5P6VBa.cjs';
|
|
2
2
|
import { AbstractBlock } from 'asciidoctor';
|
|
3
3
|
import 'shiki';
|
|
4
4
|
import 'astro/zod';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as AbstractEngine, b as AsciidocTemplate, T as TemplateModule, F as FilesystemTemplate, R as RawTemplate } from '../../../../index-
|
|
1
|
+
import { A as AbstractEngine, b as AsciidocTemplate, T as TemplateModule, F as FilesystemTemplate, R as RawTemplate } from '../../../../index-CA5P6VBa.js';
|
|
2
2
|
import { AbstractBlock } from 'asciidoctor';
|
|
3
3
|
import 'shiki';
|
|
4
4
|
import 'astro/zod';
|
|
@@ -25,7 +25,9 @@ __export(transformers_exports, {
|
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(transformers_exports);
|
|
27
27
|
|
|
28
|
-
// src/
|
|
28
|
+
// src/utils.ts
|
|
29
|
+
var import_node_path = require("path");
|
|
30
|
+
var import_tinyglobby = require("tinyglobby");
|
|
29
31
|
function escapeRegexCharacters(str) {
|
|
30
32
|
const re = /[-\\^$*+?.()|\[\]{}]/g;
|
|
31
33
|
return str.replace(re, "\\$&");
|
|
@@ -34,7 +36,7 @@ function escapeRegexCharacters(str) {
|
|
|
34
36
|
// src/lib/shiki/transformers/transformAsciidocCallout.ts
|
|
35
37
|
var transformAsciidocCallout = (options) => {
|
|
36
38
|
return (node) => {
|
|
37
|
-
const lineComments = ["//", "#", ";;", "%"];
|
|
39
|
+
const lineComments = ["//", "#", ";;", "%", "--"];
|
|
38
40
|
const customLineComment = node.getAttribute("line-comment");
|
|
39
41
|
if (customLineComment) {
|
|
40
42
|
lineComments.push(escapeRegexCharacters(customLineComment));
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
transformAsciidocCallout,
|
|
3
3
|
transformerPrompt
|
|
4
|
-
} from "../../../chunk-
|
|
5
|
-
import "../../../chunk-
|
|
4
|
+
} from "../../../chunk-FVYBQ3D5.js";
|
|
5
|
+
import "../../../chunk-37PTJDHV.js";
|
|
6
6
|
export {
|
|
7
7
|
transformAsciidocCallout,
|
|
8
8
|
transformerPrompt
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d10f/asciidoc-astro-loader",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "An Astro collections loader for Asciidoc files",
|
|
5
5
|
"author": "D10f",
|
|
6
6
|
"license": "MIT",
|
|
@@ -52,7 +52,8 @@
|
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@shikijs/transformers": "^4.5.0",
|
|
54
54
|
"asciidoctor": "^3.0.4",
|
|
55
|
-
"shiki": "^4.5.0"
|
|
55
|
+
"shiki": "^4.5.0",
|
|
56
|
+
"tinyglobby": "^0.2.17"
|
|
56
57
|
},
|
|
57
58
|
"peerDependencies": {
|
|
58
59
|
"astro": "^6.3.1"
|