@d10f/asciidoc-astro-loader 0.0.14 → 0.0.15

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.
@@ -69,6 +69,11 @@ var transformerPrompt = (options) => {
69
69
  );
70
70
  const promptToAdd = customPrompt ?? (options?.langs && options.langs[language]);
71
71
  let cssClasses = typeof promptToAdd === "object" ? promptToAdd.cssClasses : options?.cssClasses;
72
+ const breakOn = typeof promptToAdd === "object" ? promptToAdd.breakOn ?? "\\" : "\\";
73
+ const breakOnRe = new RegExp(
74
+ `\\s+${escapeRegexCharacters(breakOn)}\\s*$`
75
+ );
76
+ const hideBreak = options?.langs && options.langs[language] && typeof options.langs[language] === "object" && options.langs[language].hideBreak;
72
77
  if (customPrompt && options?.langs && typeof options.langs[language] === "object") {
73
78
  cssClasses = options.langs[language].cssClasses;
74
79
  }
@@ -80,19 +85,19 @@ var transformerPrompt = (options) => {
80
85
  const skipCurrent = skipNext;
81
86
  skipNext = false;
82
87
  const lastChild = hast.children.at(-1);
83
- if (lastChild) {
84
- if (lastChild.children[0].value.match(/\s+\\(?:\\)?\s*$/)) {
85
- skipNext = true;
86
- } else if (
87
- // @ts-expect-error property "children" does exist
88
- lastChild.children[0].value.match(/\s+\\n\s*$/)
89
- ) {
88
+ const lastToken = lastChild.children[0];
89
+ if (lastChild && lastToken) {
90
+ skipNext = breakOnRe.test(lastToken.value);
91
+ lastToken.value = lastToken.value.replace(breakOnRe, "");
92
+ if (lastChild.children[0].value.match(breakOnRe)) {
90
93
  skipNext = true;
91
- lastChild.children[0].value = // @ts-expect-error property "children" does exist
92
- lastChild.children[0].value.replace(
93
- /\s+\\n\s*$/,
94
- ""
95
- );
94
+ if (hideBreak) {
95
+ lastChild.children[0].value = // @ts-expect-error property "children" does exist
96
+ lastChild.children[0].value.replace(
97
+ breakOnRe,
98
+ ""
99
+ );
100
+ }
96
101
  }
97
102
  }
98
103
  if (skipCurrent) return;
package/dist/index.cjs CHANGED
@@ -793,6 +793,11 @@ var transformerPrompt = (options) => {
793
793
  );
794
794
  const promptToAdd = customPrompt ?? (options?.langs && options.langs[language]);
795
795
  let cssClasses = typeof promptToAdd === "object" ? promptToAdd.cssClasses : options?.cssClasses;
796
+ const breakOn = typeof promptToAdd === "object" ? promptToAdd.breakOn ?? "\\" : "\\";
797
+ const breakOnRe = new RegExp(
798
+ `\\s+${escapeRegexCharacters(breakOn)}\\s*$`
799
+ );
800
+ const hideBreak = options?.langs && options.langs[language] && typeof options.langs[language] === "object" && options.langs[language].hideBreak;
796
801
  if (customPrompt && options?.langs && typeof options.langs[language] === "object") {
797
802
  cssClasses = options.langs[language].cssClasses;
798
803
  }
@@ -804,19 +809,19 @@ var transformerPrompt = (options) => {
804
809
  const skipCurrent = skipNext;
805
810
  skipNext = false;
806
811
  const lastChild = hast.children.at(-1);
807
- if (lastChild) {
808
- if (lastChild.children[0].value.match(/\s+\\(?:\\)?\s*$/)) {
809
- skipNext = true;
810
- } else if (
811
- // @ts-expect-error property "children" does exist
812
- lastChild.children[0].value.match(/\s+\\n\s*$/)
813
- ) {
812
+ const lastToken = lastChild.children[0];
813
+ if (lastChild && lastToken) {
814
+ skipNext = breakOnRe.test(lastToken.value);
815
+ lastToken.value = lastToken.value.replace(breakOnRe, "");
816
+ if (lastChild.children[0].value.match(breakOnRe)) {
814
817
  skipNext = true;
815
- lastChild.children[0].value = // @ts-expect-error property "children" does exist
816
- lastChild.children[0].value.replace(
817
- /\s+\\n\s*$/,
818
- ""
819
- );
818
+ if (hideBreak) {
819
+ lastChild.children[0].value = // @ts-expect-error property "children" does exist
820
+ lastChild.children[0].value.replace(
821
+ breakOnRe,
822
+ ""
823
+ );
824
+ }
820
825
  }
821
826
  }
822
827
  if (skipCurrent) return;
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  transformAsciidocCallout,
6
6
  transformerPrompt
7
- } from "./chunk-NYOV2AHU.js";
7
+ } from "./chunk-4JCAN3ZN.js";
8
8
  import {
9
9
  slugify,
10
10
  splitFilenameComponents
@@ -98,6 +98,11 @@ var transformerPrompt = (options) => {
98
98
  );
99
99
  const promptToAdd = customPrompt ?? (options?.langs && options.langs[language]);
100
100
  let cssClasses = typeof promptToAdd === "object" ? promptToAdd.cssClasses : options?.cssClasses;
101
+ const breakOn = typeof promptToAdd === "object" ? promptToAdd.breakOn ?? "\\" : "\\";
102
+ const breakOnRe = new RegExp(
103
+ `\\s+${escapeRegexCharacters(breakOn)}\\s*$`
104
+ );
105
+ const hideBreak = options?.langs && options.langs[language] && typeof options.langs[language] === "object" && options.langs[language].hideBreak;
101
106
  if (customPrompt && options?.langs && typeof options.langs[language] === "object") {
102
107
  cssClasses = options.langs[language].cssClasses;
103
108
  }
@@ -109,19 +114,19 @@ var transformerPrompt = (options) => {
109
114
  const skipCurrent = skipNext;
110
115
  skipNext = false;
111
116
  const lastChild = hast.children.at(-1);
112
- if (lastChild) {
113
- if (lastChild.children[0].value.match(/\s+\\(?:\\)?\s*$/)) {
114
- skipNext = true;
115
- } else if (
116
- // @ts-expect-error property "children" does exist
117
- lastChild.children[0].value.match(/\s+\\n\s*$/)
118
- ) {
117
+ const lastToken = lastChild.children[0];
118
+ if (lastChild && lastToken) {
119
+ skipNext = breakOnRe.test(lastToken.value);
120
+ lastToken.value = lastToken.value.replace(breakOnRe, "");
121
+ if (lastChild.children[0].value.match(breakOnRe)) {
119
122
  skipNext = true;
120
- lastChild.children[0].value = // @ts-expect-error property "children" does exist
121
- lastChild.children[0].value.replace(
122
- /\s+\\n\s*$/,
123
- ""
124
- );
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
+ }
125
130
  }
126
131
  }
127
132
  if (skipCurrent) return;
@@ -7,6 +7,27 @@ import 'astro/zod';
7
7
  type PromptOptions = {
8
8
  prompt: string;
9
9
  cssClasses: string;
10
+ /**
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.
16
+ *
17
+ * @default \
18
+ */
19
+ breakOn?: string;
20
+ /**
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.
27
+ *
28
+ * @default false
29
+ */
30
+ hideBreak?: boolean;
10
31
  };
11
32
  type TransformOptions = {
12
33
  /**
@@ -17,7 +38,7 @@ type TransformOptions = {
17
38
  /**
18
39
  * An object mapping each language block to a prompt string. An object
19
40
  * can also be provided specified with two keys, the prompt and the
20
- * css classes that modify this prompt in particular. Useful when you
41
+ * CSS classes that modify this prompt in particular. Useful when you
21
42
  * want to style them differently from the
22
43
  * If not provided, it will default to look at the block attribute.
23
44
  */
@@ -7,6 +7,27 @@ import 'astro/zod';
7
7
  type PromptOptions = {
8
8
  prompt: string;
9
9
  cssClasses: string;
10
+ /**
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.
16
+ *
17
+ * @default \
18
+ */
19
+ breakOn?: string;
20
+ /**
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.
27
+ *
28
+ * @default false
29
+ */
30
+ hideBreak?: boolean;
10
31
  };
11
32
  type TransformOptions = {
12
33
  /**
@@ -17,7 +38,7 @@ type TransformOptions = {
17
38
  /**
18
39
  * An object mapping each language block to a prompt string. An object
19
40
  * can also be provided specified with two keys, the prompt and the
20
- * css classes that modify this prompt in particular. Useful when you
41
+ * CSS classes that modify this prompt in particular. Useful when you
21
42
  * want to style them differently from the
22
43
  * If not provided, it will default to look at the block attribute.
23
44
  */
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  transformAsciidocCallout,
3
3
  transformerPrompt
4
- } from "../../../chunk-NYOV2AHU.js";
4
+ } from "../../../chunk-4JCAN3ZN.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.14",
3
+ "version": "0.0.15",
4
4
  "description": "An Astro collections loader for Asciidoc files",
5
5
  "author": "D10f",
6
6
  "license": "MIT",