@d10f/asciidoc-astro-loader 0.0.9 → 0.0.10

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.
@@ -21,19 +21,20 @@ var sourceCodeConverter = (converterOptions) => {
21
21
  return typeof transformer === "function" ? transformer(node) : transformer;
22
22
  })
23
23
  });
24
- if (templateEngine && template) {
25
- const { extension } = splitFilenameComponents(template);
26
- const engine = templateEngine.getEngineByExtension(
27
- extension || ""
24
+ if (templateEngine) {
25
+ const { extension } = splitFilenameComponents(
26
+ template ?? ""
28
27
  );
29
- if (engine) {
28
+ const engine = extension ? templateEngine.getEngineByExtension(extension ?? "") : templateEngine.getEngineByContext(this.nodeContext);
29
+ if (template) {
30
30
  const templateFile = resolve(process.cwd(), template);
31
- if (engine.canRenderFile) {
32
- return engine.renderFile(templateFile, {
33
- content: output,
34
- lang
35
- });
36
- }
31
+ engine?.addContext(this.nodeContext, templateFile);
32
+ }
33
+ if (engine) {
34
+ return engine.renderNode(node, {
35
+ content: output,
36
+ lang
37
+ });
37
38
  }
38
39
  }
39
40
  return output;
@@ -317,6 +317,10 @@ declare class TemplateEngineRegistry {
317
317
  * Returns the module that supports the given extension.
318
318
  */
319
319
  getEngineByExtension(ext: string): (AbstractEngine & AsciidocTemplate) | undefined;
320
+ /**
321
+ * Returns the first module that supports the given context.
322
+ */
323
+ getEngineByContext(context: NodeContext): (AbstractEngine & AsciidocTemplate) | undefined;
320
324
  /**
321
325
  * Converts the provided node using one of the registered template
322
326
  * engine modules. For more granular control, gain access to the
@@ -317,6 +317,10 @@ declare class TemplateEngineRegistry {
317
317
  * Returns the module that supports the given extension.
318
318
  */
319
319
  getEngineByExtension(ext: string): (AbstractEngine & AsciidocTemplate) | undefined;
320
+ /**
321
+ * Returns the first module that supports the given context.
322
+ */
323
+ getEngineByContext(context: NodeContext): (AbstractEngine & AsciidocTemplate) | undefined;
320
324
  /**
321
325
  * Converts the provided node using one of the registered template
322
326
  * engine modules. For more granular control, gain access to the
package/dist/index.cjs CHANGED
@@ -193,6 +193,14 @@ var TemplateEngineRegistry = class _TemplateEngineRegistry {
193
193
  (m) => m.extensions.includes(ext)
194
194
  );
195
195
  }
196
+ /**
197
+ * Returns the first module that supports the given context.
198
+ */
199
+ getEngineByContext(context) {
200
+ return _TemplateEngineRegistry.modules.find(
201
+ (m) => m.hasContext(context)
202
+ );
203
+ }
196
204
  /**
197
205
  * Converts the provided node using one of the registered template
198
206
  * engine modules. For more granular control, gain access to the
@@ -570,19 +578,20 @@ var sourceCodeConverter = (converterOptions) => {
570
578
  return typeof transformer === "function" ? transformer(node) : transformer;
571
579
  })
572
580
  });
573
- if (templateEngine && template) {
574
- const { extension } = splitFilenameComponents(template);
575
- const engine = templateEngine.getEngineByExtension(
576
- extension || ""
581
+ if (templateEngine) {
582
+ const { extension } = splitFilenameComponents(
583
+ template ?? ""
577
584
  );
578
- if (engine) {
585
+ const engine = extension ? templateEngine.getEngineByExtension(extension ?? "") : templateEngine.getEngineByContext(this.nodeContext);
586
+ if (template) {
579
587
  const templateFile = (0, import_node_path2.resolve)(process.cwd(), template);
580
- if (engine.canRenderFile) {
581
- return engine.renderFile(templateFile, {
582
- content: output,
583
- lang
584
- });
585
- }
588
+ engine?.addContext(this.nodeContext, templateFile);
589
+ }
590
+ if (engine) {
591
+ return engine.renderNode(node, {
592
+ content: output,
593
+ lang
594
+ });
586
595
  }
587
596
  }
588
597
  return output;
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { LoaderContext } from 'astro/loaders';
2
- import { A as AsciidocLoader } from './index-DwboxIUQ.cjs';
3
- export { a as AsciidocTemplate, C as CustomConverterFactoryFn, F as FilesystemTemplate, N as NodeContext, R as RawTemplate } from './index-DwboxIUQ.cjs';
2
+ import { A as AsciidocLoader } from './index-C8nJcG2h.cjs';
3
+ export { a as AsciidocTemplate, C as CustomConverterFactoryFn, F as FilesystemTemplate, N as NodeContext, R as RawTemplate } from './index-C8nJcG2h.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-DwboxIUQ.js';
3
- export { a as AsciidocTemplate, C as CustomConverterFactoryFn, F as FilesystemTemplate, N as NodeContext, R as RawTemplate } from './index-DwboxIUQ.js';
2
+ import { A as AsciidocLoader } from './index-C8nJcG2h.js';
3
+ export { a as AsciidocTemplate, C as CustomConverterFactoryFn, F as FilesystemTemplate, N as NodeContext, R as RawTemplate } from './index-C8nJcG2h.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,6 +1,6 @@
1
1
  import {
2
2
  sourceCodeConverter
3
- } from "./chunk-NC6IZHLR.js";
3
+ } from "./chunk-SUQERYPQ.js";
4
4
  import {
5
5
  transformAsciidocCallout,
6
6
  transformerPrompt
@@ -155,6 +155,14 @@ var TemplateEngineRegistry = class _TemplateEngineRegistry {
155
155
  (m) => m.extensions.includes(ext)
156
156
  );
157
157
  }
158
+ /**
159
+ * Returns the first module that supports the given context.
160
+ */
161
+ getEngineByContext(context) {
162
+ return _TemplateEngineRegistry.modules.find(
163
+ (m) => m.hasContext(context)
164
+ );
165
+ }
158
166
  /**
159
167
  * Converts the provided node using one of the registered template
160
168
  * engine modules. For more granular control, gain access to the
@@ -55,19 +55,20 @@ var sourceCodeConverter = (converterOptions) => {
55
55
  return typeof transformer === "function" ? transformer(node) : transformer;
56
56
  })
57
57
  });
58
- if (templateEngine && template) {
59
- const { extension } = splitFilenameComponents(template);
60
- const engine = templateEngine.getEngineByExtension(
61
- extension || ""
58
+ if (templateEngine) {
59
+ const { extension } = splitFilenameComponents(
60
+ template ?? ""
62
61
  );
63
- if (engine) {
62
+ const engine = extension ? templateEngine.getEngineByExtension(extension ?? "") : templateEngine.getEngineByContext(this.nodeContext);
63
+ if (template) {
64
64
  const templateFile = (0, import_node_path.resolve)(process.cwd(), template);
65
- if (engine.canRenderFile) {
66
- return engine.renderFile(templateFile, {
67
- content: output,
68
- lang
69
- });
70
- }
65
+ engine?.addContext(this.nodeContext, templateFile);
66
+ }
67
+ if (engine) {
68
+ return engine.renderNode(node, {
69
+ content: output,
70
+ lang
71
+ });
71
72
  }
72
73
  }
73
74
  return output;
@@ -1,5 +1,5 @@
1
1
  import { ShikiTransformer } from 'shiki';
2
- import { C as CustomConverterFactoryFn, S as ShikiTransformerFactoryFn } from '../../../index-DwboxIUQ.cjs';
2
+ import { C as CustomConverterFactoryFn, S as ShikiTransformerFactoryFn } from '../../../index-C8nJcG2h.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, S as ShikiTransformerFactoryFn } from '../../../index-DwboxIUQ.js';
2
+ import { C as CustomConverterFactoryFn, S as ShikiTransformerFactoryFn } from '../../../index-C8nJcG2h.js';
3
3
  import 'asciidoctor';
4
4
  import 'astro/zod';
5
5
 
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  sourceCodeConverter
3
- } from "../../../chunk-NC6IZHLR.js";
3
+ } from "../../../chunk-SUQERYPQ.js";
4
4
  import "../../../chunk-2UGTFP4R.js";
5
5
  export {
6
6
  sourceCodeConverter
@@ -1,4 +1,4 @@
1
- import { b as AbstractEngine, a as AsciidocTemplate, T as TemplateModule, F as FilesystemTemplate, R as RawTemplate } from '../../../../index-DwboxIUQ.cjs';
1
+ import { b as AbstractEngine, a as AsciidocTemplate, T as TemplateModule, F as FilesystemTemplate, R as RawTemplate } from '../../../../index-C8nJcG2h.cjs';
2
2
  import { AbstractBlock } from 'asciidoctor';
3
3
  import 'shiki';
4
4
  import 'astro/zod';
@@ -1,4 +1,4 @@
1
- import { b as AbstractEngine, a as AsciidocTemplate, T as TemplateModule, F as FilesystemTemplate, R as RawTemplate } from '../../../../index-DwboxIUQ.js';
1
+ import { b as AbstractEngine, a as AsciidocTemplate, T as TemplateModule, F as FilesystemTemplate, R as RawTemplate } from '../../../../index-C8nJcG2h.js';
2
2
  import { AbstractBlock } from 'asciidoctor';
3
3
  import 'shiki';
4
4
  import 'astro/zod';
@@ -1,4 +1,4 @@
1
- import { c as ShikiTransformerFactory } from '../../../index-DwboxIUQ.cjs';
1
+ import { c as ShikiTransformerFactory } from '../../../index-C8nJcG2h.cjs';
2
2
  import { BundledLanguage } from 'shiki/types';
3
3
  import 'shiki';
4
4
  import 'asciidoctor';
@@ -1,4 +1,4 @@
1
- import { c as ShikiTransformerFactory } from '../../../index-DwboxIUQ.js';
1
+ import { c as ShikiTransformerFactory } from '../../../index-C8nJcG2h.js';
2
2
  import { BundledLanguage } from 'shiki/types';
3
3
  import 'shiki';
4
4
  import 'asciidoctor';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@d10f/asciidoc-astro-loader",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "description": "An Astro collections loader for Asciidoc files",
5
5
  "author": "D10f",
6
6
  "license": "MIT",