@d10f/asciidoc-astro-loader 0.1.0 → 0.2.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/README.md CHANGED
@@ -353,18 +353,27 @@ Using a converter might make more sense if you need to keep some state as the do
353
353
 
354
354
  ## Example
355
355
 
356
- This is an example taken from my own website to showcase how to use it in a real world setting. This configuration uses a custom converter, a custom Shiki transformer and points to a folder where custom templates are found:
356
+ This is an example taken from my own website to showcase how to use it in a real world setting:
357
357
 
358
358
  ```ts
359
359
  const blog = defineCollection({
360
360
  loader: asciidocLoader({
361
361
  base: 'src/content/blog',
362
+ images: {
363
+ imageUrl: '/',
364
+ },
362
365
  document: {
363
366
  template: './src/templates',
364
- converters: [admonitionConverter()],
367
+ converters: [
368
+ admonitionConverter(),
369
+ xrefConverter()
370
+ ],
365
371
  },
366
372
  syntaxHighlighting: {
367
- theme: 'catppuccin-frappe',
373
+ theme: {
374
+ light: 'catppuccin-latte',
375
+ dark: 'catppuccin-frappe',
376
+ },
368
377
  transformers: [
369
378
  transformerNotationDiff(),
370
379
  transformerNotationErrorLevel(),
@@ -373,6 +382,9 @@ const blog = defineCollection({
373
382
  transformerPrompt({
374
383
  langs: {
375
384
  console: '$',
385
+ prolog: {
386
+ hideBreak: true,
387
+ },
376
388
  },
377
389
  cssClasses: 'unselectable mr-2 opacity-50',
378
390
  }),
@@ -382,10 +394,38 @@ const blog = defineCollection({
382
394
  },
383
395
  },
384
396
  }),
385
- schema: z.object({
386
- doctitle: z.string(),
387
- description: z.string(),
388
- revdate: z.coerce.date(),
389
- }),
397
+ schema: z
398
+ .object({
399
+ doctitle: z.string(),
400
+ description: z.string(),
401
+ revdate: z.coerce.date(),
402
+ keywords: z.string().transform((t) => t.split(', ')),
403
+ technologies: z.string().transform((t) => t.split(' ')),
404
+ series: z.string().optional(),
405
+ 'series-prev': z.string().optional(),
406
+ 'series-next': z.string().optional(),
407
+ 'series-description': z.string().optional(),
408
+ })
409
+ .transform(({ doctitle, revdate, ...rest }) => ({
410
+ title: doctitle,
411
+ createdAt: revdate,
412
+ ...rest,
413
+ })),
390
414
  });
391
415
  ```
416
+
417
+ This configuration uses a couple of custom converters, a custom Shiki transformer and points to a folder where custom templates are found.
418
+
419
+ The first converter applies a simple CSS rule so that admonitions are placed on either side of the main document, in an alternate fashion.
420
+
421
+ The other converter is a little helper to rectify cross-reference links to other documents. I created it because cross-reference in AsciiDoc works by referencing a filename, whereas Astro uses the post title as the URL slug, which makes more sense in the context of the web. This converter handles the conversion so that I can keep things organized neatly based on what makes more sense: use filenames in the file system, and URL slugs in the web.
422
+
423
+ As for the custom Shiki transformer, that's just so that I control how code snippets look like when there's either a prefix expected, or when multi-line is supported. The classic example of this are console commands, but REPL interpreters are also a good example.
424
+
425
+ Here you can see it in action with a command that is written over multiple lines for clarity (horizontal overflow not shown here):
426
+
427
+ ![A ffmpeg command written over multiple lines showing only a single prompt](./assets/code-snippet-transformer-console.avif)
428
+
429
+ Notice the escaping of the newline character, which you might want to omit with the `hideBreak` option. This is useful to distinguish code from REPL interpreters:
430
+
431
+ ![A Prolog interpreter running a command that spans over multiple lines](./assets/code-snippet-transformer-prolog.avif)
@@ -5,7 +5,7 @@ import {
5
5
  // src/lib/shiki/transformers/transformAsciidocCallout.ts
6
6
  var transformAsciidocCallout = (options) => {
7
7
  return (node) => {
8
- const lineComments = ["//", "#", ";;", "%"];
8
+ const lineComments = ["//", "#", ";;", "%", "--"];
9
9
  const customLineComment = node.getAttribute("line-comment");
10
10
  if (customLineComment) {
11
11
  lineComments.push(escapeRegexCharacters(customLineComment));
@@ -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>;
@@ -169,6 +169,27 @@ declare class TemplateEngineRegistry {
169
169
  private loadTemplates;
170
170
  }
171
171
 
172
+ declare class AsciidocDocument {
173
+ private document;
174
+ private baseConverter;
175
+ constructor(filepath: string);
176
+ private get documentTitle();
177
+ get attributes(): any;
178
+ get title(): string;
179
+ get subtitle(): string;
180
+ get slug(): string;
181
+ get preamble(): string | undefined;
182
+ get description(): string;
183
+ get author(): string;
184
+ get authors(): Document.Author[];
185
+ get version(): string;
186
+ get createdAt(): string;
187
+ get keywords(): any;
188
+ get languages(): Set<BundledLanguage>;
189
+ setAttribute(attribute: string, value: string): void;
190
+ convert(converters?: CustomConverter[], templateEngine?: TemplateEngineRegistry): string;
191
+ }
192
+
172
193
  /**
173
194
  * Checks if the given property K is required in object T.
174
195
  *
@@ -206,7 +227,7 @@ type CustomConverter = {
206
227
  convert(node: AbstractNode, templateEngine?: TemplateEngineRegistry): string | null | undefined;
207
228
  };
208
229
  type CustomConverterFactoryFn<T extends object> = HasRequiredKeys<T> extends true ? (converterOptions: T) => CustomConverterFn : (converterOptions?: T) => CustomConverterFn;
209
- type CustomConverterFn = (opts: RequiredOptions, highlighter: HighlighterCore) => CustomConverter;
230
+ type CustomConverterFn = (opts: RequiredOptions, highlighter: HighlighterCore, docs: AsciidocDocument[]) => CustomConverter;
210
231
  type ShikiTransformerFactory<T extends object> = HasRequiredKeys<T> extends true ? (options: T) => ShikiTransformerFactoryFn : (options?: T) => ShikiTransformerFactoryFn;
211
232
  type ShikiTransformerFactoryFn = (node: AbstractNode) => ShikiTransformer;
212
233
  type CalloutOptions = Partial<{
@@ -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>;
@@ -169,6 +169,27 @@ declare class TemplateEngineRegistry {
169
169
  private loadTemplates;
170
170
  }
171
171
 
172
+ declare class AsciidocDocument {
173
+ private document;
174
+ private baseConverter;
175
+ constructor(filepath: string);
176
+ private get documentTitle();
177
+ get attributes(): any;
178
+ get title(): string;
179
+ get subtitle(): string;
180
+ get slug(): string;
181
+ get preamble(): string | undefined;
182
+ get description(): string;
183
+ get author(): string;
184
+ get authors(): Document.Author[];
185
+ get version(): string;
186
+ get createdAt(): string;
187
+ get keywords(): any;
188
+ get languages(): Set<BundledLanguage>;
189
+ setAttribute(attribute: string, value: string): void;
190
+ convert(converters?: CustomConverter[], templateEngine?: TemplateEngineRegistry): string;
191
+ }
192
+
172
193
  /**
173
194
  * Checks if the given property K is required in object T.
174
195
  *
@@ -206,7 +227,7 @@ type CustomConverter = {
206
227
  convert(node: AbstractNode, templateEngine?: TemplateEngineRegistry): string | null | undefined;
207
228
  };
208
229
  type CustomConverterFactoryFn<T extends object> = HasRequiredKeys<T> extends true ? (converterOptions: T) => CustomConverterFn : (converterOptions?: T) => CustomConverterFn;
209
- type CustomConverterFn = (opts: RequiredOptions, highlighter: HighlighterCore) => CustomConverter;
230
+ type CustomConverterFn = (opts: RequiredOptions, highlighter: HighlighterCore, docs: AsciidocDocument[]) => CustomConverter;
210
231
  type ShikiTransformerFactory<T extends object> = HasRequiredKeys<T> extends true ? (options: T) => ShikiTransformerFactoryFn : (options?: T) => ShikiTransformerFactoryFn;
211
232
  type ShikiTransformerFactoryFn = (node: AbstractNode) => ShikiTransformer;
212
233
  type CalloutOptions = Partial<{
package/dist/index.cjs CHANGED
@@ -617,7 +617,7 @@ var sourceCodeConverter = (converterOptions) => {
617
617
  // src/lib/shiki/transformers/transformAsciidocCallout.ts
618
618
  var transformAsciidocCallout = (options) => {
619
619
  return (node) => {
620
- const lineComments = ["//", "#", ";;", "%"];
620
+ const lineComments = ["//", "#", ";;", "%", "--"];
621
621
  const customLineComment = node.getAttribute("line-comment");
622
622
  if (customLineComment) {
623
623
  lineComments.push(escapeRegexCharacters(customLineComment));
@@ -721,7 +721,7 @@ function asciidocLoader(_options) {
721
721
  );
722
722
  }
723
723
  const converters = options.document.converters.map(
724
- (converter) => converter(options, highlighter)
724
+ (converter) => converter(options, highlighter, docs)
725
725
  );
726
726
  const hasSourceCodeConverter = converters.find(
727
727
  (converter) => converter.nodeContext === "listing" && converter?.nodeStyle === "source"
@@ -735,7 +735,7 @@ function asciidocLoader(_options) {
735
735
  options.syntaxHighlighting.callouts
736
736
  )
737
737
  ]
738
- })(options, highlighter)
738
+ })(options, highlighter, docs)
739
739
  );
740
740
  }
741
741
  await Promise.all(
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { LoaderContext } from 'astro/loaders';
2
- import { a as AsciidocLoader } from './index-B1d5alka.cjs';
3
- export { b as AsciidocTemplate, C as CustomConverterFactoryFn, F as FilesystemTemplate, N as NodeContext, R as RawTemplate } from './index-B1d5alka.cjs';
2
+ import { a as AsciidocLoader } from './index-Bbw2Lfb5.cjs';
3
+ export { b as AsciidocTemplate, C as CustomConverterFactoryFn, F as FilesystemTemplate, N as NodeContext, R as RawTemplate } from './index-Bbw2Lfb5.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-B1d5alka.js';
3
- export { b as AsciidocTemplate, C as CustomConverterFactoryFn, F as FilesystemTemplate, N as NodeContext, R as RawTemplate } from './index-B1d5alka.js';
2
+ import { a as AsciidocLoader } from './index-Bbw2Lfb5.js';
3
+ export { b as AsciidocTemplate, C as CustomConverterFactoryFn, F as FilesystemTemplate, N as NodeContext, R as RawTemplate } from './index-Bbw2Lfb5.js';
4
4
  export { transformAsciidocCallout, transformerPrompt } from './lib/shiki/transformers/index.js';
5
5
  import 'shiki';
6
6
  import 'asciidoctor';
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
- import {
2
- sourceCodeConverter
3
- } from "./chunk-SUQERYPQ.js";
4
1
  import {
5
2
  transformAsciidocCallout,
6
3
  transformerPrompt
7
- } from "./chunk-TCLZUBH3.js";
4
+ } from "./chunk-KPBQHX55.js";
5
+ import {
6
+ sourceCodeConverter
7
+ } from "./chunk-SUQERYPQ.js";
8
8
  import {
9
9
  slugify,
10
10
  splitFilenameComponents
@@ -429,7 +429,7 @@ function asciidocLoader(_options) {
429
429
  );
430
430
  }
431
431
  const converters = options.document.converters.map(
432
- (converter) => converter(options, highlighter)
432
+ (converter) => converter(options, highlighter, docs)
433
433
  );
434
434
  const hasSourceCodeConverter = converters.find(
435
435
  (converter) => converter.nodeContext === "listing" && converter?.nodeStyle === "source"
@@ -443,7 +443,7 @@ function asciidocLoader(_options) {
443
443
  options.syntaxHighlighting.callouts
444
444
  )
445
445
  ]
446
- })(options, highlighter)
446
+ })(options, highlighter, docs)
447
447
  );
448
448
  }
449
449
  await Promise.all(
@@ -1,5 +1,5 @@
1
1
  import { ShikiTransformer } from 'shiki';
2
- import { C as CustomConverterFactoryFn, c as ShikiTransformerFactoryFn } from '../../../index-B1d5alka.cjs';
2
+ import { C as CustomConverterFactoryFn, c as ShikiTransformerFactoryFn } from '../../../index-Bbw2Lfb5.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-B1d5alka.js';
2
+ import { C as CustomConverterFactoryFn, c as ShikiTransformerFactoryFn } from '../../../index-Bbw2Lfb5.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-B1d5alka.cjs';
1
+ import { A as AbstractEngine, b as AsciidocTemplate, T as TemplateModule, F as FilesystemTemplate, R as RawTemplate } from '../../../../index-Bbw2Lfb5.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-B1d5alka.js';
1
+ import { A as AbstractEngine, b as AsciidocTemplate, T as TemplateModule, F as FilesystemTemplate, R as RawTemplate } from '../../../../index-Bbw2Lfb5.js';
2
2
  import { AbstractBlock } from 'asciidoctor';
3
3
  import 'shiki';
4
4
  import 'astro/zod';
@@ -34,7 +34,7 @@ function escapeRegexCharacters(str) {
34
34
  // src/lib/shiki/transformers/transformAsciidocCallout.ts
35
35
  var transformAsciidocCallout = (options) => {
36
36
  return (node) => {
37
- const lineComments = ["//", "#", ";;", "%"];
37
+ const lineComments = ["//", "#", ";;", "%", "--"];
38
38
  const customLineComment = node.getAttribute("line-comment");
39
39
  if (customLineComment) {
40
40
  lineComments.push(escapeRegexCharacters(customLineComment));
@@ -1,4 +1,4 @@
1
- import { S as ShikiTransformerFactory } from '../../../index-B1d5alka.cjs';
1
+ import { S as ShikiTransformerFactory } from '../../../index-Bbw2Lfb5.cjs';
2
2
  import { BundledLanguage } from 'shiki';
3
3
  import 'asciidoctor';
4
4
  import 'astro/zod';
@@ -1,4 +1,4 @@
1
- import { S as ShikiTransformerFactory } from '../../../index-B1d5alka.js';
1
+ import { S as ShikiTransformerFactory } from '../../../index-Bbw2Lfb5.js';
2
2
  import { BundledLanguage } from 'shiki';
3
3
  import 'asciidoctor';
4
4
  import 'astro/zod';
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  transformAsciidocCallout,
3
3
  transformerPrompt
4
- } from "../../../chunk-TCLZUBH3.js";
4
+ } from "../../../chunk-KPBQHX55.js";
5
5
  import "../../../chunk-2UGTFP4R.js";
6
6
  export {
7
7
  transformAsciidocCallout,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@d10f/asciidoc-astro-loader",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "An Astro collections loader for Asciidoc files",
5
5
  "author": "D10f",
6
6
  "license": "MIT",
@@ -47,12 +47,12 @@
47
47
  "tsup": "^8.5.0",
48
48
  "typescript": "^5.9.3",
49
49
  "typescript-eslint": "^8.45.0",
50
- "vitest": "^3.2.4"
50
+ "vitest": "^5.0.3"
51
51
  },
52
52
  "dependencies": {
53
- "@shikijs/transformers": "^3.20.0",
53
+ "@shikijs/transformers": "^4.5.0",
54
54
  "asciidoctor": "^3.0.4",
55
- "shiki": "^3.20.0"
55
+ "shiki": "^4.5.0"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "astro": "^6.3.1"