@d10f/asciidoc-astro-loader 0.0.15 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -27,7 +27,8 @@ Install the package from `npm`:
27
27
  And import the loader function inside your `content.config.ts` file to define a new collection:
28
28
 
29
29
  ```ts
30
- import { defineCollection, z } from "astro:content";
30
+ import { defineCollection } from "astro:content";
31
+ import { z } from 'astro/zod';
31
32
  import { asciidocLoader } from "asciidoc-astro-loader";
32
33
 
33
34
  const blog = defineCollection({
@@ -93,7 +94,7 @@ const blog = defineCollection({
93
94
  });
94
95
  ```
95
96
 
96
- ### Shiki Trasnformers
97
+ ### Shiki Transformers
97
98
 
98
99
  One of the coolest features from Shiki are [transformers](https://shiki.style/guide/transformers). You can provide a list of the transformers that you want to use at the loader configuration:
99
100
 
@@ -5,6 +5,8 @@ var AbstractEngine = class {
5
5
  this._extensions = _extensions;
6
6
  this.templateList = /* @__PURE__ */ new Map();
7
7
  }
8
+ _name;
9
+ _extensions;
8
10
  templateList;
9
11
  /**
10
12
  * Returns the given name to this template engine.
@@ -61,43 +61,57 @@ var transformAsciidocCallout = (options) => {
61
61
  };
62
62
 
63
63
  // src/lib/shiki/transformers/transformerPrompt.ts
64
- var transformerPrompt = (options) => {
64
+ var DEFAULT_OPTS = {
65
+ breakOn: "\\",
66
+ cssClasses: "",
67
+ hideBreak: false,
68
+ prompt: "",
69
+ promptAttribute: "custom-prompt"
70
+ };
71
+ var transformerPrompt = (opts) => {
65
72
  return (node) => {
66
- const language = node.getAttribute("language");
67
- const customPrompt = node.getAttribute(
68
- options?.promptAttribute ?? "custom-prompt"
73
+ const config = {
74
+ breakOn: opts?.breakOn ?? DEFAULT_OPTS.breakOn,
75
+ cssClasses: opts?.cssClasses ?? DEFAULT_OPTS.cssClasses,
76
+ hideBreak: opts?.hideBreak ?? DEFAULT_OPTS.hideBreak,
77
+ prompt: opts?.prompt ?? DEFAULT_OPTS.prompt
78
+ };
79
+ if (opts && opts.langs) {
80
+ const lang = node.getAttribute("language");
81
+ const langOpts = opts.langs[lang];
82
+ Object.assign(
83
+ config,
84
+ typeof langOpts === "object" ? langOpts : { prompt: langOpts }
85
+ );
86
+ }
87
+ const promptAttr = node.getAttribute(
88
+ opts?.promptAttribute ?? DEFAULT_OPTS.promptAttribute
69
89
  );
70
- const promptToAdd = customPrompt ?? (options?.langs && options.langs[language]);
71
- let cssClasses = typeof promptToAdd === "object" ? promptToAdd.cssClasses : options?.cssClasses;
72
- const breakOn = typeof promptToAdd === "object" ? promptToAdd.breakOn ?? "\\" : "\\";
90
+ if (promptAttr) {
91
+ Object.assign(config, {
92
+ prompt: promptAttr
93
+ });
94
+ }
73
95
  const breakOnRe = new RegExp(
74
- `\\s+${escapeRegexCharacters(breakOn)}\\s*$`
96
+ `\\s+${escapeRegexCharacters(config.breakOn)}\\s*$`
75
97
  );
76
- const hideBreak = options?.langs && options.langs[language] && typeof options.langs[language] === "object" && options.langs[language].hideBreak;
77
- if (customPrompt && options?.langs && typeof options.langs[language] === "object") {
78
- cssClasses = options.langs[language].cssClasses;
79
- }
80
98
  let skipNext = false;
99
+ let skipCurrent = false;
81
100
  return {
82
101
  enforce: "pre",
83
102
  line(hast) {
84
- if (!promptToAdd) return;
85
- const skipCurrent = skipNext;
103
+ if (!config.prompt || !config.prompt.trim()) return;
104
+ skipCurrent = skipNext;
86
105
  skipNext = false;
87
106
  const lastChild = hast.children.at(-1);
88
- const lastToken = lastChild.children[0];
89
- if (lastChild && lastToken) {
107
+ const lastToken = lastChild?.children[0];
108
+ if (lastToken) {
90
109
  skipNext = breakOnRe.test(lastToken.value);
91
- lastToken.value = lastToken.value.replace(breakOnRe, "");
92
- if (lastChild.children[0].value.match(breakOnRe)) {
93
- skipNext = true;
94
- if (hideBreak) {
95
- lastChild.children[0].value = // @ts-expect-error property "children" does exist
96
- lastChild.children[0].value.replace(
97
- breakOnRe,
98
- ""
99
- );
100
- }
110
+ if (skipNext && config.hideBreak) {
111
+ lastToken.value = lastToken.value.replace(
112
+ breakOnRe,
113
+ ""
114
+ );
101
115
  }
102
116
  }
103
117
  if (skipCurrent) return;
@@ -105,12 +119,12 @@ var transformerPrompt = (options) => {
105
119
  type: "element",
106
120
  tagName: "span",
107
121
  properties: {
108
- class: cssClasses
122
+ class: config.cssClasses
109
123
  },
110
124
  children: [
111
125
  {
112
126
  type: "text",
113
- value: typeof promptToAdd === "object" ? promptToAdd.prompt : promptToAdd
127
+ value: config.prompt
114
128
  }
115
129
  ]
116
130
  });
@@ -7,110 +7,37 @@ type DocumentOptions = RequiredOptions['document'];
7
7
  type PreambleOptions = RequiredOptions['preamble'];
8
8
  declare const loaderOptionsSchema: z.ZodObject<{
9
9
  base: z.ZodString;
10
+ images: z.ZodOptional<z.ZodObject<{
11
+ imageDir: z.ZodOptional<z.ZodString>;
12
+ imageUrl: z.ZodOptional<z.ZodString>;
13
+ }, z.core.$strip>>;
10
14
  document: z.ZodDefault<z.ZodObject<{
11
- mode: z.ZodDefault<z.ZodUnion<[z.ZodLiteral<"safe">, z.ZodLiteral<"unsafe">]>>;
12
- template: z.ZodEffects<z.ZodDefault<z.ZodString>, string, string | undefined>;
15
+ mode: z.ZodDefault<z.ZodUnion<readonly [z.ZodLiteral<"safe">, z.ZodLiteral<"unsafe">]>>;
16
+ template: z.ZodPipe<z.ZodDefault<z.ZodString>, z.ZodTransform<string, string>>;
13
17
  recursive: z.ZodDefault<z.ZodBoolean>;
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<{
18
+ }, z.core.$loose>>;
19
+ syntaxHighlighting: z.ZodDefault<z.ZodPipe<z.ZodObject<{
20
+ theme: z.ZodDefault<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
28
21
  light: z.ZodString;
29
22
  dark: z.ZodString;
30
- }, z.ZodString, "strip">, z.objectInputType<{
31
- light: z.ZodString;
32
- dark: z.ZodString;
33
- }, z.ZodString, "strip">>]>, {
23
+ }, z.core.$catchall<z.ZodString>>]>, z.ZodTransform<{
34
24
  light: string;
35
25
  dark: string;
36
26
  } & {
37
27
  [other: string]: string;
38
- }, string | z.objectInputType<{
39
- light: z.ZodString;
40
- dark: z.ZodString;
41
- }, z.ZodString, "strip">>>;
42
- defaultColor: z.ZodDefault<z.ZodString>;
43
- cssVariablePrefix: z.ZodDefault<z.ZodString>;
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
- callouts: z.ZodOptional<z.ZodObject<{
47
- cssClasses: z.ZodOptional<z.ZodString>;
48
- }, "strip", z.ZodTypeAny, {
49
- cssClasses?: string | undefined;
50
- }, {
51
- cssClasses?: string | undefined;
52
- }>>;
53
- }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
54
- theme: z.ZodDefault<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodObject<{
55
- light: z.ZodString;
56
- dark: z.ZodString;
57
- }, "strip", z.ZodString, z.objectOutputType<{
58
- light: z.ZodString;
59
- dark: z.ZodString;
60
- }, z.ZodString, "strip">, z.objectInputType<{
61
- light: z.ZodString;
62
- dark: z.ZodString;
63
- }, z.ZodString, "strip">>]>, {
64
- light: string;
65
- dark: string;
66
- } & {
67
- [other: string]: string;
68
- }, string | z.objectInputType<{
69
- light: z.ZodString;
70
- dark: z.ZodString;
71
- }, z.ZodString, "strip">>>;
72
- defaultColor: z.ZodDefault<z.ZodString>;
73
- cssVariablePrefix: z.ZodDefault<z.ZodString>;
74
- mergeWhitespaces: z.ZodDefault<z.ZodUnion<[z.ZodBoolean, z.ZodLiteral<"never">]>>;
75
- tabindex: z.ZodDefault<z.ZodUnion<[z.ZodNumber, z.ZodString, z.ZodLiteral<false>]>>;
76
- callouts: z.ZodOptional<z.ZodObject<{
77
- cssClasses: z.ZodOptional<z.ZodString>;
78
- }, "strip", z.ZodTypeAny, {
79
- cssClasses?: string | undefined;
80
- }, {
81
- cssClasses?: string | undefined;
82
- }>>;
83
- }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
84
- theme: z.ZodDefault<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodObject<{
85
- light: z.ZodString;
86
- dark: z.ZodString;
87
- }, "strip", z.ZodString, z.objectOutputType<{
88
- light: z.ZodString;
89
- dark: z.ZodString;
90
- }, z.ZodString, "strip">, z.objectInputType<{
91
- light: z.ZodString;
92
- dark: z.ZodString;
93
- }, z.ZodString, "strip">>]>, {
28
+ }, string | {
29
+ [x: string]: string;
94
30
  light: string;
95
31
  dark: string;
96
- } & {
97
- [other: string]: string;
98
- }, string | z.objectInputType<{
99
- light: z.ZodString;
100
- dark: z.ZodString;
101
- }, z.ZodString, "strip">>>;
32
+ }>>>;
102
33
  defaultColor: z.ZodDefault<z.ZodString>;
103
34
  cssVariablePrefix: z.ZodDefault<z.ZodString>;
104
- mergeWhitespaces: z.ZodDefault<z.ZodUnion<[z.ZodBoolean, z.ZodLiteral<"never">]>>;
105
- tabindex: z.ZodDefault<z.ZodUnion<[z.ZodNumber, z.ZodString, z.ZodLiteral<false>]>>;
35
+ mergeWhitespaces: z.ZodDefault<z.ZodUnion<readonly [z.ZodBoolean, z.ZodLiteral<"never">]>>;
36
+ tabindex: z.ZodDefault<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodLiteral<false>]>>;
106
37
  callouts: z.ZodOptional<z.ZodObject<{
107
38
  cssClasses: z.ZodOptional<z.ZodString>;
108
- }, "strip", z.ZodTypeAny, {
109
- cssClasses?: string | undefined;
110
- }, {
111
- cssClasses?: string | undefined;
112
- }>>;
113
- }, z.ZodTypeAny, "passthrough">>, {
39
+ }, z.core.$strip>>;
40
+ }, z.core.$loose>, z.ZodTransform<{
114
41
  defaultColor: string;
115
42
  cssVariablePrefix: string;
116
43
  mergeWhitespaces: boolean | "never";
@@ -124,60 +51,14 @@ declare const loaderOptionsSchema: z.ZodObject<{
124
51
  } & {
125
52
  [other: string]: string;
126
53
  };
127
- }, z.objectInputType<{
128
- theme: z.ZodDefault<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodObject<{
129
- light: z.ZodString;
130
- dark: z.ZodString;
131
- }, "strip", z.ZodString, z.objectOutputType<{
132
- light: z.ZodString;
133
- dark: z.ZodString;
134
- }, z.ZodString, "strip">, z.objectInputType<{
135
- light: z.ZodString;
136
- dark: z.ZodString;
137
- }, z.ZodString, "strip">>]>, {
54
+ }, {
55
+ [x: string]: unknown;
56
+ theme: {
138
57
  light: string;
139
58
  dark: string;
140
59
  } & {
141
60
  [other: string]: string;
142
- }, string | z.objectInputType<{
143
- light: z.ZodString;
144
- dark: z.ZodString;
145
- }, z.ZodString, "strip">>>;
146
- defaultColor: z.ZodDefault<z.ZodString>;
147
- cssVariablePrefix: z.ZodDefault<z.ZodString>;
148
- mergeWhitespaces: z.ZodDefault<z.ZodUnion<[z.ZodBoolean, z.ZodLiteral<"never">]>>;
149
- tabindex: z.ZodDefault<z.ZodUnion<[z.ZodNumber, z.ZodString, z.ZodLiteral<false>]>>;
150
- callouts: z.ZodOptional<z.ZodObject<{
151
- cssClasses: z.ZodOptional<z.ZodString>;
152
- }, "strip", z.ZodTypeAny, {
153
- cssClasses?: string | undefined;
154
- }, {
155
- cssClasses?: string | undefined;
156
- }>>;
157
- }, z.ZodTypeAny, "passthrough">>>;
158
- preamble: z.ZodDefault<z.ZodObject<{
159
- tableOfContents: z.ZodDefault<z.ZodBoolean>;
160
- maxLevel: z.ZodDefault<z.ZodNumber>;
161
- position: z.ZodDefault<z.ZodUnion<[z.ZodLiteral<"before">, z.ZodLiteral<"after">]>>;
162
- }, "strip", z.ZodTypeAny, {
163
- tableOfContents: boolean;
164
- maxLevel: number;
165
- position: "before" | "after";
166
- }, {
167
- tableOfContents?: boolean | undefined;
168
- maxLevel?: number | undefined;
169
- position?: "before" | "after" | undefined;
170
- }>>;
171
- }, "strip", z.ZodTypeAny, {
172
- base: string;
173
- document: {
174
- mode: "safe" | "unsafe";
175
- template: string;
176
- recursive: boolean;
177
- } & {
178
- [k: string]: unknown;
179
- };
180
- syntaxHighlighting: {
61
+ };
181
62
  defaultColor: string;
182
63
  cssVariablePrefix: string;
183
64
  mergeWhitespaces: boolean | "never";
@@ -185,62 +66,13 @@ declare const loaderOptionsSchema: z.ZodObject<{
185
66
  callouts?: {
186
67
  cssClasses?: string | undefined;
187
68
  } | undefined;
188
- themes: {
189
- light: string;
190
- dark: string;
191
- } & {
192
- [other: string]: string;
193
- };
194
- };
195
- preamble: {
196
- tableOfContents: boolean;
197
- maxLevel: number;
198
- position: "before" | "after";
199
- };
200
- }, {
201
- base: string;
202
- document?: z.objectInputType<{
203
- mode: z.ZodDefault<z.ZodUnion<[z.ZodLiteral<"safe">, z.ZodLiteral<"unsafe">]>>;
204
- template: z.ZodEffects<z.ZodDefault<z.ZodString>, string, string | undefined>;
205
- recursive: z.ZodDefault<z.ZodBoolean>;
206
- }, z.ZodTypeAny, "passthrough"> | undefined;
207
- syntaxHighlighting?: z.objectInputType<{
208
- theme: z.ZodDefault<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodObject<{
209
- light: z.ZodString;
210
- dark: z.ZodString;
211
- }, "strip", z.ZodString, z.objectOutputType<{
212
- light: z.ZodString;
213
- dark: z.ZodString;
214
- }, z.ZodString, "strip">, z.objectInputType<{
215
- light: z.ZodString;
216
- dark: z.ZodString;
217
- }, z.ZodString, "strip">>]>, {
218
- light: string;
219
- dark: string;
220
- } & {
221
- [other: string]: string;
222
- }, string | z.objectInputType<{
223
- light: z.ZodString;
224
- dark: z.ZodString;
225
- }, z.ZodString, "strip">>>;
226
- defaultColor: z.ZodDefault<z.ZodString>;
227
- cssVariablePrefix: z.ZodDefault<z.ZodString>;
228
- mergeWhitespaces: z.ZodDefault<z.ZodUnion<[z.ZodBoolean, z.ZodLiteral<"never">]>>;
229
- tabindex: z.ZodDefault<z.ZodUnion<[z.ZodNumber, z.ZodString, z.ZodLiteral<false>]>>;
230
- callouts: z.ZodOptional<z.ZodObject<{
231
- cssClasses: z.ZodOptional<z.ZodString>;
232
- }, "strip", z.ZodTypeAny, {
233
- cssClasses?: string | undefined;
234
- }, {
235
- cssClasses?: string | undefined;
236
- }>>;
237
- }, z.ZodTypeAny, "passthrough"> | undefined;
238
- preamble?: {
239
- tableOfContents?: boolean | undefined;
240
- maxLevel?: number | undefined;
241
- position?: "before" | "after" | undefined;
242
- } | undefined;
243
- }>;
69
+ }>>>;
70
+ preamble: z.ZodDefault<z.ZodObject<{
71
+ tableOfContents: z.ZodDefault<z.ZodBoolean>;
72
+ maxLevel: z.ZodDefault<z.ZodNumber>;
73
+ position: z.ZodDefault<z.ZodUnion<readonly [z.ZodLiteral<"before">, z.ZodLiteral<"after">]>>;
74
+ }, z.core.$strip>>;
75
+ }, z.core.$strip>;
244
76
 
245
77
  declare abstract class AbstractEngine {
246
78
  private _name;
@@ -420,6 +252,30 @@ type AsciidocLoader = {
420
252
  */
421
253
  templateEngines: Array<AbstractEngine & AsciidocTemplate>;
422
254
  }>;
255
+ /**
256
+ * Options related to images and their location while parsing documents
257
+ */
258
+ images?: Partial<{
259
+ /**
260
+ * Path to the directory where images are stored. This is a global
261
+ * setting that applies to all documents that _do not_ already have
262
+ * an imagesdir attribute set.
263
+ *
264
+ * Make use of templates or converters for granuar control over this
265
+ * attribute on individua documents.
266
+ *
267
+ * @see https://docs.asciidoctor.org/pdf-converter/latest/image-paths-and-formats/#imagesdir
268
+ */
269
+ imagesDir?: string;
270
+ /**
271
+ * Path relative to the base URL of the site that will be used to
272
+ * resolve image src attributes. The base URL is configured via the
273
+ * Astro configuration file.
274
+ *
275
+ * @see https://docs.astro.build/en/reference/configuration-reference/#site
276
+ */
277
+ imageUrl?: string;
278
+ }>;
423
279
  /**
424
280
  * Options provided for the output of the preamble section, when
425
281
  * there is one present in the parsed document.
@@ -546,4 +402,4 @@ interface RawTemplate {
546
402
  renderString(content: string, options?: Record<string, unknown>): string;
547
403
  }
548
404
 
549
- export { type AsciidocLoader as A, type CustomConverterFactoryFn as C, type FilesystemTemplate as F, type NodeContext as N, type RawTemplate as R, type ShikiTransformerFactoryFn as S, type TemplateModule as T, type AsciidocTemplate as a, AbstractEngine as b, type ShikiTransformerFactory as c };
405
+ export { AbstractEngine as A, type CustomConverterFactoryFn as C, type FilesystemTemplate as F, type NodeContext as N, type RawTemplate as R, type ShikiTransformerFactory as S, type TemplateModule as T, type AsciidocLoader as a, type AsciidocTemplate as b, type ShikiTransformerFactoryFn as c };