@d10f/asciidoc-astro-loader 0.0.2 → 0.0.4
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 +153 -95
- package/dist/chunk-2UGTFP4R.js +22 -0
- package/dist/chunk-5P6LDJGO.js +65 -0
- package/dist/{chunk-BRMWIQA2.js → chunk-NC6IZHLR.js} +8 -10
- package/dist/{index-BNxO58s3.d.cts → index-CS3PBqxf.d.cts} +159 -66
- package/dist/{index-BNxO58s3.d.ts → index-CS3PBqxf.d.ts} +159 -66
- package/dist/index.cjs +227 -254
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +47 -37
- package/dist/lib/asciidoc/converters/index.cjs +6 -100
- package/dist/lib/asciidoc/converters/index.d.cts +5 -5
- package/dist/lib/asciidoc/converters/index.d.ts +5 -5
- package/dist/lib/asciidoc/converters/index.js +2 -2
- 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 +120 -79
- package/dist/lib/shiki/transformers/index.d.cts +52 -32
- package/dist/lib/shiki/transformers/index.d.ts +52 -32
- package/dist/lib/shiki/transformers/index.js +76 -4
- package/package.json +1 -1
- package/dist/chunk-DDIUST2Z.js +0 -113
|
@@ -1,43 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import { b as ShikiTransformerFactory } from '../../../index-CS3PBqxf.cjs';
|
|
2
|
+
import { BundledLanguage } from 'shiki/types';
|
|
3
|
+
import 'shiki';
|
|
4
|
+
import 'asciidoctor';
|
|
5
|
+
import 'astro/zod';
|
|
6
|
+
|
|
7
|
+
type TransformerOptions = Partial<{
|
|
8
|
+
cssClasses?: string;
|
|
9
|
+
}>;
|
|
10
|
+
declare const transformAsciidocCallout: ShikiTransformerFactory<TransformerOptions>;
|
|
4
11
|
|
|
5
12
|
type TransformOptions$1 = {
|
|
6
13
|
/**
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
node: Block;
|
|
10
|
-
/**
|
|
11
|
-
* String of CSS classes to apply to Asciidoc callout elements.
|
|
12
|
-
* Note: this does not override Asciidoctor's default class "conum"
|
|
13
|
-
* that applies to callout elements.
|
|
14
|
-
*
|
|
15
|
-
* @default pointer-events-none select-none ml-2
|
|
14
|
+
* String of CSS classes to apply to leading prompt character(s) on
|
|
15
|
+
* source code blocks of type console.
|
|
16
16
|
*/
|
|
17
|
-
cssClasses
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Transforms source code blocks by converting Asciidoc's callout annotations
|
|
21
|
-
* into unselectable tokens.
|
|
22
|
-
*/
|
|
23
|
-
declare function transformAsciidocCallout({ node, cssClasses, }: TransformOptions$1): ShikiTransformer;
|
|
24
|
-
|
|
25
|
-
type TransformOptions = {
|
|
17
|
+
cssClasses: string;
|
|
26
18
|
/**
|
|
27
|
-
*
|
|
28
|
-
* code blocks. By default, this transformer makes it unselectable and
|
|
29
|
-
* applies 50% opacity.
|
|
19
|
+
* The prompt character representing the actual console prompt.
|
|
30
20
|
*
|
|
31
|
-
* @default
|
|
21
|
+
* @default $
|
|
32
22
|
*/
|
|
33
|
-
|
|
23
|
+
promptChar?: string;
|
|
34
24
|
};
|
|
35
25
|
/**
|
|
36
|
-
* For code blocks of language "console",
|
|
37
|
-
* character
|
|
38
|
-
*
|
|
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..
|
|
39
31
|
*
|
|
40
|
-
*
|
|
32
|
+
* In addition, the leading spaces before the actual command are deleted
|
|
41
33
|
* from the span elements generated by Shiki to avoid accidentally
|
|
42
34
|
* running commands that would not appear in the shell history.
|
|
43
35
|
*
|
|
@@ -54,6 +46,34 @@ type TransformOptions = {
|
|
|
54
46
|
* before: <span>$</span><span> npm run dev</span>
|
|
55
47
|
* after: <span>$</span><span>npm run dev</span>
|
|
56
48
|
*/
|
|
57
|
-
declare
|
|
49
|
+
declare const transformConsolePrompt: ShikiTransformerFactory<TransformOptions$1>;
|
|
50
|
+
|
|
51
|
+
type PromptOptions = {
|
|
52
|
+
prompt: string;
|
|
53
|
+
cssClasses: string;
|
|
54
|
+
};
|
|
55
|
+
type TransformOptions = {
|
|
56
|
+
/**
|
|
57
|
+
* String of CSS classes to apply to leading prompt character(s) on
|
|
58
|
+
* source code blocks of type console.
|
|
59
|
+
*/
|
|
60
|
+
cssClasses?: string;
|
|
61
|
+
/**
|
|
62
|
+
* An object mapping each language block to a prompt string. An object
|
|
63
|
+
* can also be provided specified with two keys, the prompt and the
|
|
64
|
+
* css classes that modify this prompt in particular. Useful when you
|
|
65
|
+
* want to style them differently from the
|
|
66
|
+
* If not provided, it will default to look at the block attribute.
|
|
67
|
+
*/
|
|
68
|
+
prompts?: Partial<Record<BundledLanguage, PromptOptions | string>>;
|
|
69
|
+
/**
|
|
70
|
+
* The name of the block attribute on the original document to look
|
|
71
|
+
* for and use as the prompt for this block.
|
|
72
|
+
*
|
|
73
|
+
* @default custom-prompt
|
|
74
|
+
*/
|
|
75
|
+
promptAttribute?: string;
|
|
76
|
+
};
|
|
77
|
+
declare const transformerPrompt: ShikiTransformerFactory<TransformOptions>;
|
|
58
78
|
|
|
59
|
-
export { transformAsciidocCallout,
|
|
79
|
+
export { transformAsciidocCallout, transformConsolePrompt, transformerPrompt };
|
|
@@ -1,43 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import { b as ShikiTransformerFactory } from '../../../index-CS3PBqxf.js';
|
|
2
|
+
import { BundledLanguage } from 'shiki/types';
|
|
3
|
+
import 'shiki';
|
|
4
|
+
import 'asciidoctor';
|
|
5
|
+
import 'astro/zod';
|
|
6
|
+
|
|
7
|
+
type TransformerOptions = Partial<{
|
|
8
|
+
cssClasses?: string;
|
|
9
|
+
}>;
|
|
10
|
+
declare const transformAsciidocCallout: ShikiTransformerFactory<TransformerOptions>;
|
|
4
11
|
|
|
5
12
|
type TransformOptions$1 = {
|
|
6
13
|
/**
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
node: Block;
|
|
10
|
-
/**
|
|
11
|
-
* String of CSS classes to apply to Asciidoc callout elements.
|
|
12
|
-
* Note: this does not override Asciidoctor's default class "conum"
|
|
13
|
-
* that applies to callout elements.
|
|
14
|
-
*
|
|
15
|
-
* @default pointer-events-none select-none ml-2
|
|
14
|
+
* String of CSS classes to apply to leading prompt character(s) on
|
|
15
|
+
* source code blocks of type console.
|
|
16
16
|
*/
|
|
17
|
-
cssClasses
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Transforms source code blocks by converting Asciidoc's callout annotations
|
|
21
|
-
* into unselectable tokens.
|
|
22
|
-
*/
|
|
23
|
-
declare function transformAsciidocCallout({ node, cssClasses, }: TransformOptions$1): ShikiTransformer;
|
|
24
|
-
|
|
25
|
-
type TransformOptions = {
|
|
17
|
+
cssClasses: string;
|
|
26
18
|
/**
|
|
27
|
-
*
|
|
28
|
-
* code blocks. By default, this transformer makes it unselectable and
|
|
29
|
-
* applies 50% opacity.
|
|
19
|
+
* The prompt character representing the actual console prompt.
|
|
30
20
|
*
|
|
31
|
-
* @default
|
|
21
|
+
* @default $
|
|
32
22
|
*/
|
|
33
|
-
|
|
23
|
+
promptChar?: string;
|
|
34
24
|
};
|
|
35
25
|
/**
|
|
36
|
-
* For code blocks of language "console",
|
|
37
|
-
* character
|
|
38
|
-
*
|
|
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..
|
|
39
31
|
*
|
|
40
|
-
*
|
|
32
|
+
* In addition, the leading spaces before the actual command are deleted
|
|
41
33
|
* from the span elements generated by Shiki to avoid accidentally
|
|
42
34
|
* running commands that would not appear in the shell history.
|
|
43
35
|
*
|
|
@@ -54,6 +46,34 @@ type TransformOptions = {
|
|
|
54
46
|
* before: <span>$</span><span> npm run dev</span>
|
|
55
47
|
* after: <span>$</span><span>npm run dev</span>
|
|
56
48
|
*/
|
|
57
|
-
declare
|
|
49
|
+
declare const transformConsolePrompt: ShikiTransformerFactory<TransformOptions$1>;
|
|
50
|
+
|
|
51
|
+
type PromptOptions = {
|
|
52
|
+
prompt: string;
|
|
53
|
+
cssClasses: string;
|
|
54
|
+
};
|
|
55
|
+
type TransformOptions = {
|
|
56
|
+
/**
|
|
57
|
+
* String of CSS classes to apply to leading prompt character(s) on
|
|
58
|
+
* source code blocks of type console.
|
|
59
|
+
*/
|
|
60
|
+
cssClasses?: string;
|
|
61
|
+
/**
|
|
62
|
+
* An object mapping each language block to a prompt string. An object
|
|
63
|
+
* can also be provided specified with two keys, the prompt and the
|
|
64
|
+
* css classes that modify this prompt in particular. Useful when you
|
|
65
|
+
* want to style them differently from the
|
|
66
|
+
* If not provided, it will default to look at the block attribute.
|
|
67
|
+
*/
|
|
68
|
+
prompts?: Partial<Record<BundledLanguage, PromptOptions | string>>;
|
|
69
|
+
/**
|
|
70
|
+
* The name of the block attribute on the original document to look
|
|
71
|
+
* for and use as the prompt for this block.
|
|
72
|
+
*
|
|
73
|
+
* @default custom-prompt
|
|
74
|
+
*/
|
|
75
|
+
promptAttribute?: string;
|
|
76
|
+
};
|
|
77
|
+
declare const transformerPrompt: ShikiTransformerFactory<TransformOptions>;
|
|
58
78
|
|
|
59
|
-
export { transformAsciidocCallout,
|
|
79
|
+
export { transformAsciidocCallout, transformConsolePrompt, transformerPrompt };
|
|
@@ -1,8 +1,80 @@
|
|
|
1
1
|
import {
|
|
2
|
-
transformAsciidocCallout
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
transformAsciidocCallout
|
|
3
|
+
} from "../../../chunk-5P6LDJGO.js";
|
|
4
|
+
import "../../../chunk-2UGTFP4R.js";
|
|
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
|
+
// src/lib/shiki/transformers/transformerPrompt.ts
|
|
48
|
+
var transformerPrompt = (options) => {
|
|
49
|
+
return (node) => {
|
|
50
|
+
const language = node.getAttribute("language");
|
|
51
|
+
const customPrompt = node.getAttribute(
|
|
52
|
+
options?.promptAttribute ?? "custom-prompt"
|
|
53
|
+
);
|
|
54
|
+
const promptToAdd = customPrompt ?? (options?.prompts && options.prompts[language]);
|
|
55
|
+
const cssClasses = typeof promptToAdd === "object" ? promptToAdd.cssClasses : options?.cssClasses;
|
|
56
|
+
return {
|
|
57
|
+
line(hast) {
|
|
58
|
+
if (!promptToAdd) return;
|
|
59
|
+
hast.children.unshift({
|
|
60
|
+
type: "element",
|
|
61
|
+
tagName: "span",
|
|
62
|
+
properties: {
|
|
63
|
+
class: cssClasses
|
|
64
|
+
},
|
|
65
|
+
children: [
|
|
66
|
+
{
|
|
67
|
+
type: "text",
|
|
68
|
+
value: typeof promptToAdd === "object" ? promptToAdd.prompt : promptToAdd
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
};
|
|
5
76
|
export {
|
|
6
77
|
transformAsciidocCallout,
|
|
7
|
-
|
|
78
|
+
transformConsolePrompt,
|
|
79
|
+
transformerPrompt
|
|
8
80
|
};
|
package/package.json
CHANGED
package/dist/chunk-DDIUST2Z.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
// src/lib/utils.ts
|
|
2
|
-
function slugify(text) {
|
|
3
|
-
return text.trim().normalize().toLowerCase().replace(/\s+/g, "-").replace(/[^\w-]+/g, "").replace(/--+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
|
|
4
|
-
}
|
|
5
|
-
function escapeRegexCharacters(str) {
|
|
6
|
-
const re = /[-\\^$*+?.()|\[\]{}]/g;
|
|
7
|
-
return str.replace(re, "\\$&");
|
|
8
|
-
}
|
|
9
|
-
function splitFilenameComponents(filename) {
|
|
10
|
-
const match = filename.match(/^(?<path>.*\/)*(?<name>[^\.]+)\.(?<ext>.*)$/);
|
|
11
|
-
return {
|
|
12
|
-
filepath: match?.groups?.path ?? null,
|
|
13
|
-
filename: match?.groups?.name ?? null,
|
|
14
|
-
extension: match?.groups?.ext ?? null
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// src/lib/shiki/transformers/transformAsciidocCallout.ts
|
|
19
|
-
function transformAsciidocCallout({
|
|
20
|
-
node,
|
|
21
|
-
cssClasses = "pointer-events-none select-none ml-2"
|
|
22
|
-
}) {
|
|
23
|
-
const lineComments = ["//", "#", ";;"];
|
|
24
|
-
const customLineComment = node.getAttribute("line-comment");
|
|
25
|
-
if (customLineComment) {
|
|
26
|
-
lineComments.push(escapeRegexCharacters(customLineComment));
|
|
27
|
-
}
|
|
28
|
-
const calloutReList = [
|
|
29
|
-
// Handles C-style and similar comments like Perl, Python...
|
|
30
|
-
new RegExp(`(?:${lineComments.join("|")})((?:\\s+<(\\d+)>)+)`),
|
|
31
|
-
// Handles XML comments
|
|
32
|
-
new RegExp(/((?:\s*<!--(\d+)-->)+)/)
|
|
33
|
-
];
|
|
34
|
-
const linesWithCallout = {};
|
|
35
|
-
return {
|
|
36
|
-
preprocess(code) {
|
|
37
|
-
return code.split("\n").map((line, idx) => {
|
|
38
|
-
for (const re of calloutReList) {
|
|
39
|
-
const match = line.match(re);
|
|
40
|
-
if (!match) continue;
|
|
41
|
-
const callouts = match[0].trim().replaceAll(/(?:<!--|-->|[<>])/g, "").split(" ");
|
|
42
|
-
linesWithCallout[idx + 1] = callouts;
|
|
43
|
-
return line.replace(re, "");
|
|
44
|
-
}
|
|
45
|
-
return line;
|
|
46
|
-
}).join("\n");
|
|
47
|
-
},
|
|
48
|
-
line(hast, line) {
|
|
49
|
-
const callouts = linesWithCallout[line];
|
|
50
|
-
if (!callouts) return;
|
|
51
|
-
callouts.forEach((calloutId) => {
|
|
52
|
-
hast.properties[`data-callout-${calloutId}`] = "";
|
|
53
|
-
hast.children.push({
|
|
54
|
-
type: "element",
|
|
55
|
-
tagName: "i",
|
|
56
|
-
properties: {
|
|
57
|
-
class: `conum ${cssClasses}`,
|
|
58
|
-
"data-value": calloutId
|
|
59
|
-
},
|
|
60
|
-
children: [
|
|
61
|
-
{
|
|
62
|
-
type: "element",
|
|
63
|
-
tagName: "b",
|
|
64
|
-
properties: {},
|
|
65
|
-
children: [
|
|
66
|
-
{
|
|
67
|
-
type: "text",
|
|
68
|
-
value: calloutId
|
|
69
|
-
}
|
|
70
|
-
]
|
|
71
|
-
}
|
|
72
|
-
]
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// src/lib/shiki/transformers/transformConsoleCodeBlock.ts
|
|
80
|
-
function transformConsoleCodeBlock(options = {
|
|
81
|
-
cssClasses: "pointer-events-none select-none mr-2 opacity-50"
|
|
82
|
-
}) {
|
|
83
|
-
const unselectablePrompt = `<span $1 class="${options.cssClasses}">$</span>`;
|
|
84
|
-
const linePrefix = '<span class="line[^>]+?>';
|
|
85
|
-
const splitPrompt = new RegExp(
|
|
86
|
-
`(?<=${linePrefix})(?:<span (style="[^"]*?")>\\s*?\\$\\s+?([^<]))`
|
|
87
|
-
);
|
|
88
|
-
const trimWhitespace = new RegExp(
|
|
89
|
-
`(?<=${linePrefix})(?:<span (style="[^"]*?")>\\s*?\\$\\s*?<\\/span>(?:<span>\\s+<\\/span>)?)`
|
|
90
|
-
);
|
|
91
|
-
const trimWhitespaceAhead = new RegExp(
|
|
92
|
-
`(?<=${linePrefix}<span [^>]+?>\\$<\\/span>)(<span style="[^"]+?">)\\s+?`
|
|
93
|
-
);
|
|
94
|
-
return {
|
|
95
|
-
postprocess: (html, { lang }) => {
|
|
96
|
-
if (lang === "console") {
|
|
97
|
-
return html.split("\n").map((line) => {
|
|
98
|
-
return line.replace(
|
|
99
|
-
splitPrompt,
|
|
100
|
-
unselectablePrompt + "<span $1>$2"
|
|
101
|
-
).replace(trimWhitespace, unselectablePrompt).replace(trimWhitespaceAhead, "$1");
|
|
102
|
-
}).join("\n");
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export {
|
|
109
|
-
slugify,
|
|
110
|
-
splitFilenameComponents,
|
|
111
|
-
transformAsciidocCallout,
|
|
112
|
-
transformConsoleCodeBlock
|
|
113
|
-
};
|