@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 +3 -2
- package/dist/{chunk-5LUVP7HW.js → chunk-S7W7VGV4.js} +2 -0
- package/dist/{chunk-4JCAN3ZN.js → chunk-TCLZUBH3.js} +42 -28
- package/dist/{index-C1F2jTPD.d.cts → index-B1d5alka.d.cts} +53 -197
- package/dist/{index-C1F2jTPD.d.ts → index-B1d5alka.d.ts} +53 -197
- package/dist/index.cjs +66 -29
- package/dist/index.d.cts +2 -3
- package/dist/index.d.ts +2 -3
- package/dist/index.js +24 -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/templates/engines/index.cjs +2 -0
- 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/asciidoc/templates/engines/index.js +1 -1
- package/dist/lib/shiki/transformers/index.cjs +42 -28
- package/dist/lib/shiki/transformers/index.d.cts +38 -38
- package/dist/lib/shiki/transformers/index.d.ts +38 -38
- package/dist/lib/shiki/transformers/index.js +1 -1
- package/package.json +4 -3
|
@@ -90,43 +90,57 @@ var transformAsciidocCallout = (options) => {
|
|
|
90
90
|
};
|
|
91
91
|
|
|
92
92
|
// src/lib/shiki/transformers/transformerPrompt.ts
|
|
93
|
-
var
|
|
93
|
+
var DEFAULT_OPTS = {
|
|
94
|
+
breakOn: "\\",
|
|
95
|
+
cssClasses: "",
|
|
96
|
+
hideBreak: false,
|
|
97
|
+
prompt: "",
|
|
98
|
+
promptAttribute: "custom-prompt"
|
|
99
|
+
};
|
|
100
|
+
var transformerPrompt = (opts) => {
|
|
94
101
|
return (node) => {
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
102
|
+
const config = {
|
|
103
|
+
breakOn: opts?.breakOn ?? DEFAULT_OPTS.breakOn,
|
|
104
|
+
cssClasses: opts?.cssClasses ?? DEFAULT_OPTS.cssClasses,
|
|
105
|
+
hideBreak: opts?.hideBreak ?? DEFAULT_OPTS.hideBreak,
|
|
106
|
+
prompt: opts?.prompt ?? DEFAULT_OPTS.prompt
|
|
107
|
+
};
|
|
108
|
+
if (opts && opts.langs) {
|
|
109
|
+
const lang = node.getAttribute("language");
|
|
110
|
+
const langOpts = opts.langs[lang];
|
|
111
|
+
Object.assign(
|
|
112
|
+
config,
|
|
113
|
+
typeof langOpts === "object" ? langOpts : { prompt: langOpts }
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
const promptAttr = node.getAttribute(
|
|
117
|
+
opts?.promptAttribute ?? DEFAULT_OPTS.promptAttribute
|
|
98
118
|
);
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
119
|
+
if (promptAttr) {
|
|
120
|
+
Object.assign(config, {
|
|
121
|
+
prompt: promptAttr
|
|
122
|
+
});
|
|
123
|
+
}
|
|
102
124
|
const breakOnRe = new RegExp(
|
|
103
|
-
`\\s+${escapeRegexCharacters(breakOn)}\\s*$`
|
|
125
|
+
`\\s+${escapeRegexCharacters(config.breakOn)}\\s*$`
|
|
104
126
|
);
|
|
105
|
-
const hideBreak = options?.langs && options.langs[language] && typeof options.langs[language] === "object" && options.langs[language].hideBreak;
|
|
106
|
-
if (customPrompt && options?.langs && typeof options.langs[language] === "object") {
|
|
107
|
-
cssClasses = options.langs[language].cssClasses;
|
|
108
|
-
}
|
|
109
127
|
let skipNext = false;
|
|
128
|
+
let skipCurrent = false;
|
|
110
129
|
return {
|
|
111
130
|
enforce: "pre",
|
|
112
131
|
line(hast) {
|
|
113
|
-
if (!
|
|
114
|
-
|
|
132
|
+
if (!config.prompt || !config.prompt.trim()) return;
|
|
133
|
+
skipCurrent = skipNext;
|
|
115
134
|
skipNext = false;
|
|
116
135
|
const lastChild = hast.children.at(-1);
|
|
117
|
-
const lastToken = lastChild
|
|
118
|
-
if (
|
|
136
|
+
const lastToken = lastChild?.children[0];
|
|
137
|
+
if (lastToken) {
|
|
119
138
|
skipNext = breakOnRe.test(lastToken.value);
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
lastChild.children[0].value.replace(
|
|
126
|
-
breakOnRe,
|
|
127
|
-
""
|
|
128
|
-
);
|
|
129
|
-
}
|
|
139
|
+
if (skipNext && config.hideBreak) {
|
|
140
|
+
lastToken.value = lastToken.value.replace(
|
|
141
|
+
breakOnRe,
|
|
142
|
+
""
|
|
143
|
+
);
|
|
130
144
|
}
|
|
131
145
|
}
|
|
132
146
|
if (skipCurrent) return;
|
|
@@ -134,12 +148,12 @@ var transformerPrompt = (options) => {
|
|
|
134
148
|
type: "element",
|
|
135
149
|
tagName: "span",
|
|
136
150
|
properties: {
|
|
137
|
-
class: cssClasses
|
|
151
|
+
class: config.cssClasses
|
|
138
152
|
},
|
|
139
153
|
children: [
|
|
140
154
|
{
|
|
141
155
|
type: "text",
|
|
142
|
-
value:
|
|
156
|
+
value: config.prompt
|
|
143
157
|
}
|
|
144
158
|
]
|
|
145
159
|
});
|
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BundledLanguage } from 'shiki
|
|
3
|
-
import 'shiki';
|
|
1
|
+
import { S as ShikiTransformerFactory } from '../../../index-B1d5alka.cjs';
|
|
2
|
+
import { BundledLanguage } from 'shiki';
|
|
4
3
|
import 'asciidoctor';
|
|
5
4
|
import 'astro/zod';
|
|
6
5
|
|
|
7
|
-
type PromptOptions = {
|
|
6
|
+
type PromptOptions = Partial<{
|
|
7
|
+
/**
|
|
8
|
+
* The string prefixed on every line of the code block. It's an empty
|
|
9
|
+
* string by default.
|
|
10
|
+
*
|
|
11
|
+
* @default ''
|
|
12
|
+
*/
|
|
8
13
|
prompt: string;
|
|
9
|
-
cssClasses: string;
|
|
10
14
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* in a single line, like shell commands. Without a line break, every
|
|
14
|
-
* newline will be prefixed with the prompt, which might not always be
|
|
15
|
-
* desirable. Defaults to a backslash.
|
|
15
|
+
* CSS classes to apply to the newly-inserted node containing the
|
|
16
|
+
* prompt. It's an empty string by default.
|
|
16
17
|
*
|
|
17
|
-
* @default
|
|
18
|
+
* @default ''
|
|
18
19
|
*/
|
|
19
|
-
|
|
20
|
+
cssClasses: string;
|
|
20
21
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* newline characters which aren't visible, as opposed to other type
|
|
25
|
-
* of breaks like shell console that rely on visible characters like
|
|
26
|
-
* the backslash.
|
|
22
|
+
* Allows to hide the prompt for the next line, if the current line
|
|
23
|
+
* ends with the given string. Use this to output, for example, multi
|
|
24
|
+
* line console commands.
|
|
27
25
|
*
|
|
28
|
-
* @default
|
|
26
|
+
* @default '\\'
|
|
29
27
|
*/
|
|
30
|
-
|
|
31
|
-
};
|
|
32
|
-
type TransformOptions = {
|
|
28
|
+
breakOn: string;
|
|
33
29
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
30
|
+
* If the current line ends with a `breakOn` string sequence, this
|
|
31
|
+
* option determines whether the newline break should be hidden from
|
|
32
|
+
* the output or not. For multi-line console commands you may want to
|
|
33
|
+
* display the "\" delimiter for clarity, but other consoles,
|
|
34
|
+
* interpreters, or REPLs might look better with this out of the way.
|
|
35
|
+
*
|
|
36
|
+
* @default false
|
|
36
37
|
*/
|
|
37
|
-
|
|
38
|
+
hideBreak: boolean;
|
|
39
|
+
}>;
|
|
40
|
+
type TransformerOptions$1 = PromptOptions & Partial<{
|
|
38
41
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* want to style them differently from the
|
|
43
|
-
* If not provided, it will default to look at the block attribute.
|
|
42
|
+
* Specify options on a per language basis. These take precedence
|
|
43
|
+
* over the options applied to all languages. Or, instead of a whole
|
|
44
|
+
* object, provide a string as a shortcut for the `prompt` option.
|
|
44
45
|
*/
|
|
45
|
-
langs
|
|
46
|
+
langs: Partial<Record<BundledLanguage, PromptOptions | string>>;
|
|
46
47
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* @default custom-prompt
|
|
48
|
+
* If the source AsciiDoc node being processed includes this custom
|
|
49
|
+
* attribue, it will be read and used as the `prompt` for this code
|
|
50
|
+
* block. This takes the most precedence over other prompt options.
|
|
51
51
|
*/
|
|
52
|
-
promptAttribute
|
|
53
|
-
}
|
|
54
|
-
declare const transformerPrompt: ShikiTransformerFactory<
|
|
52
|
+
promptAttribute: string;
|
|
53
|
+
}>;
|
|
54
|
+
declare const transformerPrompt: ShikiTransformerFactory<TransformerOptions$1>;
|
|
55
55
|
|
|
56
56
|
type TransformerOptions = Partial<{
|
|
57
57
|
cssClasses?: string;
|
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BundledLanguage } from 'shiki
|
|
3
|
-
import 'shiki';
|
|
1
|
+
import { S as ShikiTransformerFactory } from '../../../index-B1d5alka.js';
|
|
2
|
+
import { BundledLanguage } from 'shiki';
|
|
4
3
|
import 'asciidoctor';
|
|
5
4
|
import 'astro/zod';
|
|
6
5
|
|
|
7
|
-
type PromptOptions = {
|
|
6
|
+
type PromptOptions = Partial<{
|
|
7
|
+
/**
|
|
8
|
+
* The string prefixed on every line of the code block. It's an empty
|
|
9
|
+
* string by default.
|
|
10
|
+
*
|
|
11
|
+
* @default ''
|
|
12
|
+
*/
|
|
8
13
|
prompt: string;
|
|
9
|
-
cssClasses: string;
|
|
10
14
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* in a single line, like shell commands. Without a line break, every
|
|
14
|
-
* newline will be prefixed with the prompt, which might not always be
|
|
15
|
-
* desirable. Defaults to a backslash.
|
|
15
|
+
* CSS classes to apply to the newly-inserted node containing the
|
|
16
|
+
* prompt. It's an empty string by default.
|
|
16
17
|
*
|
|
17
|
-
* @default
|
|
18
|
+
* @default ''
|
|
18
19
|
*/
|
|
19
|
-
|
|
20
|
+
cssClasses: string;
|
|
20
21
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* newline characters which aren't visible, as opposed to other type
|
|
25
|
-
* of breaks like shell console that rely on visible characters like
|
|
26
|
-
* the backslash.
|
|
22
|
+
* Allows to hide the prompt for the next line, if the current line
|
|
23
|
+
* ends with the given string. Use this to output, for example, multi
|
|
24
|
+
* line console commands.
|
|
27
25
|
*
|
|
28
|
-
* @default
|
|
26
|
+
* @default '\\'
|
|
29
27
|
*/
|
|
30
|
-
|
|
31
|
-
};
|
|
32
|
-
type TransformOptions = {
|
|
28
|
+
breakOn: string;
|
|
33
29
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
30
|
+
* If the current line ends with a `breakOn` string sequence, this
|
|
31
|
+
* option determines whether the newline break should be hidden from
|
|
32
|
+
* the output or not. For multi-line console commands you may want to
|
|
33
|
+
* display the "\" delimiter for clarity, but other consoles,
|
|
34
|
+
* interpreters, or REPLs might look better with this out of the way.
|
|
35
|
+
*
|
|
36
|
+
* @default false
|
|
36
37
|
*/
|
|
37
|
-
|
|
38
|
+
hideBreak: boolean;
|
|
39
|
+
}>;
|
|
40
|
+
type TransformerOptions$1 = PromptOptions & Partial<{
|
|
38
41
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* want to style them differently from the
|
|
43
|
-
* If not provided, it will default to look at the block attribute.
|
|
42
|
+
* Specify options on a per language basis. These take precedence
|
|
43
|
+
* over the options applied to all languages. Or, instead of a whole
|
|
44
|
+
* object, provide a string as a shortcut for the `prompt` option.
|
|
44
45
|
*/
|
|
45
|
-
langs
|
|
46
|
+
langs: Partial<Record<BundledLanguage, PromptOptions | string>>;
|
|
46
47
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* @default custom-prompt
|
|
48
|
+
* If the source AsciiDoc node being processed includes this custom
|
|
49
|
+
* attribue, it will be read and used as the `prompt` for this code
|
|
50
|
+
* block. This takes the most precedence over other prompt options.
|
|
51
51
|
*/
|
|
52
|
-
promptAttribute
|
|
53
|
-
}
|
|
54
|
-
declare const transformerPrompt: ShikiTransformerFactory<
|
|
52
|
+
promptAttribute: string;
|
|
53
|
+
}>;
|
|
54
|
+
declare const transformerPrompt: ShikiTransformerFactory<TransformerOptions$1>;
|
|
55
55
|
|
|
56
56
|
type TransformerOptions = Partial<{
|
|
57
57
|
cssClasses?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d10f/asciidoc-astro-loader",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "An Astro collections loader for Asciidoc files",
|
|
5
5
|
"author": "D10f",
|
|
6
6
|
"license": "MIT",
|
|
@@ -36,7 +36,8 @@
|
|
|
36
36
|
"./transformers": "./dist/lib/shiki/transformers/index.js"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"
|
|
39
|
+
"@types/node": "^25.9.1",
|
|
40
|
+
"astro": "^6.3.1",
|
|
40
41
|
"eslint": "^9.36.0",
|
|
41
42
|
"eslint-plugin-prettier": "^5.5.4",
|
|
42
43
|
"globals": "^16.4.0",
|
|
@@ -54,6 +55,6 @@
|
|
|
54
55
|
"shiki": "^3.20.0"
|
|
55
56
|
},
|
|
56
57
|
"peerDependencies": {
|
|
57
|
-
"astro": "^
|
|
58
|
+
"astro": "^6.3.1"
|
|
58
59
|
}
|
|
59
60
|
}
|