@d10f/asciidoc-astro-loader 0.0.4 → 0.0.5
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 +1 -1
- package/dist/{index-CS3PBqxf.d.cts → index-R3g0cYiE.d.cts} +1 -1
- package/dist/{index-CS3PBqxf.d.ts → index-R3g0cYiE.d.ts} +1 -1
- package/dist/index.cjs +40 -2
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +44 -5
- package/dist/lib/asciidoc/converters/index.d.cts +1 -1
- package/dist/lib/asciidoc/converters/index.d.ts +1 -1
- 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 +1 -44
- package/dist/lib/shiki/transformers/index.d.cts +3 -42
- package/dist/lib/shiki/transformers/index.d.ts +3 -42
- package/dist/lib/shiki/transformers/index.js +1 -43
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -179,7 +179,7 @@ Just like regular Asciidoctor.js, any files located here will be used to replace
|
|
|
179
179
|
|
|
180
180
|
### Registering A Templating Engine
|
|
181
181
|
|
|
182
|
-
By default, only Handlebars and Nunjucks are
|
|
182
|
+
Templates can be written as plain functions that return an HTML string, or as templates written in a format supported by one of the registered templating engines. By default, only Handlebars and Nunjucks are supported, but you can create your own. A templating engine in the context of this package is a class that extends the `AbstractEngine` class:
|
|
183
183
|
|
|
184
184
|
```ts
|
|
185
185
|
import { Php, Request } from '@platformatic/php-node';
|
|
@@ -542,4 +542,4 @@ interface RawTemplate {
|
|
|
542
542
|
renderString(content: string, options?: Record<string, unknown>): string;
|
|
543
543
|
}
|
|
544
544
|
|
|
545
|
-
export { type AsciidocLoader as A, type CustomConverterFactoryFn as C, type FilesystemTemplate as F, type NodeContext as N, type RawTemplate as R, type
|
|
545
|
+
export { type AsciidocLoader 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 AsciidocTemplate as a, type ShikiTransformerFactoryFn as b, AbstractEngine as c };
|
|
@@ -542,4 +542,4 @@ interface RawTemplate {
|
|
|
542
542
|
renderString(content: string, options?: Record<string, unknown>): string;
|
|
543
543
|
}
|
|
544
544
|
|
|
545
|
-
export { type AsciidocLoader as A, type CustomConverterFactoryFn as C, type FilesystemTemplate as F, type NodeContext as N, type RawTemplate as R, type
|
|
545
|
+
export { type AsciidocLoader 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 AsciidocTemplate as a, type ShikiTransformerFactoryFn as b, AbstractEngine as c };
|
package/dist/index.cjs
CHANGED
|
@@ -260,6 +260,15 @@ var AsciidocDocument = class {
|
|
|
260
260
|
const [preambleBlock] = documentBlock?.getBlocks();
|
|
261
261
|
if (preambleBlock) return preambleBlock.getSourceLines()[0];
|
|
262
262
|
}
|
|
263
|
+
get description() {
|
|
264
|
+
return this.document.getAttribute("description", "");
|
|
265
|
+
}
|
|
266
|
+
get author() {
|
|
267
|
+
return this.document.getAuthor();
|
|
268
|
+
}
|
|
269
|
+
get authors() {
|
|
270
|
+
return this.document.getAuthors();
|
|
271
|
+
}
|
|
263
272
|
get version() {
|
|
264
273
|
return this.document.getRevisionNumber();
|
|
265
274
|
}
|
|
@@ -416,6 +425,26 @@ var NunjucksEngine = class extends AbstractEngine {
|
|
|
416
425
|
}
|
|
417
426
|
};
|
|
418
427
|
|
|
428
|
+
// src/lib/asciidoc/templates/engines/TemplateStr.ts
|
|
429
|
+
var TemplateStr = class extends AbstractEngine {
|
|
430
|
+
renderMap;
|
|
431
|
+
constructor(name = "templateStr", extensions = ["ts", "js"]) {
|
|
432
|
+
super(name, extensions);
|
|
433
|
+
this.renderMap = /* @__PURE__ */ new Map();
|
|
434
|
+
}
|
|
435
|
+
async load() {
|
|
436
|
+
for (const [context, path] of this.templateList.entries()) {
|
|
437
|
+
const templateFn = await import(path);
|
|
438
|
+
this.renderMap.set(context, templateFn.default);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
renderNode(node, options) {
|
|
442
|
+
const context = node.getNodeName();
|
|
443
|
+
const renderFn = this.renderMap.get(context);
|
|
444
|
+
return renderFn ? renderFn(node, options) : "";
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
|
|
419
448
|
// src/schemas/index.ts
|
|
420
449
|
var import_zod3 = require("astro/zod");
|
|
421
450
|
|
|
@@ -624,7 +653,8 @@ function asciidocLoader(_options) {
|
|
|
624
653
|
if (options.document.templateEngines === void 0) {
|
|
625
654
|
options.document.templateEngines = [
|
|
626
655
|
new HandlebarsEngine(),
|
|
627
|
-
new NunjucksEngine()
|
|
656
|
+
new NunjucksEngine(),
|
|
657
|
+
new TemplateStr()
|
|
628
658
|
];
|
|
629
659
|
}
|
|
630
660
|
let highlighter;
|
|
@@ -715,8 +745,16 @@ async function setDocument(doc, converters, templateEngine, { parseData, store }
|
|
|
715
745
|
id: doc.slug,
|
|
716
746
|
data: {
|
|
717
747
|
title: doc.title,
|
|
748
|
+
subtitle: doc.subtitle,
|
|
749
|
+
author: doc.author,
|
|
750
|
+
authors: doc.authors,
|
|
751
|
+
version: doc.version,
|
|
718
752
|
createdAt: new Date(doc.createdAt),
|
|
719
|
-
|
|
753
|
+
email: doc.authors.at(0)?.getEmail(),
|
|
754
|
+
description: doc.description,
|
|
755
|
+
slug: doc.slug,
|
|
756
|
+
preamble: doc.preamble,
|
|
757
|
+
keywords: doc.keywords
|
|
720
758
|
}
|
|
721
759
|
});
|
|
722
760
|
store.set({
|
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 { a as AsciidocTemplate, C as CustomConverterFactoryFn, F as FilesystemTemplate, N as NodeContext, R as RawTemplate } from './index-
|
|
2
|
+
import { A as AsciidocLoader } from './index-R3g0cYiE.cjs';
|
|
3
|
+
export { a as AsciidocTemplate, C as CustomConverterFactoryFn, F as FilesystemTemplate, N as NodeContext, R as RawTemplate } from './index-R3g0cYiE.cjs';
|
|
4
4
|
import 'shiki';
|
|
5
5
|
import 'asciidoctor';
|
|
6
6
|
import 'astro/zod';
|
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 { a as AsciidocTemplate, C as CustomConverterFactoryFn, F as FilesystemTemplate, N as NodeContext, R as RawTemplate } from './index-
|
|
2
|
+
import { A as AsciidocLoader } from './index-R3g0cYiE.js';
|
|
3
|
+
export { a as AsciidocTemplate, C as CustomConverterFactoryFn, F as FilesystemTemplate, N as NodeContext, R as RawTemplate } from './index-R3g0cYiE.js';
|
|
4
4
|
import 'shiki';
|
|
5
5
|
import 'asciidoctor';
|
|
6
6
|
import 'astro/zod';
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
sourceCodeConverter
|
|
3
|
-
} from "./chunk-NC6IZHLR.js";
|
|
4
1
|
import {
|
|
5
2
|
transformAsciidocCallout
|
|
6
3
|
} from "./chunk-5P6LDJGO.js";
|
|
4
|
+
import {
|
|
5
|
+
sourceCodeConverter
|
|
6
|
+
} from "./chunk-NC6IZHLR.js";
|
|
7
7
|
import {
|
|
8
8
|
slugify,
|
|
9
9
|
splitFilenameComponents
|
|
10
10
|
} from "./chunk-2UGTFP4R.js";
|
|
11
11
|
import {
|
|
12
|
+
AbstractEngine,
|
|
12
13
|
HandlebarsEngine,
|
|
13
14
|
NunjucksEngine
|
|
14
15
|
} from "./chunk-2F52PMNV.js";
|
|
@@ -222,6 +223,15 @@ var AsciidocDocument = class {
|
|
|
222
223
|
const [preambleBlock] = documentBlock?.getBlocks();
|
|
223
224
|
if (preambleBlock) return preambleBlock.getSourceLines()[0];
|
|
224
225
|
}
|
|
226
|
+
get description() {
|
|
227
|
+
return this.document.getAttribute("description", "");
|
|
228
|
+
}
|
|
229
|
+
get author() {
|
|
230
|
+
return this.document.getAuthor();
|
|
231
|
+
}
|
|
232
|
+
get authors() {
|
|
233
|
+
return this.document.getAuthors();
|
|
234
|
+
}
|
|
225
235
|
get version() {
|
|
226
236
|
return this.document.getRevisionNumber();
|
|
227
237
|
}
|
|
@@ -249,6 +259,26 @@ var AsciidocDocument = class {
|
|
|
249
259
|
}
|
|
250
260
|
};
|
|
251
261
|
|
|
262
|
+
// src/lib/asciidoc/templates/engines/TemplateStr.ts
|
|
263
|
+
var TemplateStr = class extends AbstractEngine {
|
|
264
|
+
renderMap;
|
|
265
|
+
constructor(name = "templateStr", extensions = ["ts", "js"]) {
|
|
266
|
+
super(name, extensions);
|
|
267
|
+
this.renderMap = /* @__PURE__ */ new Map();
|
|
268
|
+
}
|
|
269
|
+
async load() {
|
|
270
|
+
for (const [context, path] of this.templateList.entries()) {
|
|
271
|
+
const templateFn = await import(path);
|
|
272
|
+
this.renderMap.set(context, templateFn.default);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
renderNode(node, options) {
|
|
276
|
+
const context = node.getNodeName();
|
|
277
|
+
const renderFn = this.renderMap.get(context);
|
|
278
|
+
return renderFn ? renderFn(node, options) : "";
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
|
|
252
282
|
// src/schemas/index.ts
|
|
253
283
|
import { z as z3 } from "astro/zod";
|
|
254
284
|
|
|
@@ -359,7 +389,8 @@ function asciidocLoader(_options) {
|
|
|
359
389
|
if (options.document.templateEngines === void 0) {
|
|
360
390
|
options.document.templateEngines = [
|
|
361
391
|
new HandlebarsEngine(),
|
|
362
|
-
new NunjucksEngine()
|
|
392
|
+
new NunjucksEngine(),
|
|
393
|
+
new TemplateStr()
|
|
363
394
|
];
|
|
364
395
|
}
|
|
365
396
|
let highlighter;
|
|
@@ -450,8 +481,16 @@ async function setDocument(doc, converters, templateEngine, { parseData, store }
|
|
|
450
481
|
id: doc.slug,
|
|
451
482
|
data: {
|
|
452
483
|
title: doc.title,
|
|
484
|
+
subtitle: doc.subtitle,
|
|
485
|
+
author: doc.author,
|
|
486
|
+
authors: doc.authors,
|
|
487
|
+
version: doc.version,
|
|
453
488
|
createdAt: new Date(doc.createdAt),
|
|
454
|
-
|
|
489
|
+
email: doc.authors.at(0)?.getEmail(),
|
|
490
|
+
description: doc.description,
|
|
491
|
+
slug: doc.slug,
|
|
492
|
+
preamble: doc.preamble,
|
|
493
|
+
keywords: doc.keywords
|
|
455
494
|
}
|
|
456
495
|
});
|
|
457
496
|
store.set({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ShikiTransformer } from 'shiki';
|
|
2
|
-
import { C as CustomConverterFactoryFn,
|
|
2
|
+
import { C as CustomConverterFactoryFn, b as ShikiTransformerFactoryFn } from '../../../index-R3g0cYiE.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,
|
|
2
|
+
import { C as CustomConverterFactoryFn, b as ShikiTransformerFactoryFn } from '../../../index-R3g0cYiE.js';
|
|
3
3
|
import 'asciidoctor';
|
|
4
4
|
import 'astro/zod';
|
|
5
5
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as AbstractEngine, a as AsciidocTemplate, T as TemplateModule, F as FilesystemTemplate, R as RawTemplate } from '../../../../index-
|
|
1
|
+
import { c as AbstractEngine, a as AsciidocTemplate, T as TemplateModule, F as FilesystemTemplate, R as RawTemplate } from '../../../../index-R3g0cYiE.cjs';
|
|
2
2
|
import { AbstractBlock } from 'asciidoctor';
|
|
3
3
|
import 'shiki';
|
|
4
4
|
import 'astro/zod';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as AbstractEngine, a as AsciidocTemplate, T as TemplateModule, F as FilesystemTemplate, R as RawTemplate } from '../../../../index-
|
|
1
|
+
import { c as AbstractEngine, a as AsciidocTemplate, T as TemplateModule, F as FilesystemTemplate, R as RawTemplate } from '../../../../index-R3g0cYiE.js';
|
|
2
2
|
import { AbstractBlock } from 'asciidoctor';
|
|
3
3
|
import 'shiki';
|
|
4
4
|
import 'astro/zod';
|
|
@@ -21,7 +21,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var transformers_exports = {};
|
|
22
22
|
__export(transformers_exports, {
|
|
23
23
|
transformAsciidocCallout: () => transformAsciidocCallout,
|
|
24
|
-
transformConsolePrompt: () => transformConsolePrompt,
|
|
25
24
|
transformerPrompt: () => transformerPrompt
|
|
26
25
|
});
|
|
27
26
|
module.exports = __toCommonJS(transformers_exports);
|
|
@@ -90,47 +89,6 @@ var transformAsciidocCallout = (options) => {
|
|
|
90
89
|
};
|
|
91
90
|
};
|
|
92
91
|
|
|
93
|
-
// src/lib/shiki/transformers/transformConsolePrompt.ts
|
|
94
|
-
var transformConsolePrompt = (options) => {
|
|
95
|
-
return (node) => {
|
|
96
|
-
const language = node.getAttribute("language");
|
|
97
|
-
const cssClasses = options?.cssClasses;
|
|
98
|
-
const promptChar = options?.promptChar ?? "$";
|
|
99
|
-
const unselectablePrompt = `<span $1 class="${cssClasses}">${promptChar}</span>`;
|
|
100
|
-
const linePrefix = '<span class="line[^>]+?>';
|
|
101
|
-
const splitPrompt = new RegExp(
|
|
102
|
-
`(?<=${linePrefix})(?:<span (style="[^"]*?")>\\s*?\\${promptChar}\\s+?([^<]))`
|
|
103
|
-
);
|
|
104
|
-
const trimWhitespace = new RegExp(
|
|
105
|
-
`(?<=${linePrefix})(?:<span (style="[^"]*?")>\\s*?\\${promptChar}\\s*?<\\/span>(?:<span>\\s+<\\/span>)?)`
|
|
106
|
-
);
|
|
107
|
-
const trimWhitespaceAhead = new RegExp(
|
|
108
|
-
`(?<=${linePrefix}<span [^>]+?>\\${promptChar}<\\/span>)(<span style="[^"]+?">)\\s+?`
|
|
109
|
-
);
|
|
110
|
-
return {
|
|
111
|
-
line(hast) {
|
|
112
|
-
if (language !== "console") return;
|
|
113
|
-
const textNode = hast.children.at(0)?.children.at(0);
|
|
114
|
-
if (textNode && textNode.type === "text") {
|
|
115
|
-
const leadingChar = textNode.value;
|
|
116
|
-
if (!leadingChar.startsWith(promptChar)) {
|
|
117
|
-
textNode.value = promptChar + " " + textNode.value;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
postprocess: (html) => {
|
|
122
|
-
if (language !== "console") return;
|
|
123
|
-
return html.split("\n").map((line) => {
|
|
124
|
-
return line.replace(
|
|
125
|
-
splitPrompt,
|
|
126
|
-
unselectablePrompt + "<span $1>$2"
|
|
127
|
-
).replace(trimWhitespace, unselectablePrompt).replace(trimWhitespaceAhead, "$1");
|
|
128
|
-
}).join("\n");
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
};
|
|
132
|
-
};
|
|
133
|
-
|
|
134
92
|
// src/lib/shiki/transformers/transformerPrompt.ts
|
|
135
93
|
var transformerPrompt = (options) => {
|
|
136
94
|
return (node) => {
|
|
@@ -138,7 +96,7 @@ var transformerPrompt = (options) => {
|
|
|
138
96
|
const customPrompt = node.getAttribute(
|
|
139
97
|
options?.promptAttribute ?? "custom-prompt"
|
|
140
98
|
);
|
|
141
|
-
const promptToAdd = customPrompt ?? (options?.
|
|
99
|
+
const promptToAdd = customPrompt ?? (options?.langs && options.langs[language]);
|
|
142
100
|
const cssClasses = typeof promptToAdd === "object" ? promptToAdd.cssClasses : options?.cssClasses;
|
|
143
101
|
return {
|
|
144
102
|
line(hast) {
|
|
@@ -163,6 +121,5 @@ var transformerPrompt = (options) => {
|
|
|
163
121
|
// Annotate the CommonJS export names for ESM import in node:
|
|
164
122
|
0 && (module.exports = {
|
|
165
123
|
transformAsciidocCallout,
|
|
166
|
-
transformConsolePrompt,
|
|
167
124
|
transformerPrompt
|
|
168
125
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { S as ShikiTransformerFactory } from '../../../index-R3g0cYiE.cjs';
|
|
2
2
|
import { BundledLanguage } from 'shiki/types';
|
|
3
3
|
import 'shiki';
|
|
4
4
|
import 'asciidoctor';
|
|
@@ -9,45 +9,6 @@ type TransformerOptions = Partial<{
|
|
|
9
9
|
}>;
|
|
10
10
|
declare const transformAsciidocCallout: ShikiTransformerFactory<TransformerOptions>;
|
|
11
11
|
|
|
12
|
-
type TransformOptions$1 = {
|
|
13
|
-
/**
|
|
14
|
-
* String of CSS classes to apply to leading prompt character(s) on
|
|
15
|
-
* source code blocks of type console.
|
|
16
|
-
*/
|
|
17
|
-
cssClasses: string;
|
|
18
|
-
/**
|
|
19
|
-
* The prompt character representing the actual console prompt.
|
|
20
|
-
*
|
|
21
|
-
* @default $
|
|
22
|
-
*/
|
|
23
|
-
promptChar?: string;
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* For code blocks of language "console", prepends each line with a
|
|
27
|
-
* prompt character(s), where applicable. By default, a "$" is used but
|
|
28
|
-
* this can be controlled via the *promptChar* option.
|
|
29
|
-
* Use the *cssClasses* option to style this prompt for things like
|
|
30
|
-
* making it unselectable, or dimmed..
|
|
31
|
-
*
|
|
32
|
-
* In addition, the leading spaces before the actual command are deleted
|
|
33
|
-
* from the span elements generated by Shiki to avoid accidentally
|
|
34
|
-
* running commands that would not appear in the shell history.
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* before: <span>$ npm run dev</span>
|
|
38
|
-
* after: <span>$</span><span>npm run dev</span>
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* before: <span> $ </span><span> </span>
|
|
42
|
-
* before: <span> $ </span>
|
|
43
|
-
* after: <span>$</span>
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* before: <span>$</span><span> npm run dev</span>
|
|
47
|
-
* after: <span>$</span><span>npm run dev</span>
|
|
48
|
-
*/
|
|
49
|
-
declare const transformConsolePrompt: ShikiTransformerFactory<TransformOptions$1>;
|
|
50
|
-
|
|
51
12
|
type PromptOptions = {
|
|
52
13
|
prompt: string;
|
|
53
14
|
cssClasses: string;
|
|
@@ -65,7 +26,7 @@ type TransformOptions = {
|
|
|
65
26
|
* want to style them differently from the
|
|
66
27
|
* If not provided, it will default to look at the block attribute.
|
|
67
28
|
*/
|
|
68
|
-
|
|
29
|
+
langs?: Partial<Record<BundledLanguage, PromptOptions | string>>;
|
|
69
30
|
/**
|
|
70
31
|
* The name of the block attribute on the original document to look
|
|
71
32
|
* for and use as the prompt for this block.
|
|
@@ -76,4 +37,4 @@ type TransformOptions = {
|
|
|
76
37
|
};
|
|
77
38
|
declare const transformerPrompt: ShikiTransformerFactory<TransformOptions>;
|
|
78
39
|
|
|
79
|
-
export { transformAsciidocCallout,
|
|
40
|
+
export { transformAsciidocCallout, transformerPrompt };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { S as ShikiTransformerFactory } from '../../../index-R3g0cYiE.js';
|
|
2
2
|
import { BundledLanguage } from 'shiki/types';
|
|
3
3
|
import 'shiki';
|
|
4
4
|
import 'asciidoctor';
|
|
@@ -9,45 +9,6 @@ type TransformerOptions = Partial<{
|
|
|
9
9
|
}>;
|
|
10
10
|
declare const transformAsciidocCallout: ShikiTransformerFactory<TransformerOptions>;
|
|
11
11
|
|
|
12
|
-
type TransformOptions$1 = {
|
|
13
|
-
/**
|
|
14
|
-
* String of CSS classes to apply to leading prompt character(s) on
|
|
15
|
-
* source code blocks of type console.
|
|
16
|
-
*/
|
|
17
|
-
cssClasses: string;
|
|
18
|
-
/**
|
|
19
|
-
* The prompt character representing the actual console prompt.
|
|
20
|
-
*
|
|
21
|
-
* @default $
|
|
22
|
-
*/
|
|
23
|
-
promptChar?: string;
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* For code blocks of language "console", prepends each line with a
|
|
27
|
-
* prompt character(s), where applicable. By default, a "$" is used but
|
|
28
|
-
* this can be controlled via the *promptChar* option.
|
|
29
|
-
* Use the *cssClasses* option to style this prompt for things like
|
|
30
|
-
* making it unselectable, or dimmed..
|
|
31
|
-
*
|
|
32
|
-
* In addition, the leading spaces before the actual command are deleted
|
|
33
|
-
* from the span elements generated by Shiki to avoid accidentally
|
|
34
|
-
* running commands that would not appear in the shell history.
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* before: <span>$ npm run dev</span>
|
|
38
|
-
* after: <span>$</span><span>npm run dev</span>
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* before: <span> $ </span><span> </span>
|
|
42
|
-
* before: <span> $ </span>
|
|
43
|
-
* after: <span>$</span>
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* before: <span>$</span><span> npm run dev</span>
|
|
47
|
-
* after: <span>$</span><span>npm run dev</span>
|
|
48
|
-
*/
|
|
49
|
-
declare const transformConsolePrompt: ShikiTransformerFactory<TransformOptions$1>;
|
|
50
|
-
|
|
51
12
|
type PromptOptions = {
|
|
52
13
|
prompt: string;
|
|
53
14
|
cssClasses: string;
|
|
@@ -65,7 +26,7 @@ type TransformOptions = {
|
|
|
65
26
|
* want to style them differently from the
|
|
66
27
|
* If not provided, it will default to look at the block attribute.
|
|
67
28
|
*/
|
|
68
|
-
|
|
29
|
+
langs?: Partial<Record<BundledLanguage, PromptOptions | string>>;
|
|
69
30
|
/**
|
|
70
31
|
* The name of the block attribute on the original document to look
|
|
71
32
|
* for and use as the prompt for this block.
|
|
@@ -76,4 +37,4 @@ type TransformOptions = {
|
|
|
76
37
|
};
|
|
77
38
|
declare const transformerPrompt: ShikiTransformerFactory<TransformOptions>;
|
|
78
39
|
|
|
79
|
-
export { transformAsciidocCallout,
|
|
40
|
+
export { transformAsciidocCallout, transformerPrompt };
|
|
@@ -3,47 +3,6 @@ import {
|
|
|
3
3
|
} from "../../../chunk-5P6LDJGO.js";
|
|
4
4
|
import "../../../chunk-2UGTFP4R.js";
|
|
5
5
|
|
|
6
|
-
// src/lib/shiki/transformers/transformConsolePrompt.ts
|
|
7
|
-
var transformConsolePrompt = (options) => {
|
|
8
|
-
return (node) => {
|
|
9
|
-
const language = node.getAttribute("language");
|
|
10
|
-
const cssClasses = options?.cssClasses;
|
|
11
|
-
const promptChar = options?.promptChar ?? "$";
|
|
12
|
-
const unselectablePrompt = `<span $1 class="${cssClasses}">${promptChar}</span>`;
|
|
13
|
-
const linePrefix = '<span class="line[^>]+?>';
|
|
14
|
-
const splitPrompt = new RegExp(
|
|
15
|
-
`(?<=${linePrefix})(?:<span (style="[^"]*?")>\\s*?\\${promptChar}\\s+?([^<]))`
|
|
16
|
-
);
|
|
17
|
-
const trimWhitespace = new RegExp(
|
|
18
|
-
`(?<=${linePrefix})(?:<span (style="[^"]*?")>\\s*?\\${promptChar}\\s*?<\\/span>(?:<span>\\s+<\\/span>)?)`
|
|
19
|
-
);
|
|
20
|
-
const trimWhitespaceAhead = new RegExp(
|
|
21
|
-
`(?<=${linePrefix}<span [^>]+?>\\${promptChar}<\\/span>)(<span style="[^"]+?">)\\s+?`
|
|
22
|
-
);
|
|
23
|
-
return {
|
|
24
|
-
line(hast) {
|
|
25
|
-
if (language !== "console") return;
|
|
26
|
-
const textNode = hast.children.at(0)?.children.at(0);
|
|
27
|
-
if (textNode && textNode.type === "text") {
|
|
28
|
-
const leadingChar = textNode.value;
|
|
29
|
-
if (!leadingChar.startsWith(promptChar)) {
|
|
30
|
-
textNode.value = promptChar + " " + textNode.value;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
postprocess: (html) => {
|
|
35
|
-
if (language !== "console") return;
|
|
36
|
-
return html.split("\n").map((line) => {
|
|
37
|
-
return line.replace(
|
|
38
|
-
splitPrompt,
|
|
39
|
-
unselectablePrompt + "<span $1>$2"
|
|
40
|
-
).replace(trimWhitespace, unselectablePrompt).replace(trimWhitespaceAhead, "$1");
|
|
41
|
-
}).join("\n");
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
|
|
47
6
|
// src/lib/shiki/transformers/transformerPrompt.ts
|
|
48
7
|
var transformerPrompt = (options) => {
|
|
49
8
|
return (node) => {
|
|
@@ -51,7 +10,7 @@ var transformerPrompt = (options) => {
|
|
|
51
10
|
const customPrompt = node.getAttribute(
|
|
52
11
|
options?.promptAttribute ?? "custom-prompt"
|
|
53
12
|
);
|
|
54
|
-
const promptToAdd = customPrompt ?? (options?.
|
|
13
|
+
const promptToAdd = customPrompt ?? (options?.langs && options.langs[language]);
|
|
55
14
|
const cssClasses = typeof promptToAdd === "object" ? promptToAdd.cssClasses : options?.cssClasses;
|
|
56
15
|
return {
|
|
57
16
|
line(hast) {
|
|
@@ -75,6 +34,5 @@ var transformerPrompt = (options) => {
|
|
|
75
34
|
};
|
|
76
35
|
export {
|
|
77
36
|
transformAsciidocCallout,
|
|
78
|
-
transformConsolePrompt,
|
|
79
37
|
transformerPrompt
|
|
80
38
|
};
|