@gmb/bitmark-parser-generator 3.31.0 → 3.31.1
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/dist/browser/bitmark-parser-generator.min.js +1 -1
- package/dist/browser/bundle-report.html +2 -2
- package/dist/cjs/breakscaping/Breakscape.js +2 -3
- package/dist/cjs/breakscaping/Breakscape.js.map +1 -1
- package/dist/cjs/breakscaping/BreakscapeLoop.js +305 -0
- package/dist/cjs/breakscaping/BreakscapeLoop.js.map +1 -0
- package/dist/cjs/breakscaping/BreakscapeOptions.js +3 -0
- package/dist/cjs/breakscaping/BreakscapeOptions.js.map +1 -0
- package/dist/cjs/breakscaping/BreakscapeRegex.js +213 -0
- package/dist/cjs/breakscaping/BreakscapeRegex.js.map +1 -0
- package/dist/cjs/breakscaping/RegexConfigs.js +38 -0
- package/dist/cjs/breakscaping/RegexConfigs.js.map +1 -0
- package/dist/cjs/generated/build-info.js +1 -1
- package/dist/esm/breakscaping/Breakscape.js +2 -3
- package/dist/esm/breakscaping/Breakscape.js.map +1 -1
- package/dist/esm/breakscaping/BreakscapeLoop.js +302 -0
- package/dist/esm/breakscaping/BreakscapeLoop.js.map +1 -0
- package/dist/esm/breakscaping/BreakscapeOptions.js +2 -0
- package/dist/esm/breakscaping/BreakscapeOptions.js.map +1 -0
- package/dist/esm/breakscaping/BreakscapeRegex.js +177 -0
- package/dist/esm/breakscaping/BreakscapeRegex.js.map +1 -0
- package/dist/esm/breakscaping/RegexConfigs.js +35 -0
- package/dist/esm/breakscaping/RegexConfigs.js.map +1 -0
- package/dist/esm/generated/build-info.js +1 -1
- package/dist/types/breakscaping/Breakscape.d.ts.map +1 -1
- package/dist/types/breakscaping/BreakscapeLoop.d.ts +142 -0
- package/dist/types/breakscaping/BreakscapeLoop.d.ts.map +1 -0
- package/dist/types/breakscaping/BreakscapeOptions.d.ts +30 -0
- package/dist/types/breakscaping/BreakscapeOptions.d.ts.map +1 -0
- package/dist/types/breakscaping/BreakscapeRegex.d.ts +96 -0
- package/dist/types/breakscaping/BreakscapeRegex.d.ts.map +1 -0
- package/dist/types/breakscaping/RegexConfigs.d.ts +35 -0
- package/dist/types/breakscaping/RegexConfigs.d.ts.map +1 -0
- package/package.json +1 -2
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* breakscape.ts
|
|
3
|
+
* ------------------------------------------------------------
|
|
4
|
+
* Breakscaping for bitmark text.
|
|
5
|
+
* (c) 2025 — MIT / public domain
|
|
6
|
+
*/
|
|
7
|
+
import { buildInfo } from '../generated/build-info';
|
|
8
|
+
import { BodyTextFormat } from '../model/enum/BodyTextFormat';
|
|
9
|
+
import { TextLocation } from '../model/enum/TextLocation';
|
|
10
|
+
import * as RC from './RegexConfigs';
|
|
11
|
+
// default options
|
|
12
|
+
const DEF = {
|
|
13
|
+
format: BodyTextFormat.bitmarkPlusPlus,
|
|
14
|
+
location: TextLocation.body,
|
|
15
|
+
v2: false,
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Check if an object is a string.
|
|
19
|
+
*
|
|
20
|
+
* @param obj - The object to check.
|
|
21
|
+
* @returns true if the object is a string, otherwise false.
|
|
22
|
+
*/
|
|
23
|
+
function isString(obj) {
|
|
24
|
+
return typeof obj === 'string' || obj instanceof String;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* For breakscaping, select the correct regex and replacer for the text format, location, and v2 flag.
|
|
28
|
+
*/
|
|
29
|
+
function selectBreakscapeRegexAndReplacer(textFormat, textLocation, v2 = false) {
|
|
30
|
+
if (textLocation === TextLocation.tag) {
|
|
31
|
+
if (!v2 && textFormat === BodyTextFormat.bitmarkPlusPlus) {
|
|
32
|
+
return {
|
|
33
|
+
regex: RC.BREAKSCAPE_BITMARK_TAG_REGEX,
|
|
34
|
+
replacer: RC.BREAKSCAPE_BITMARK_TAG_REGEX_REPLACER,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
regex: RC.BREAKSCAPE_PLAIN_TAG_REGEX,
|
|
39
|
+
replacer: RC.BREAKSCAPE_PLAIN_TAG_REGEX_REPLACER,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
if (textFormat === BodyTextFormat.bitmarkPlusPlus) {
|
|
44
|
+
if (v2) {
|
|
45
|
+
return {
|
|
46
|
+
regex: RC.BREAKSCAPE_V2_BODY_REGEX,
|
|
47
|
+
replacer: RC.BREAKSCAPE_V2_BODY_REGEX_REPLACER,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
regex: RC.BREAKSCAPE_BITMARK_BODY_REGEX,
|
|
52
|
+
replacer: RC.BREAKSCAPE_BITMARK_BODY_REGEX_REPLACER,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
regex: RC.BREAKSCAPE_PLAIN_BODY_REGEX,
|
|
57
|
+
replacer: RC.BREAKSCAPE_PLAIN_BODY_REGEX_REPLACER,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* For unbreakscaping, select the correct regex and replacer for the text format and location.
|
|
63
|
+
*/
|
|
64
|
+
function selectUnbreakscapeRegexAndReplacer(textFormat, textLocation) {
|
|
65
|
+
const isPlain = textFormat !== BodyTextFormat.bitmarkPlusPlus;
|
|
66
|
+
if (textLocation === TextLocation.body && isPlain) {
|
|
67
|
+
return {
|
|
68
|
+
regex: RC.UNBREAKSCAPE_PLAIN_IN_BODY_REGEX,
|
|
69
|
+
replacer: RC.UNBREAKSCAPE_PLAIN_IN_BODY_REGEX_REPLACER,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
regex: RC.UNBREAKSCAPE_REGEX,
|
|
74
|
+
replacer: RC.UNBREAKSCAPE_REGEX_REPLACER,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
// -----------------------------------------------------------------------------
|
|
78
|
+
// ╭──────────────────────────────────────────────────────────────────────────╮
|
|
79
|
+
// │ 2. PUBLIC API │
|
|
80
|
+
// ╰──────────────────────────────────────────────────────────────────────────╯
|
|
81
|
+
class Breakscape {
|
|
82
|
+
constructor() {
|
|
83
|
+
this.EMPTY_STRING = '';
|
|
84
|
+
}
|
|
85
|
+
breakscape(val, opts = {}) {
|
|
86
|
+
if (val == null)
|
|
87
|
+
return undefined;
|
|
88
|
+
const options = Object.assign({}, DEF, opts);
|
|
89
|
+
if (Array.isArray(val)) {
|
|
90
|
+
return val.map((v) => this.breakscape(v, options));
|
|
91
|
+
}
|
|
92
|
+
// If an unrecognized type is passed, return it as is (e.g. true, false, 0, 1, etc.)
|
|
93
|
+
if (!isString(val))
|
|
94
|
+
return val;
|
|
95
|
+
const { regex, replacer } = selectBreakscapeRegexAndReplacer(options.format, options.location, options.v2);
|
|
96
|
+
let str = val;
|
|
97
|
+
str = str.replace(regex, replacer);
|
|
98
|
+
return str;
|
|
99
|
+
}
|
|
100
|
+
unbreakscape(val, opts = {}) {
|
|
101
|
+
if (val == null)
|
|
102
|
+
return undefined;
|
|
103
|
+
const options = Object.assign({}, DEF, opts);
|
|
104
|
+
if (Array.isArray(val)) {
|
|
105
|
+
return val.map((v) => this.unbreakscape(v, options));
|
|
106
|
+
}
|
|
107
|
+
// If an unrecognized type is passed, return it as is (e.g. true, false, 0, 1, etc.)
|
|
108
|
+
if (!isString(val))
|
|
109
|
+
return val;
|
|
110
|
+
const { regex, replacer } = selectUnbreakscapeRegexAndReplacer(options.format, options.location);
|
|
111
|
+
let str = val;
|
|
112
|
+
str = str.replace(regex, replacer);
|
|
113
|
+
return str;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Breakscape a code string or an array of code strings.
|
|
117
|
+
* If the input is an array, a new array will be returned.
|
|
118
|
+
*
|
|
119
|
+
* @param val input value
|
|
120
|
+
* @param modifyArray if true, the original array will be modified rather than a copy being made
|
|
121
|
+
* @returns the input value with any strings breakscaped
|
|
122
|
+
*/
|
|
123
|
+
breakscapeCode(val, options) {
|
|
124
|
+
if (val == null)
|
|
125
|
+
return val;
|
|
126
|
+
const opts = Object.assign({}, DEF, options);
|
|
127
|
+
const breakscapeStr = (str) => {
|
|
128
|
+
if (!str)
|
|
129
|
+
return str;
|
|
130
|
+
return str.replace(RC.BREAKSCAPE_CODE_REGEX, RC.BREAKSCAPE_CODE_REGEX_REPLACER);
|
|
131
|
+
};
|
|
132
|
+
if (Array.isArray(val)) {
|
|
133
|
+
const newVal = opts.inPlaceArray ? val : [val.length];
|
|
134
|
+
for (let i = 0, len = val.length; i < len; i++) {
|
|
135
|
+
const v = val[i];
|
|
136
|
+
if (isString(v)) {
|
|
137
|
+
val[i] = breakscapeStr(v);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
val = newVal;
|
|
141
|
+
}
|
|
142
|
+
else if (isString(val)) {
|
|
143
|
+
val = breakscapeStr(val);
|
|
144
|
+
}
|
|
145
|
+
return val;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Gets the version of the breakscape library.
|
|
149
|
+
*
|
|
150
|
+
* @returns The current version string of the library.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* const breakscape = new Breakscape();
|
|
155
|
+
* console.log(breakscape.version()); // e.g., "1.0.0"
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
version() {
|
|
159
|
+
return buildInfo.version;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Gets the license information for the breakscape library.
|
|
163
|
+
*
|
|
164
|
+
* @returns The license string for the library.
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```typescript
|
|
168
|
+
* const breakscape = new Breakscape();
|
|
169
|
+
* console.log(breakscape.license()); // e.g., "MIT"
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
license() {
|
|
173
|
+
return buildInfo.license;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
export { Breakscape };
|
|
177
|
+
//# sourceMappingURL=BreakscapeRegex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BreakscapeRegex.js","sourceRoot":"","sources":["../../../src/breakscaping/BreakscapeRegex.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAsB,MAAM,8BAA8B,CAAC;AAClF,OAAO,EAAE,YAAY,EAAoB,MAAM,4BAA4B,CAAC;AAG5E,OAAO,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAErC,kBAAkB;AAClB,MAAM,GAAG,GAAG;IACV,MAAM,EAAE,cAAc,CAAC,eAAe;IACtC,QAAQ,EAAE,YAAY,CAAC,IAAI;IAC3B,EAAE,EAAE,KAAK;CACD,CAAC;AAEX;;;;;GAKG;AACH,SAAS,QAAQ,CAAC,GAAY;IAC5B,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,YAAY,MAAM,CAAC;AAC1D,CAAC;AAED;;GAEG;AACH,SAAS,gCAAgC,CACvC,UAA8B,EAC9B,YAA8B,EAC9B,EAAE,GAAG,KAAK;IAEV,IAAI,YAAY,KAAK,YAAY,CAAC,GAAG,EAAE,CAAC;QACtC,IAAI,CAAC,EAAE,IAAI,UAAU,KAAK,cAAc,CAAC,eAAe,EAAE,CAAC;YACzD,OAAO;gBACL,KAAK,EAAE,EAAE,CAAC,4BAA4B;gBACtC,QAAQ,EAAE,EAAE,CAAC,qCAAqC;aACnD,CAAC;QACJ,CAAC;QACD,OAAO;YACL,KAAK,EAAE,EAAE,CAAC,0BAA0B;YACpC,QAAQ,EAAE,EAAE,CAAC,mCAAmC;SACjD,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,IAAI,UAAU,KAAK,cAAc,CAAC,eAAe,EAAE,CAAC;YAClD,IAAI,EAAE,E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AU,EAAE,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized regex and replacer constants for breakscape and unbreakscape.
|
|
3
|
+
* Extracted from breakscape-regex.ts to simplify core logic.
|
|
4
|
+
*/
|
|
5
|
+
export const REGEX_MARKS = /([*`_!=])(?=\1)/; // BM_TAG: $1^ --BODY: $1^ ++BODY: $1^
|
|
6
|
+
export const REGEX_BLOCKS = /^(\|)(code[\s]*|code:|image:|[\s]*$)/; // ++BODY: $2^$3
|
|
7
|
+
export const REGEX_TITLE_BLOCKS = /^([#]{1,3})([^\S\r\n]+)/; // ++BODY: $4^$5
|
|
8
|
+
export const REGEX_LIST_BLOCKS = /^(•)([0-9]+[iI]*|[a-zA-Z]{1}|_|\+|-|)([^\S\r\n]+)/; // ++BODY: $6^$7$8
|
|
9
|
+
export const REGEX_START_OF_TAG = /(\[)([.@#▼►%!?+\-$_=&])/; // --BODY: $2^$3 ++BODY: $9^$10
|
|
10
|
+
export const REGEX_FOOTER_DIVIDER = /^(~)(~~~[ \t]*)$/; // --BODY: $4^$5 ++BODY: $11^$12
|
|
11
|
+
export const REGEX_PLAIN_TEXT_DIVIDER = /^(\$)(\$\$\$[ \t]*)$/; // --BODY: $6^$7 ++BODY: $13^$14
|
|
12
|
+
export const REGEX_END_OF_TAG = /(\^*])/; // BM_TAG: ^$2 PLAIN_TAG: ^$1
|
|
13
|
+
export const REGEX_BIT_START = /^(\[)(\^*)(\.)/; // PLAIN_BODY: $1^$2$3
|
|
14
|
+
export const REGEX_HATS = /(\^+)/; // BM_TAG: $3^ PLAIN_TAG: $2^ --BODY: ^$8 ++BODY: $15^ // Must be last
|
|
15
|
+
export const BREAKSCAPE_BITMARK_TAG_REGEX_SOURCE = `${REGEX_MARKS.source}|${REGEX_END_OF_TAG.source}|${REGEX_HATS.source}`;
|
|
16
|
+
export const BREAKSCAPE_PLAIN_TAG_REGEX_SOURCE = `${REGEX_END_OF_TAG.source}|${REGEX_HATS.source}`;
|
|
17
|
+
export const BREAKSCAPE_BITMARK_BODY_REGEX_SOURCE = `${REGEX_MARKS.source}|${REGEX_BLOCKS.source}|${REGEX_TITLE_BLOCKS.source}|${REGEX_LIST_BLOCKS.source}|${REGEX_START_OF_TAG.source}|${REGEX_FOOTER_DIVIDER.source}|${REGEX_PLAIN_TEXT_DIVIDER.source}|${REGEX_HATS.source}`;
|
|
18
|
+
export const BREAKSCAPE_PLAIN_BODY_REGEX_SOURCE = `${REGEX_BIT_START.source}`;
|
|
19
|
+
export const BREAKSCAPE_BITMARK_TAG_REGEX = new RegExp(BREAKSCAPE_BITMARK_TAG_REGEX_SOURCE, 'gm');
|
|
20
|
+
export const BREAKSCAPE_BITMARK_TAG_REGEX_REPLACER = '$1$3^$2';
|
|
21
|
+
export const BREAKSCAPE_PLAIN_TAG_REGEX = new RegExp(BREAKSCAPE_PLAIN_TAG_REGEX_SOURCE, 'gm');
|
|
22
|
+
export const BREAKSCAPE_PLAIN_TAG_REGEX_REPLACER = '$2^$1';
|
|
23
|
+
export const BREAKSCAPE_BITMARK_BODY_REGEX = new RegExp(BREAKSCAPE_BITMARK_BODY_REGEX_SOURCE, 'gm');
|
|
24
|
+
export const BREAKSCAPE_BITMARK_BODY_REGEX_REPLACER = '$1$2$4$6$9$11$13$15^$3$5$7$8$10$12$14';
|
|
25
|
+
export const BREAKSCAPE_PLAIN_BODY_REGEX = new RegExp(BREAKSCAPE_PLAIN_BODY_REGEX_SOURCE, 'gm');
|
|
26
|
+
export const BREAKSCAPE_PLAIN_BODY_REGEX_REPLACER = '$1^$2$3';
|
|
27
|
+
export const BREAKSCAPE_V2_BODY_REGEX = new RegExp('^(?:(\\[)(\\^*)(\\.))|(\\^+)', 'gm');
|
|
28
|
+
export const BREAKSCAPE_V2_BODY_REGEX_REPLACER = '$1$4^$2$3';
|
|
29
|
+
export const UNBREAKSCAPE_REGEX = new RegExp('\\^([\\^]*)', 'gm');
|
|
30
|
+
export const UNBREAKSCAPE_REGEX_REPLACER = '$1';
|
|
31
|
+
export const UNBREAKSCAPE_PLAIN_IN_BODY_REGEX = new RegExp('^(\\[)\\^(\\^*)(\\.)', 'gm');
|
|
32
|
+
export const UNBREAKSCAPE_PLAIN_IN_BODY_REGEX_REPLACER = '$1$2$3';
|
|
33
|
+
export const BREAKSCAPE_CODE_REGEX = new RegExp('^(\\||•|#)', 'gm');
|
|
34
|
+
export const BREAKSCAPE_CODE_REGEX_REPLACER = '$1^';
|
|
35
|
+
//# sourceMappingURL=RegexConfigs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RegexConfigs.js","sourceRoot":"","sources":["../../../src/breakscaping/RegexConfigs.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,CAAC,MAAM,WAAW,GAAG,iBAAiB,CAAC,CAAC,wCAAwC;AACtF,MAAM,CAAC,MAAM,YAAY,GAAG,sCAAsC,CAAC,CAAC,gBAAgB;AACpF,MAAM,CAAC,MAAM,kBAAkB,GAAG,yBAAyB,CAAC,CAAC,gBAAgB;AAC7E,MAAM,CAAC,MAAM,iBAAiB,GAAG,mDAAmD,CAAC,CAAC,kBAAkB;AACxG,MAAM,CAAC,MAAM,kBAAkB,GAAG,yBAAyB,CAAC,CAAC,gCAAgC;AAC7F,MAAM,CAAC,MAAM,oBAAoB,GAAG,kBAAkB,CAAC,CAAC,iCAAiC;AACzF,MAAM,CAAC,MAAM,wBAAwB,GAAG,sBAAsB,CAAC,CAAC,iCAAiC;AACjG,MAAM,CAAC,MAAM,gBAAgB,GAAG,QAAQ,CAAC,CAAC,8BAA8B;AACxE,MAAM,CAAC,MAAM,eAAe,GAAG,gBAAgB,CAAC,CAAC,sBAAsB;AACvE,MAAM,CAAC,MAAM,UAAU,GAAG,OAAO,CAAC,CAAC,0EAA0E;AAE7G,MAAM,CAAC,MAAM,mCAAmC,GAAG,GAAG,WAAW,CAAC,MAAM,IAAI,gBAAgB,CAAC,MAAM,IAAI,UAAU,CAAC,MA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AAC,CAAC;AAClE,MAAM,CAAC,MAAM,2BAA2B,GAAG,IAAI,CAAC;AAEhD,MAAM,CAAC,MAAM,gCAAgC,GAAG,IAAI,MAAM,CAAC,sBAAsB,EAAE,IAAI,CAAC,CAAC;AACzF,MAAM,CAAC,MAAM,yCAAyC,GAAG,QAAQ,CAAC;AAElE,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,MAAM,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;AACpE,MAAM,CAAC,MAAM,8BAA8B,GAAG,KAAK,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Breakscape.d.ts","sourceRoot":"","sources":["../../../src/breakscaping/Breakscape.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Breakscape.d.ts","sourceRoot":"","sources":["../../../src/breakscaping/Breakscape.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAc,cAAc,EAAE,MAAM,0BAA0B,CAAC;AACtE,OAAO,EAAgB,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAI5E;;;;;;GAMG;AAEH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,UAAU,EAAE,cAAc,CAAC;IAE3B;;OAEG;IACH,YAAY,EAAE,gBAAgB,CAAC;IAE/B;;OAEG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB;;OAEG;IACH,EAAE,CAAC,EAAE,OAAO,CAAC;CACd;AAWD,cAAM,UAAU;IACd,SAAgB,YAAY,EAAS,iBAAiB,CAAC;IAEvD;;;;;;;;OAQG;IACI,UAAU,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,EACvD,GAAG,EAAE,CAAC,EACN,OAAO,EAAE,iBAAiB,GACzB,CAAC,SAAS,MAAM,GAAG,iBAAiB,GAAG,CAAC,SAAS,MAAM,EAAE,GAAG,iBAAiB,EAAE,GAAG,SAAS;IAa9F;;;;;;;OAOG;IACI,YAAY,CAAC,CAAC,SAAS,iBAAiB,GAAG,iBAAiB,EAAE,GAAG,SAAS,EAC/E,GAAG,EAAE,CAAC,EACN,OAAO,EAAE,iBAAiB,GACzB,CAAC,SAAS,iBAAiB,GAAG,MAAM,GAAG,CAAC,SAAS,iBAAiB,EAAE,GAAG,MAAM,EAAE,GAAG,SAAS;IAa9F;;;;;;;OAOG;IACI,cAAc,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,EAAE,GAAG,SAAS,EAC7D,GAAG,EAAE,CAAC,EACN,OAAO,CAAC,EAAE,iBAAiB,GAC1B,CAAC,SAAS,MAAM,GAAG,iBAAiB,GAAG,CAAC,SAAS,MAAM,EAAE,GAAG,iBAAiB,EAAE,GAAG,SAAS;IAa9F;;;;;;OAMG;IACI,WAAW,CAAC,EAAE,EAAE,iBAAiB,EAAE,EAAE,EAAE,iBAAiB,GAAG,iBAAiB;CAGpF;AAED,QAAA,MAAM,QAAQ,YAAmB,CAAC;AAElC,OAAO,EAAE,QAAQ,IAAI,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* breakscape.ts
|
|
3
|
+
* ------------------------------------------------------------
|
|
4
|
+
* Breakscaping for bitmark text.
|
|
5
|
+
* (c) 2025 — MIT / public domain
|
|
6
|
+
*/
|
|
7
|
+
import { BreakscapeOptions } from './BreakscapeOptions';
|
|
8
|
+
/**
|
|
9
|
+
* Main class for performing breakscape and unbreakscape operations on bitmark text.
|
|
10
|
+
*
|
|
11
|
+
* Breakscaping is the process of escaping special characters in bitmark text to prevent
|
|
12
|
+
* them from being interpreted as markup. This includes adding caret (^) characters before
|
|
13
|
+
* special characters that would otherwise be interpreted as bitmark syntax.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const breakscape = new Breakscape();
|
|
18
|
+
*
|
|
19
|
+
* // Breakscape a string
|
|
20
|
+
* const escaped = breakscape.breakscape('[.hello]');
|
|
21
|
+
*
|
|
22
|
+
* // Unbreakscape a string
|
|
23
|
+
* const unescaped = breakscape.unbreakscape('[^.hello]');
|
|
24
|
+
*
|
|
25
|
+
* // Process arrays
|
|
26
|
+
* const escapedArray = breakscape.breakscape(['[.hello]', '[.world]']);
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
declare class Breakscape {
|
|
32
|
+
/**
|
|
33
|
+
* Escapes special characters in bitmark text by adding caret (^) characters.
|
|
34
|
+
*
|
|
35
|
+
* This method processes text to prevent special characters from being interpreted
|
|
36
|
+
* as bitmark markup. It handles various scenarios including:
|
|
37
|
+
* - Tag triggers after '[' characters
|
|
38
|
+
* - Paired punctuation marks
|
|
39
|
+
* - Hat characters (^)
|
|
40
|
+
* - End-of-tag brackets
|
|
41
|
+
* - Beginning-of-line markers
|
|
42
|
+
*
|
|
43
|
+
* IMPORTANT: Breakscaping differs depending on the bit text format, and if the text will
|
|
44
|
+
* be used in a tag or in the body of a bitmark. The default is bitmark++ in the body.
|
|
45
|
+
* If the text is to be used in a tag, or is not bitmark++, you must specify the textFormat
|
|
46
|
+
* and textLocation options.
|
|
47
|
+
*
|
|
48
|
+
* @param val - The input to breakscape. Can be a string, array of strings, null, or undefined.
|
|
49
|
+
* @param opts - Optional configuration for the breakscape operation.
|
|
50
|
+
* @returns The breakscaped result with the same type as the input.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const breakscape = new Breakscape();
|
|
55
|
+
*
|
|
56
|
+
* // Single string
|
|
57
|
+
* breakscape.breakscape('[.hello]'); // Returns '[^.hello]'
|
|
58
|
+
*
|
|
59
|
+
* // Array of strings
|
|
60
|
+
* breakscape.breakscape(['[.hello]', '[.world]']); // Returns ['[^.hello]', '[^.world]']
|
|
61
|
+
*
|
|
62
|
+
* // With options
|
|
63
|
+
* breakscape.breakscape('[.hello]', {
|
|
64
|
+
* textFormat: TextFormat.bitmark++,
|
|
65
|
+
* textLocation: TextLocation.body
|
|
66
|
+
* });
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
breakscape(val: string, opts?: BreakscapeOptions): string;
|
|
70
|
+
breakscape(val: string[], opts?: BreakscapeOptions): string[];
|
|
71
|
+
breakscape(val: undefined | null, opts?: BreakscapeOptions): undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Removes escape characters (carets) from previously breakscaped bitmark text.
|
|
74
|
+
*
|
|
75
|
+
* This method reverses the breakscape operation by removing caret (^) characters
|
|
76
|
+
* that were added to escape special bitmark syntax.
|
|
77
|
+
*
|
|
78
|
+
* IMPORTANT: Unbreakscaping differs depending on the bit text format, and if the text will
|
|
79
|
+
* be used in a tag or in the body of a bitmark. The default is bitmark++ in the body.
|
|
80
|
+
* If the text is to be used in a tag, or is not bitmark++, you must specify the textFormat
|
|
81
|
+
* and textLocation options.
|
|
82
|
+
*
|
|
83
|
+
* @param val - The input to unbreakscape. Can be a string, array of strings, null, or undefined.
|
|
84
|
+
* @param opts - Optional configuration for the unbreakscape operation.
|
|
85
|
+
* @returns The unbreakscaped result with the same type as the input.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const breakscape = new Breakscape();
|
|
90
|
+
*
|
|
91
|
+
* // Single string
|
|
92
|
+
* breakscape.unbreakscape('[^.hello]'); // Returns '[.hello]'
|
|
93
|
+
*
|
|
94
|
+
* // Array of strings
|
|
95
|
+
* breakscape.unbreakscape(['[^.hello]', '[^.world]']); // Returns ['[.hello]', '[.world]']
|
|
96
|
+
*
|
|
97
|
+
* // With options
|
|
98
|
+
* breakscape.unbreakscape('[^.hello]', {
|
|
99
|
+
* textFormat: TextFormat.bitmarkPlusPlus,
|
|
100
|
+
* textLocation: TextLocation.body
|
|
101
|
+
* });
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
unbreakscape(val: string, opts?: BreakscapeOptions): string;
|
|
105
|
+
unbreakscape(val: string[], opts?: BreakscapeOptions): string[];
|
|
106
|
+
unbreakscape(val: undefined | null, opts?: BreakscapeOptions): undefined;
|
|
107
|
+
/**
|
|
108
|
+
* Breakscape a code string or an array of code strings.
|
|
109
|
+
* If the input is an array, a new array will be returned.
|
|
110
|
+
*
|
|
111
|
+
* @param val input value
|
|
112
|
+
* @param modifyArray if true, the original array will be modified rather than a copy being made
|
|
113
|
+
* @returns the input value with any strings breakscaped
|
|
114
|
+
*/
|
|
115
|
+
breakscapeCode<T extends unknown | unknown[] | undefined>(_val: T, _options?: BreakscapeOptions): T extends string ? string : T extends string[] ? string[] : undefined;
|
|
116
|
+
/**
|
|
117
|
+
* Gets the version of the breakscape library.
|
|
118
|
+
*
|
|
119
|
+
* @returns The current version string of the library.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* const breakscape = new Breakscape();
|
|
124
|
+
* console.log(breakscape.version()); // e.g., "1.0.0"
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
version(): string;
|
|
128
|
+
/**
|
|
129
|
+
* Gets the license information for the breakscape library.
|
|
130
|
+
*
|
|
131
|
+
* @returns The license string for the library.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* const breakscape = new Breakscape();
|
|
136
|
+
* console.log(breakscape.license()); // e.g., "MIT"
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
license(): string;
|
|
140
|
+
}
|
|
141
|
+
export { Breakscape };
|
|
142
|
+
//# sourceMappingURL=BreakscapeLoop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BreakscapeLoop.d.ts","sourceRoot":"","sources":["../../../src/breakscaping/BreakscapeLoop.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AA0NxD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,cAAM,UAAU;IACd;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoCG;IACH,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,iBAAiB,GAAG,MAAM;IACzD,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,EAAE,iBAAiB,GAAG,MAAM,EAAE;IAC7D,UAAU,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,EAAE,IAAI,CAAC,EAAE,iBAAiB,GAAG,SAAS;IAatE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACH,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,iBAAiB,GAAG,MAAM;IAC3D,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,EAAE,iBAAiB,GAAG,MAAM,EAAE;IAC/D,YAAY,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,EAAE,IAAI,CAAC,EAAE,iBAAiB,GAAG,SAAS;IAaxE;;;;;;;OAOG;IACI,cAAc,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,EAAE,GAAG,SAAS,EAC7D,IAAI,EAAE,CAAC,EACP,QAAQ,CAAC,EAAE,iBAAiB,GAC3B,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,CAAC,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,GAAG,SAAS;IAOxE;;;;;;;;;;OAUG;IACH,OAAO,IAAI,MAAM;IAIjB;;;;;;;;;;OAUG;IACH,OAAO,IAAI,MAAM;CAGlB;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BodyTextFormatType } from '../model/enum/BodyTextFormat';
|
|
2
|
+
import { TextLocationType } from '../model/enum/TextLocation';
|
|
3
|
+
/**
|
|
4
|
+
* Configuration options for breakscape and unbreakscape operations.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export interface BreakscapeOptions {
|
|
9
|
+
/**
|
|
10
|
+
* The text format to use for processing.
|
|
11
|
+
* @defaultValue TextFormat.bitmarkPlusPlus
|
|
12
|
+
*/
|
|
13
|
+
format?: BodyTextFormatType;
|
|
14
|
+
/**
|
|
15
|
+
* The text location context for processing.
|
|
16
|
+
* @defaultValue TextLocation.body
|
|
17
|
+
*/
|
|
18
|
+
location?: TextLocationType;
|
|
19
|
+
/**
|
|
20
|
+
* Whether to mutate the input array in-place when processing arrays.
|
|
21
|
+
* If false, a new array will be created.
|
|
22
|
+
* @defaultValue false
|
|
23
|
+
*/
|
|
24
|
+
inPlaceArray?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Legacy: if true, perform v2 breakscaping from JSON
|
|
27
|
+
*/
|
|
28
|
+
v2?: boolean;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=BreakscapeOptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BreakscapeOptions.d.ts","sourceRoot":"","sources":["../../../src/breakscaping/BreakscapeOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,MAAM,CAAC,EAAE,kBAAkB,CAAC;IAE5B;;;OAGG;IACH,QAAQ,CAAC,EAAE,gBAAgB,CAAC;IAE5B;;;;OAIG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB;;OAEG;IACH,EAAE,CAAC,EAAE,OAAO,CAAC;CACd"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* breakscape.ts
|
|
3
|
+
* ------------------------------------------------------------
|
|
4
|
+
* Breakscaping for bitmark text.
|
|
5
|
+
* (c) 2025 — MIT / public domain
|
|
6
|
+
*/
|
|
7
|
+
import type { BreakscapeOptions } from './BreakscapeOptions';
|
|
8
|
+
declare class Breakscape {
|
|
9
|
+
readonly EMPTY_STRING: string;
|
|
10
|
+
/**
|
|
11
|
+
* Escapes special characters in bitmark text by adding caret (^) characters.
|
|
12
|
+
*
|
|
13
|
+
* This method processes text to prevent special characters from being interpreted
|
|
14
|
+
* as bitmark markup. It handles various scenarios including:
|
|
15
|
+
* - Tag triggers after '[' characters
|
|
16
|
+
* - Paired punctuation marks
|
|
17
|
+
* - Hat characters (^)
|
|
18
|
+
* - End-of-tag brackets
|
|
19
|
+
* - Beginning-of-line markers
|
|
20
|
+
*
|
|
21
|
+
* IMPORTANT: Breakscaping differs depending on the bit text format, and if the text will
|
|
22
|
+
* be used in a tag or in the body of a bitmark. The default is bitmark++ in the body.
|
|
23
|
+
* If the text is to be used in a tag, or is not bitmark++, you must specify the textFormat
|
|
24
|
+
* and textLocation options.
|
|
25
|
+
*
|
|
26
|
+
* @param val - The input to breakscape. Can be a string, array of strings, null, or undefined.
|
|
27
|
+
* @param opts - Optional configuration for the breakscape operation.
|
|
28
|
+
* @returns The breakscaped result with the same type as the input.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const breakscape = new Breakscape();
|
|
33
|
+
*
|
|
34
|
+
* // Single string
|
|
35
|
+
* breakscape.breakscape('[.hello]'); // Returns '[^.hello]'
|
|
36
|
+
*
|
|
37
|
+
* // Array of strings
|
|
38
|
+
* breakscape.breakscape(['[.hello]', '[.world]']); // Returns ['[^.hello]', '[^.world]']
|
|
39
|
+
*
|
|
40
|
+
* // With options
|
|
41
|
+
* breakscape.breakscape('[.hello]', {
|
|
42
|
+
* textFormat: TextFormat.bitmark++,
|
|
43
|
+
* textLocation: TextLocation.body
|
|
44
|
+
* });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
breakscape(val: string, opts?: BreakscapeOptions): string;
|
|
48
|
+
breakscape(val: string[], opts?: BreakscapeOptions): string[];
|
|
49
|
+
breakscape(val: undefined | null, opts?: BreakscapeOptions): undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Unbreakscape a string or an array of strings.
|
|
52
|
+
* If the input is an array, a new array will be returned.
|
|
53
|
+
*
|
|
54
|
+
* @param val input value
|
|
55
|
+
* @param opts options for unbreakscaping
|
|
56
|
+
* @returns the input value with any strings unbreakscaped.
|
|
57
|
+
*/
|
|
58
|
+
unbreakscape(val: string, opts?: BreakscapeOptions): string;
|
|
59
|
+
unbreakscape(val: string[], opts?: BreakscapeOptions): string[];
|
|
60
|
+
unbreakscape(val: undefined | null, opts?: BreakscapeOptions): undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Breakscape a code string or an array of code strings.
|
|
63
|
+
* If the input is an array, a new array will be returned.
|
|
64
|
+
*
|
|
65
|
+
* @param val input value
|
|
66
|
+
* @param modifyArray if true, the original array will be modified rather than a copy being made
|
|
67
|
+
* @returns the input value with any strings breakscaped
|
|
68
|
+
*/
|
|
69
|
+
breakscapeCode<T extends unknown | unknown[] | undefined>(val: T, options?: BreakscapeOptions): T extends string ? string : T extends string[] ? string[] : undefined;
|
|
70
|
+
/**
|
|
71
|
+
* Gets the version of the breakscape library.
|
|
72
|
+
*
|
|
73
|
+
* @returns The current version string of the library.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* const breakscape = new Breakscape();
|
|
78
|
+
* console.log(breakscape.version()); // e.g., "1.0.0"
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
version(): string;
|
|
82
|
+
/**
|
|
83
|
+
* Gets the license information for the breakscape library.
|
|
84
|
+
*
|
|
85
|
+
* @returns The license string for the library.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const breakscape = new Breakscape();
|
|
90
|
+
* console.log(breakscape.license()); // e.g., "MIT"
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
license(): string;
|
|
94
|
+
}
|
|
95
|
+
export { Breakscape };
|
|
96
|
+
//# sourceMappingURL=BreakscapeRegex.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BreakscapeRegex.d.ts","sourceRoot":"","sources":["../../../src/breakscaping/BreakscapeRegex.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAmF7D,cAAM,UAAU;IACd,SAAgB,YAAY,EAAS,MAAM,CAAC;IAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoCG;IACH,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,iBAAiB,GAAG,MAAM;IACzD,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,EAAE,iBAAiB,GAAG,MAAM,EAAE;IAC7D,UAAU,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,EAAE,IAAI,CAAC,EAAE,iBAAiB,GAAG,SAAS;IAiBtE;;;;;;;OAOG;IACH,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,iBAAiB,GAAG,MAAM;IAC3D,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,EAAE,iBAAiB,GAAG,MAAM,EAAE;IAC/D,YAAY,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,EAAE,IAAI,CAAC,EAAE,iBAAiB,GAAG,SAAS;IAiBxE;;;;;;;OAOG;IACI,cAAc,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,EAAE,GAAG,SAAS,EAC7D,GAAG,EAAE,CAAC,EACN,OAAO,CAAC,EAAE,iBAAiB,GAC1B,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,CAAC,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,GAAG,SAAS;IA4BxE;;;;;;;;;;OAUG;IACH,OAAO,IAAI,MAAM;IAIjB;;;;;;;;;;OAUG;IACH,OAAO,IAAI,MAAM;CAGlB;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized regex and replacer constants for breakscape and unbreakscape.
|
|
3
|
+
* Extracted from breakscape-regex.ts to simplify core logic.
|
|
4
|
+
*/
|
|
5
|
+
export declare const REGEX_MARKS: RegExp;
|
|
6
|
+
export declare const REGEX_BLOCKS: RegExp;
|
|
7
|
+
export declare const REGEX_TITLE_BLOCKS: RegExp;
|
|
8
|
+
export declare const REGEX_LIST_BLOCKS: RegExp;
|
|
9
|
+
export declare const REGEX_START_OF_TAG: RegExp;
|
|
10
|
+
export declare const REGEX_FOOTER_DIVIDER: RegExp;
|
|
11
|
+
export declare const REGEX_PLAIN_TEXT_DIVIDER: RegExp;
|
|
12
|
+
export declare const REGEX_END_OF_TAG: RegExp;
|
|
13
|
+
export declare const REGEX_BIT_START: RegExp;
|
|
14
|
+
export declare const REGEX_HATS: RegExp;
|
|
15
|
+
export declare const BREAKSCAPE_BITMARK_TAG_REGEX_SOURCE: string;
|
|
16
|
+
export declare const BREAKSCAPE_PLAIN_TAG_REGEX_SOURCE: string;
|
|
17
|
+
export declare const BREAKSCAPE_BITMARK_BODY_REGEX_SOURCE: string;
|
|
18
|
+
export declare const BREAKSCAPE_PLAIN_BODY_REGEX_SOURCE: string;
|
|
19
|
+
export declare const BREAKSCAPE_BITMARK_TAG_REGEX: RegExp;
|
|
20
|
+
export declare const BREAKSCAPE_BITMARK_TAG_REGEX_REPLACER = "$1$3^$2";
|
|
21
|
+
export declare const BREAKSCAPE_PLAIN_TAG_REGEX: RegExp;
|
|
22
|
+
export declare const BREAKSCAPE_PLAIN_TAG_REGEX_REPLACER = "$2^$1";
|
|
23
|
+
export declare const BREAKSCAPE_BITMARK_BODY_REGEX: RegExp;
|
|
24
|
+
export declare const BREAKSCAPE_BITMARK_BODY_REGEX_REPLACER = "$1$2$4$6$9$11$13$15^$3$5$7$8$10$12$14";
|
|
25
|
+
export declare const BREAKSCAPE_PLAIN_BODY_REGEX: RegExp;
|
|
26
|
+
export declare const BREAKSCAPE_PLAIN_BODY_REGEX_REPLACER = "$1^$2$3";
|
|
27
|
+
export declare const BREAKSCAPE_V2_BODY_REGEX: RegExp;
|
|
28
|
+
export declare const BREAKSCAPE_V2_BODY_REGEX_REPLACER = "$1$4^$2$3";
|
|
29
|
+
export declare const UNBREAKSCAPE_REGEX: RegExp;
|
|
30
|
+
export declare const UNBREAKSCAPE_REGEX_REPLACER = "$1";
|
|
31
|
+
export declare const UNBREAKSCAPE_PLAIN_IN_BODY_REGEX: RegExp;
|
|
32
|
+
export declare const UNBREAKSCAPE_PLAIN_IN_BODY_REGEX_REPLACER = "$1$2$3";
|
|
33
|
+
export declare const BREAKSCAPE_CODE_REGEX: RegExp;
|
|
34
|
+
export declare const BREAKSCAPE_CODE_REGEX_REPLACER = "$1^";
|
|
35
|
+
//# sourceMappingURL=RegexConfigs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RegexConfigs.d.ts","sourceRoot":"","sources":["../../../src/breakscaping/RegexConfigs.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,eAAO,MAAM,WAAW,QAAoB,CAAC;AAC7C,eAAO,MAAM,YAAY,QAAyC,CAAC;AACnE,eAAO,MAAM,kBAAkB,QAA4B,CAAC;AAC5D,eAAO,MAAM,iBAAiB,QAAsD,CAAC;AACrF,eAAO,MAAM,kBAAkB,QAA4B,CAAC;AAC5D,eAAO,MAAM,oBAAoB,QAAqB,CAAC;AACvD,eAAO,MAAM,wBAAwB,QAAyB,CAAC;AAC/D,eAAO,MAAM,gBAAgB,QAAW,CAAC;AACzC,eAAO,MAAM,eAAe,QAAmB,CAAC;AAChD,eAAO,MAAM,UAAU,QAAU,CAAC;AAElC,eAAO,MAAM,mCAAmC,QAA0E,CAAC;AAC3H,eAAO,MAAM,iCAAiC,QAAoD,CAAC;AACnG,eAAO,MAAM,oCAAoC,QAA8N,CAAC;AAChR,eAAO,MAAM,kCAAkC,QAA8B,CAAC;AAE9E,eAAO,MAAM,4BAA4B,QAAwD,CAAC;AAClG,eAAO,MAAM,qCAAqC,YAAY,CAAC;AAE/D,eAAO,MAAM,0BAA0B,QAAsD,CAAC;AAC9F,eAAO,MAAM,mCAAmC,UAAU,CAAC;AAE3D,eAAO,MAAM,6BAA6B,QAAyD,CAAC;AACpG,eAAO,MAAM,sCAAsC,0CAA0C,CAAC;AAE9F,eAAO,MAAM,2BAA2B,QAAuD,CAAC;AAChG,eAAO,MAAM,oCAAoC,YAAY,CAAC;AAE9D,eAAO,MAAM,wBAAwB,QAAmD,CAAC;AACzF,eAAO,MAAM,iCAAiC,cAAc,CAAC;AAE7D,eAAO,MAAM,kBAAkB,QAAkC,CAAC;AAClE,eAAO,MAAM,2BAA2B,OAAO,CAAC;AAEhD,eAAO,MAAM,gCAAgC,QAA2C,CAAC;AACzF,eAAO,MAAM,yCAAyC,WAAW,CAAC;AAElE,eAAO,MAAM,qBAAqB,QAAiC,CAAC;AACpE,eAAO,MAAM,8BAA8B,QAAQ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gmb/bitmark-parser-generator",
|
|
3
|
-
"version": "3.31.
|
|
3
|
+
"version": "3.31.1",
|
|
4
4
|
"description": "A bitmark parser and generator using Peggy.js",
|
|
5
5
|
"author": "Get More Brain Ltd",
|
|
6
6
|
"license": "ISC",
|
|
@@ -126,7 +126,6 @@
|
|
|
126
126
|
"webpack-strip-block": "^0.3.0"
|
|
127
127
|
},
|
|
128
128
|
"dependencies": {
|
|
129
|
-
"@gmb/bitmark-breakscape": "^3.30.2",
|
|
130
129
|
"@ncoderz/superenum": "^0.2.5",
|
|
131
130
|
"@types/fs-extra": "^11.0.4",
|
|
132
131
|
"@ungap/structured-clone": "^1.3.0",
|