@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.
@@ -90,43 +90,57 @@ var transformAsciidocCallout = (options) => {
90
90
  };
91
91
 
92
92
  // src/lib/shiki/transformers/transformerPrompt.ts
93
- var transformerPrompt = (options) => {
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 language = node.getAttribute("language");
96
- const customPrompt = node.getAttribute(
97
- options?.promptAttribute ?? "custom-prompt"
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
- const promptToAdd = customPrompt ?? (options?.langs && options.langs[language]);
100
- let cssClasses = typeof promptToAdd === "object" ? promptToAdd.cssClasses : options?.cssClasses;
101
- const breakOn = typeof promptToAdd === "object" ? promptToAdd.breakOn ?? "\\" : "\\";
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 (!promptToAdd) return;
114
- const skipCurrent = skipNext;
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.children[0];
118
- if (lastChild && lastToken) {
136
+ const lastToken = lastChild?.children[0];
137
+ if (lastToken) {
119
138
  skipNext = breakOnRe.test(lastToken.value);
120
- lastToken.value = lastToken.value.replace(breakOnRe, "");
121
- if (lastChild.children[0].value.match(breakOnRe)) {
122
- skipNext = true;
123
- if (hideBreak) {
124
- lastChild.children[0].value = // @ts-expect-error property "children" does exist
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: typeof promptToAdd === "object" ? promptToAdd.prompt : promptToAdd
156
+ value: config.prompt
143
157
  }
144
158
  ]
145
159
  });
@@ -1,57 +1,57 @@
1
- import { c as ShikiTransformerFactory } from '../../../index-C1F2jTPD.cjs';
2
- import { BundledLanguage } from 'shiki/types';
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
- * The character sequence used at the end of each line to indicate a
12
- * line break. This is used to break down long commands that won't fit
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
- breakOn?: string;
20
+ cssClasses: string;
20
21
  /**
21
- * This option is used to control whether the `breakOn` character
22
- * sequence should be removed from the output code block. This can be
23
- * useful to control multiline blocks that are intrinsically based on
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 false
26
+ * @default '\\'
29
27
  */
30
- hideBreak?: boolean;
31
- };
32
- type TransformOptions = {
28
+ breakOn: string;
33
29
  /**
34
- * String of CSS classes to apply to leading prompt character(s) on
35
- * source code blocks of type console.
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
- cssClasses?: string;
38
+ hideBreak: boolean;
39
+ }>;
40
+ type TransformerOptions$1 = PromptOptions & Partial<{
38
41
  /**
39
- * An object mapping each language block to a prompt string. An object
40
- * can also be provided specified with two keys, the prompt and the
41
- * CSS classes that modify this prompt in particular. Useful when you
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?: Partial<Record<BundledLanguage, PromptOptions | string>>;
46
+ langs: Partial<Record<BundledLanguage, PromptOptions | string>>;
46
47
  /**
47
- * The name of the block attribute on the original document to look
48
- * for and use as the prompt for this block.
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?: string;
53
- };
54
- declare const transformerPrompt: ShikiTransformerFactory<TransformOptions>;
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 { c as ShikiTransformerFactory } from '../../../index-C1F2jTPD.js';
2
- import { BundledLanguage } from 'shiki/types';
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
- * The character sequence used at the end of each line to indicate a
12
- * line break. This is used to break down long commands that won't fit
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
- breakOn?: string;
20
+ cssClasses: string;
20
21
  /**
21
- * This option is used to control whether the `breakOn` character
22
- * sequence should be removed from the output code block. This can be
23
- * useful to control multiline blocks that are intrinsically based on
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 false
26
+ * @default '\\'
29
27
  */
30
- hideBreak?: boolean;
31
- };
32
- type TransformOptions = {
28
+ breakOn: string;
33
29
  /**
34
- * String of CSS classes to apply to leading prompt character(s) on
35
- * source code blocks of type console.
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
- cssClasses?: string;
38
+ hideBreak: boolean;
39
+ }>;
40
+ type TransformerOptions$1 = PromptOptions & Partial<{
38
41
  /**
39
- * An object mapping each language block to a prompt string. An object
40
- * can also be provided specified with two keys, the prompt and the
41
- * CSS classes that modify this prompt in particular. Useful when you
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?: Partial<Record<BundledLanguage, PromptOptions | string>>;
46
+ langs: Partial<Record<BundledLanguage, PromptOptions | string>>;
46
47
  /**
47
- * The name of the block attribute on the original document to look
48
- * for and use as the prompt for this block.
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?: string;
53
- };
54
- declare const transformerPrompt: ShikiTransformerFactory<TransformOptions>;
52
+ promptAttribute: string;
53
+ }>;
54
+ declare const transformerPrompt: ShikiTransformerFactory<TransformerOptions$1>;
55
55
 
56
56
  type TransformerOptions = Partial<{
57
57
  cssClasses?: string;
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  transformAsciidocCallout,
3
3
  transformerPrompt
4
- } from "../../../chunk-4JCAN3ZN.js";
4
+ } from "../../../chunk-TCLZUBH3.js";
5
5
  import "../../../chunk-2UGTFP4R.js";
6
6
  export {
7
7
  transformAsciidocCallout,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@d10f/asciidoc-astro-loader",
3
- "version": "0.0.15",
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
- "astro": "^5.15.3",
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": "^5.0.0"
58
+ "astro": "^6.3.1"
58
59
  }
59
60
  }