@d10f/asciidoc-astro-loader 0.0.2 → 0.0.3
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 +132 -92
- package/dist/chunk-2UGTFP4R.js +22 -0
- package/dist/chunk-5P6LDJGO.js +65 -0
- package/dist/{chunk-BRMWIQA2.js → chunk-KZRXEKZK.js} +5 -9
- package/dist/{index-BNxO58s3.d.cts → index-sFlXF8Qm.d.cts} +142 -65
- package/dist/{index-BNxO58s3.d.ts → index-sFlXF8Qm.d.ts} +142 -65
- package/dist/index.cjs +225 -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 +3 -99
- package/dist/lib/asciidoc/converters/index.d.cts +2 -2
- package/dist/lib/asciidoc/converters/index.d.ts +2 -2
- 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 +88 -79
- package/dist/lib/shiki/transformers/index.d.cts +23 -32
- package/dist/lib/shiki/transformers/index.d.ts +23 -32
- package/dist/lib/shiki/transformers/index.js +45 -4
- package/package.json +1 -1
- package/dist/chunk-DDIUST2Z.js +0 -113
|
@@ -1,43 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { b as ShikiTransformerFactory } from '../../../index-sFlXF8Qm.js';
|
|
2
|
+
import 'shiki';
|
|
3
|
+
import 'asciidoctor';
|
|
4
|
+
import 'astro/zod';
|
|
4
5
|
|
|
5
|
-
type
|
|
6
|
-
/**
|
|
7
|
-
* Instance of Asciidoc's Block element to act upon.
|
|
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
|
|
16
|
-
*/
|
|
6
|
+
type TransformerOptions = Partial<{
|
|
17
7
|
cssClasses?: string;
|
|
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;
|
|
8
|
+
}>;
|
|
9
|
+
declare const transformAsciidocCallout: ShikiTransformerFactory<TransformerOptions>;
|
|
24
10
|
|
|
25
11
|
type TransformOptions = {
|
|
26
12
|
/**
|
|
27
|
-
* String of CSS classes to apply to leading
|
|
28
|
-
* code blocks
|
|
29
|
-
|
|
13
|
+
* String of CSS classes to apply to leading prompt character(s) on
|
|
14
|
+
* source code blocks of type console.
|
|
15
|
+
*/
|
|
16
|
+
cssClasses: string;
|
|
17
|
+
/**
|
|
18
|
+
* The prompt character representing the actual console prompt.
|
|
30
19
|
*
|
|
31
|
-
* @default
|
|
20
|
+
* @default $
|
|
32
21
|
*/
|
|
33
|
-
|
|
22
|
+
promptChar?: string;
|
|
34
23
|
};
|
|
35
24
|
/**
|
|
36
|
-
* For code blocks of language "console",
|
|
37
|
-
* character
|
|
38
|
-
*
|
|
25
|
+
* For code blocks of language "console", prepends each line with a
|
|
26
|
+
* prompt character(s), where applicable. By default, a "$" is used but
|
|
27
|
+
* this can be controlled via the *promptChar* option.
|
|
28
|
+
* Use the *cssClasses* option to style this prompt for things like
|
|
29
|
+
* making it unselectable, or dimmed..
|
|
39
30
|
*
|
|
40
|
-
*
|
|
31
|
+
* In addition, the leading spaces before the actual command are deleted
|
|
41
32
|
* from the span elements generated by Shiki to avoid accidentally
|
|
42
33
|
* running commands that would not appear in the shell history.
|
|
43
34
|
*
|
|
@@ -54,6 +45,6 @@ type TransformOptions = {
|
|
|
54
45
|
* before: <span>$</span><span> npm run dev</span>
|
|
55
46
|
* after: <span>$</span><span>npm run dev</span>
|
|
56
47
|
*/
|
|
57
|
-
declare
|
|
48
|
+
declare const transformConsolePrompt: ShikiTransformerFactory<TransformOptions>;
|
|
58
49
|
|
|
59
|
-
export { transformAsciidocCallout,
|
|
50
|
+
export { transformAsciidocCallout, transformConsolePrompt };
|
|
@@ -1,8 +1,49 @@
|
|
|
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
|
+
};
|
|
5
46
|
export {
|
|
6
47
|
transformAsciidocCallout,
|
|
7
|
-
|
|
48
|
+
transformConsolePrompt
|
|
8
49
|
};
|
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
|
-
};
|