@gmb/bitmark-parser-generator 3.31.0 → 3.32.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.
- package/LICENSE +2 -6
- package/README.md +58 -0
- package/dist/browser/bitmark-parser-generator.min.js +1 -1
- package/dist/browser/bundle-report.html +2 -2
- package/dist/cjs/BitmarkParserGenerator.js +6 -6
- package/dist/cjs/BitmarkParserGenerator.js.map +1 -1
- package/dist/cjs/ast/BaseBuilder.js +8 -8
- package/dist/cjs/ast/BaseBuilder.js.map +1 -1
- package/dist/cjs/ast/Builder.js +5 -5
- package/dist/cjs/ast/Builder.js.map +1 -1
- package/dist/cjs/breakscaping/Breakscape.js +15 -19
- 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/config/raw/bits.js +38 -0
- package/dist/cjs/config/raw/bits.js.map +1 -1
- package/dist/cjs/config/raw/groups.js +20 -0
- package/dist/cjs/config/raw/groups.js.map +1 -1
- package/dist/cjs/config/raw/properties.js +21 -0
- package/dist/cjs/config/raw/properties.js.map +1 -1
- package/dist/cjs/generated/build-info.js +1 -1
- package/dist/cjs/generator/bitmark/BitmarkGenerator.js +4 -4
- package/dist/cjs/generator/bitmark/BitmarkGenerator.js.map +1 -1
- package/dist/cjs/generator/json/JsonGenerator.js +7 -2
- package/dist/cjs/generator/json/JsonGenerator.js.map +1 -1
- package/dist/cjs/generator/text/TextGenerator.js +8 -8
- package/dist/cjs/generator/text/TextGenerator.js.map +1 -1
- package/dist/cjs/model/ast/NodeType.js +8 -0
- package/dist/cjs/model/ast/NodeType.js.map +1 -1
- package/dist/cjs/model/config/enum/PropertyConfigKey.js +4 -0
- package/dist/cjs/model/config/enum/PropertyConfigKey.js.map +1 -1
- package/dist/cjs/model/enum/BitType.js +8 -0
- package/dist/cjs/model/enum/BitType.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/BitmarkPegParserHelper.js +4 -4
- package/dist/cjs/parser/bitmark/peg/BitmarkPegParserHelper.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/BitmarkPegParserProcessor.js +4 -4
- package/dist/cjs/parser/bitmark/peg/BitmarkPegParserProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/BodyContentProcessor.js +8 -8
- package/dist/cjs/parser/bitmark/peg/contentProcessors/BodyContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/BookChainContentProcessor.js +2 -2
- package/dist/cjs/parser/bitmark/peg/contentProcessors/BookChainContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/ClozeTagContentProcessor.js +3 -3
- package/dist/cjs/parser/bitmark/peg/contentProcessors/ClozeTagContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/DefaultTagContentProcessor.js +16 -13
- package/dist/cjs/parser/bitmark/peg/contentProcessors/DefaultTagContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/ExampleTagContentProcessor.js +7 -5
- package/dist/cjs/parser/bitmark/peg/contentProcessors/ExampleTagContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/FooterContentProcessor.js +6 -6
- package/dist/cjs/parser/bitmark/peg/contentProcessors/FooterContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/ImageSourceChainContentProcessor.js +2 -2
- package/dist/cjs/parser/bitmark/peg/contentProcessors/ImageSourceChainContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/ItemLeadTagContentProcessor.js +2 -2
- package/dist/cjs/parser/bitmark/peg/contentProcessors/ItemLeadTagContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/MarkConfigChainContentProcessor.js +2 -2
- package/dist/cjs/parser/bitmark/peg/contentProcessors/MarkConfigChainContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/PersonChainContentProcessor.js +2 -2
- package/dist/cjs/parser/bitmark/peg/contentProcessors/PersonChainContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.js +12 -12
- package/dist/cjs/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/RatingLevelChainContentProcessor.js +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/RatingLevelChainContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/ReferenceTagContentProcessor.js +4 -4
- package/dist/cjs/parser/bitmark/peg/contentProcessors/ReferenceTagContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/ResourceContentProcessor.js +2 -2
- package/dist/cjs/parser/bitmark/peg/contentProcessors/ResourceContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/TechnicalTermChainContentProcessor.js +2 -2
- package/dist/cjs/parser/bitmark/peg/contentProcessors/TechnicalTermChainContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/TitleTagContentProcessor.js +2 -2
- package/dist/cjs/parser/bitmark/peg/contentProcessors/TitleTagContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/TrueFalseTagContentProcessor.js +2 -2
- package/dist/cjs/parser/bitmark/peg/contentProcessors/TrueFalseTagContentProcessor.js.map +1 -1
- package/dist/cjs/parser/text/TextParser.js +1 -1
- package/dist/cjs/parser/text/TextParser.js.map +1 -1
- package/dist/cjs/utils/BitUtils.js +3 -1
- package/dist/cjs/utils/BitUtils.js.map +1 -1
- package/dist/esm/BitmarkParserGenerator.js +6 -6
- package/dist/esm/BitmarkParserGenerator.js.map +1 -1
- package/dist/esm/ast/BaseBuilder.js +8 -8
- package/dist/esm/ast/BaseBuilder.js.map +1 -1
- package/dist/esm/ast/Builder.js +5 -5
- package/dist/esm/ast/Builder.js.map +1 -1
- package/dist/esm/breakscaping/Breakscape.js +15 -19
- 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/config/raw/bits.js +38 -0
- package/dist/esm/config/raw/bits.js.map +1 -1
- package/dist/esm/config/raw/groups.js +20 -0
- package/dist/esm/config/raw/groups.js.map +1 -1
- package/dist/esm/config/raw/properties.js +21 -0
- package/dist/esm/config/raw/properties.js.map +1 -1
- package/dist/esm/generated/build-info.js +1 -1
- package/dist/esm/generator/bitmark/BitmarkGenerator.js +4 -4
- package/dist/esm/generator/bitmark/BitmarkGenerator.js.map +1 -1
- package/dist/esm/generator/json/JsonGenerator.js +7 -2
- package/dist/esm/generator/json/JsonGenerator.js.map +1 -1
- package/dist/esm/generator/text/TextGenerator.js +8 -8
- package/dist/esm/generator/text/TextGenerator.js.map +1 -1
- package/dist/esm/model/ast/NodeType.js +8 -0
- package/dist/esm/model/ast/NodeType.js.map +1 -1
- package/dist/esm/model/config/enum/PropertyConfigKey.js +4 -0
- package/dist/esm/model/config/enum/PropertyConfigKey.js.map +1 -1
- package/dist/esm/model/enum/BitType.js +8 -0
- package/dist/esm/model/enum/BitType.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/BitmarkPegParserHelper.js +4 -4
- package/dist/esm/parser/bitmark/peg/BitmarkPegParserHelper.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/BitmarkPegParserProcessor.js +4 -4
- package/dist/esm/parser/bitmark/peg/BitmarkPegParserProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/BodyContentProcessor.js +8 -8
- package/dist/esm/parser/bitmark/peg/contentProcessors/BodyContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/BookChainContentProcessor.js +2 -2
- package/dist/esm/parser/bitmark/peg/contentProcessors/BookChainContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/ClozeTagContentProcessor.js +3 -3
- package/dist/esm/parser/bitmark/peg/contentProcessors/ClozeTagContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/DefaultTagContentProcessor.js +16 -13
- package/dist/esm/parser/bitmark/peg/contentProcessors/DefaultTagContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/ExampleTagContentProcessor.js +7 -5
- package/dist/esm/parser/bitmark/peg/contentProcessors/ExampleTagContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/FooterContentProcessor.js +6 -6
- package/dist/esm/parser/bitmark/peg/contentProcessors/FooterContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/ImageSourceChainContentProcessor.js +2 -2
- package/dist/esm/parser/bitmark/peg/contentProcessors/ImageSourceChainContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/ItemLeadTagContentProcessor.js +2 -2
- package/dist/esm/parser/bitmark/peg/contentProcessors/ItemLeadTagContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/MarkConfigChainContentProcessor.js +2 -2
- package/dist/esm/parser/bitmark/peg/contentProcessors/MarkConfigChainContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/PersonChainContentProcessor.js +2 -2
- package/dist/esm/parser/bitmark/peg/contentProcessors/PersonChainContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.js +12 -12
- package/dist/esm/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/RatingLevelChainContentProcessor.js +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/RatingLevelChainContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/ReferenceTagContentProcessor.js +4 -4
- package/dist/esm/parser/bitmark/peg/contentProcessors/ReferenceTagContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/ResourceContentProcessor.js +2 -2
- package/dist/esm/parser/bitmark/peg/contentProcessors/ResourceContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/TechnicalTermChainContentProcessor.js +2 -2
- package/dist/esm/parser/bitmark/peg/contentProcessors/TechnicalTermChainContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/TitleTagContentProcessor.js +2 -2
- package/dist/esm/parser/bitmark/peg/contentProcessors/TitleTagContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/TrueFalseTagContentProcessor.js +2 -2
- package/dist/esm/parser/bitmark/peg/contentProcessors/TrueFalseTagContentProcessor.js.map +1 -1
- package/dist/esm/parser/text/TextParser.js +1 -1
- package/dist/esm/parser/text/TextParser.js.map +1 -1
- package/dist/esm/utils/BitUtils.js +3 -1
- package/dist/esm/utils/BitUtils.js.map +1 -1
- package/dist/types/ast/Builder.d.ts +4 -0
- package/dist/types/ast/Builder.d.ts.map +1 -1
- package/dist/types/breakscaping/Breakscape.d.ts +1 -27
- 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/dist/types/config/raw/bits.d.ts.map +1 -1
- package/dist/types/config/raw/groups.d.ts.map +1 -1
- package/dist/types/config/raw/properties.d.ts.map +1 -1
- package/dist/types/generator/json/JsonGenerator.d.ts.map +1 -1
- package/dist/types/generator/text/TextGenerator.d.ts +1 -1
- package/dist/types/generator/text/TextGenerator.d.ts.map +1 -1
- package/dist/types/model/ast/NodeType.d.ts +16 -0
- package/dist/types/model/ast/NodeType.d.ts.map +1 -1
- package/dist/types/model/ast/Nodes.d.ts +4 -0
- package/dist/types/model/ast/Nodes.d.ts.map +1 -1
- package/dist/types/model/config/enum/ConfigKey.d.ts +8 -0
- package/dist/types/model/config/enum/ConfigKey.d.ts.map +1 -1
- package/dist/types/model/config/enum/PropertyConfigKey.d.ts +12 -0
- package/dist/types/model/config/enum/PropertyConfigKey.d.ts.map +1 -1
- package/dist/types/model/enum/BitType.d.ts +16 -0
- package/dist/types/model/enum/BitType.d.ts.map +1 -1
- package/dist/types/model/enum/PropertyTag.d.ts +8 -0
- package/dist/types/model/enum/PropertyTag.d.ts.map +1 -1
- package/dist/types/model/json/BitJson.d.ts +4 -0
- package/dist/types/model/json/BitJson.d.ts.map +1 -1
- package/dist/types/parser/bitmark/peg/contentProcessors/DefaultTagContentProcessor.d.ts.map +1 -1
- package/dist/types/parser/bitmark/peg/contentProcessors/ExampleTagContentProcessor.d.ts.map +1 -1
- package/dist/types/parser/text/TextParser.d.ts +2 -2
- package/dist/types/parser/text/TextParser.d.ts.map +1 -1
- package/dist/types/utils/BitUtils.d.ts.map +1 -1
- package/package.json +1 -2
|
@@ -0,0 +1,302 @@
|
|
|
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
|
+
const DEF = {
|
|
11
|
+
format: BodyTextFormat.bitmarkPlusPlus,
|
|
12
|
+
location: TextLocation.body,
|
|
13
|
+
};
|
|
14
|
+
// -----------------------------------------------------------------------------
|
|
15
|
+
// ╭──────────────────────────────────────────────────────────────────────────╮
|
|
16
|
+
// │ 1. LOW‑LEVEL helpers │
|
|
17
|
+
// ╰──────────────────────────────────────────────────────────────────────────╯
|
|
18
|
+
// 1‑a) Trigger characters that start a bit tag construct when they follow "["
|
|
19
|
+
const TRIGGERS = new Set('.@#▼►%!?+-$_=&');
|
|
20
|
+
// 1‑b) Paired punctuation we have to split with a caret
|
|
21
|
+
const HALF_TAGS = new Set(['*', '`', '_', '!', '=']);
|
|
22
|
+
/**
|
|
23
|
+
* Predicate – true for every flavour that the spec calls “bitmark text”
|
|
24
|
+
*/
|
|
25
|
+
function isBitmarkText(fmt) {
|
|
26
|
+
// Only bitmarkPlusPlus is defined in TextFormat, so only check for that
|
|
27
|
+
return fmt === BodyTextFormat.bitmarkPlusPlus || fmt === 'bitmark+' || fmt === 'bitmark--';
|
|
28
|
+
}
|
|
29
|
+
// -----------------------------------------------------------------------------
|
|
30
|
+
// 1‑c) Single‑buffer worker (BREAKSCAPE)
|
|
31
|
+
// -----------------------------------------------------------------------------
|
|
32
|
+
function breakscapeBuf(src, fmt, loc) {
|
|
33
|
+
// If an unrecognized type is passed, return it as is (e.g. true, false, 0, 1, etc.)
|
|
34
|
+
if (!isString(src))
|
|
35
|
+
return src;
|
|
36
|
+
const bitmarkText = isBitmarkText(fmt);
|
|
37
|
+
const body = loc === TextLocation.body;
|
|
38
|
+
const inTag = loc === TextLocation.tag;
|
|
39
|
+
const len = src.length;
|
|
40
|
+
// Assume breakscaping will usually increas the length of the string by less than 20%
|
|
41
|
+
// we can allocate a buffer of that size as reallocation is expensive
|
|
42
|
+
const out = new Array(Math.ceil(len * 1.1)); // upper bound
|
|
43
|
+
let atLineStart = true;
|
|
44
|
+
let col = 0;
|
|
45
|
+
for (let i = 0; i < len;) {
|
|
46
|
+
const ch = src.charCodeAt(i); // number
|
|
47
|
+
const nxt = i + 1 < len ? src.charCodeAt(i + 1) : 0;
|
|
48
|
+
// 1) newline ----------------------------------------------------------
|
|
49
|
+
if (ch === 0x0a) {
|
|
50
|
+
// '\n'
|
|
51
|
+
out.push('\n');
|
|
52
|
+
atLineStart = true;
|
|
53
|
+
col = 0;
|
|
54
|
+
i++;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const space = ch === 0x20 || ch === 0x09; // ' ' or '\t'
|
|
58
|
+
const physicalBOC = col === 0; // zero indent
|
|
59
|
+
// 2) hats -------------------------------------------------------------
|
|
60
|
+
if (bitmarkText || inTag) {
|
|
61
|
+
if (ch === 0x5e) {
|
|
62
|
+
// '^'
|
|
63
|
+
let j = i + 1;
|
|
64
|
+
while (j < len && src.charCodeAt(j) === 0x5e)
|
|
65
|
+
j++;
|
|
66
|
+
out.push('^'); // extra one
|
|
67
|
+
out.push(src.slice(i, j)); // original run
|
|
68
|
+
col += j - i;
|
|
69
|
+
i = j;
|
|
70
|
+
atLineStart = false;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// 3) inline doubles ---------------------------------------------------
|
|
75
|
+
if (bitmarkText && HALF_TAGS.has(String.fromCharCode(ch))) {
|
|
76
|
+
out.push(String.fromCharCode(ch));
|
|
77
|
+
if (nxt === ch)
|
|
78
|
+
out.push('^');
|
|
79
|
+
i++;
|
|
80
|
+
col++;
|
|
81
|
+
atLineStart = false;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
// 4) end-of-tag -------------------------------------------------------
|
|
85
|
+
if (inTag && ch === 0x5d /* ']' */ && (i === 0 || src.charCodeAt(i - 1) !== 0x5e)) {
|
|
86
|
+
out.push('^', ']');
|
|
87
|
+
i++;
|
|
88
|
+
col++;
|
|
89
|
+
atLineStart = false;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
// 5) body-only rules --------------------------------------------------
|
|
93
|
+
if (body) {
|
|
94
|
+
// (a) ### | • at BOL
|
|
95
|
+
if (atLineStart && physicalBOC && bitmarkText && (ch === 0x23 || ch === 0x7c || ch === 0x2022)) {
|
|
96
|
+
let j = i;
|
|
97
|
+
while (j < len && src.charCodeAt(j) === ch)
|
|
98
|
+
j++;
|
|
99
|
+
out.push(src.slice(i, j));
|
|
100
|
+
if (nxt !== 0x5e)
|
|
101
|
+
out.push('^');
|
|
102
|
+
col += j - i;
|
|
103
|
+
i = j;
|
|
104
|
+
atLineStart = false;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
// (b) '[' + trigger
|
|
108
|
+
if (bitmarkText && ch === 0x5b /* '[' */ && TRIGGERS.has(String.fromCharCode(nxt))) {
|
|
109
|
+
out.push('[', '^');
|
|
110
|
+
i++;
|
|
111
|
+
col++;
|
|
112
|
+
atLineStart = false;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
// 6) plain-text "[." or "[^^... ." at BOL
|
|
117
|
+
if (!bitmarkText && body && atLineStart && physicalBOC && ch === 0x5b /* '[' */) {
|
|
118
|
+
// count carets after '['
|
|
119
|
+
let j = i + 1;
|
|
120
|
+
let count = 0;
|
|
121
|
+
while (j < len && src.charCodeAt(j) === 0x5e /* '^' */) {
|
|
122
|
+
count++;
|
|
123
|
+
j++;
|
|
124
|
+
}
|
|
125
|
+
// if next char is dot, escape by adding one more caret
|
|
126
|
+
if (j < len && src.charCodeAt(j) === 0x2e /* '.' */) {
|
|
127
|
+
out.push('[');
|
|
128
|
+
for (let k = 0; k < count + 1; k++)
|
|
129
|
+
out.push('^');
|
|
130
|
+
col += count + 1;
|
|
131
|
+
i = j; // skip '[' and all carets, next iteration handles '.'
|
|
132
|
+
atLineStart = false;
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// default copy --------------------------------------------------------
|
|
137
|
+
out.push(String.fromCharCode(ch));
|
|
138
|
+
if (!space)
|
|
139
|
+
atLineStart = false;
|
|
140
|
+
col++;
|
|
141
|
+
i++;
|
|
142
|
+
}
|
|
143
|
+
return out.join('');
|
|
144
|
+
}
|
|
145
|
+
// -----------------------------------------------------------------------------
|
|
146
|
+
// 1‑d) Single‑buffer worker (UNBREAKSCAPE)
|
|
147
|
+
// -----------------------------------------------------------------------------
|
|
148
|
+
function unbreakscapeBuf(src, fmt, loc) {
|
|
149
|
+
// If an unrecognized type is passed, return it as is (e.g. true, false, 0, 1, etc.)
|
|
150
|
+
if (!isString(src))
|
|
151
|
+
return src;
|
|
152
|
+
const bitmarkText = isBitmarkText(fmt);
|
|
153
|
+
const isTag = loc === TextLocation.tag;
|
|
154
|
+
const isPlainBody = loc === TextLocation.body && !bitmarkText;
|
|
155
|
+
const len = src.length;
|
|
156
|
+
const out = new Array(len); // upper bound
|
|
157
|
+
let outPos = 0;
|
|
158
|
+
let bol = true; // beginning-of-line flag
|
|
159
|
+
for (let i = 0; i < len;) {
|
|
160
|
+
const ch = src[i];
|
|
161
|
+
// 1) HATS – remove exactly one ^ from each run
|
|
162
|
+
if ((bitmarkText || isTag) && ch === '^') {
|
|
163
|
+
let j = i + 1;
|
|
164
|
+
while (j < len && src[j] === '^')
|
|
165
|
+
j++;
|
|
166
|
+
if (j - i > 1)
|
|
167
|
+
out[outPos++] = src.slice(i + 1, j); // keep the rest
|
|
168
|
+
i = j;
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
// 2) PLAIN-body “[ ^ .” with zero indent
|
|
172
|
+
if (isPlainBody && bol && ch === '[') {
|
|
173
|
+
let j = i + 1;
|
|
174
|
+
let count = 0;
|
|
175
|
+
while (j < len && src[j] === '^') {
|
|
176
|
+
count++;
|
|
177
|
+
j++;
|
|
178
|
+
}
|
|
179
|
+
if (count >= 1 && j < len && src[j] === '.') {
|
|
180
|
+
out[outPos++] = '[';
|
|
181
|
+
for (let k = 0; k < count - 1; k++)
|
|
182
|
+
out[outPos++] = '^';
|
|
183
|
+
out[outPos++] = '.';
|
|
184
|
+
i = j + 1;
|
|
185
|
+
bol = false;
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
// 3) default copy
|
|
190
|
+
out[outPos++] = ch;
|
|
191
|
+
i++;
|
|
192
|
+
// keep bol up to date
|
|
193
|
+
if (ch === '\n')
|
|
194
|
+
bol = true;
|
|
195
|
+
else if (bol && ch !== ' ' && ch !== '\t')
|
|
196
|
+
bol = false;
|
|
197
|
+
}
|
|
198
|
+
return out.slice(0, outPos).join('');
|
|
199
|
+
}
|
|
200
|
+
// -----------------------------------------------------------------------------
|
|
201
|
+
// ╭──────────────────────────────────────────────────────────────────────────╮
|
|
202
|
+
// │ 2. PUBLIC API │
|
|
203
|
+
// ╰──────────────────────────────────────────────────────────────────────────╯
|
|
204
|
+
function isString(x) {
|
|
205
|
+
return typeof x === 'string' || x instanceof String;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Main class for performing breakscape and unbreakscape operations on bitmark text.
|
|
209
|
+
*
|
|
210
|
+
* Breakscaping is the process of escaping special characters in bitmark text to prevent
|
|
211
|
+
* them from being interpreted as markup. This includes adding caret (^) characters before
|
|
212
|
+
* special characters that would otherwise be interpreted as bitmark syntax.
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```typescript
|
|
216
|
+
* const breakscape = new Breakscape();
|
|
217
|
+
*
|
|
218
|
+
* // Breakscape a string
|
|
219
|
+
* const escaped = breakscape.breakscape('[.hello]');
|
|
220
|
+
*
|
|
221
|
+
* // Unbreakscape a string
|
|
222
|
+
* const unescaped = breakscape.unbreakscape('[^.hello]');
|
|
223
|
+
*
|
|
224
|
+
* // Process arrays
|
|
225
|
+
* const escapedArray = breakscape.breakscape(['[.hello]', '[.world]']);
|
|
226
|
+
* ```
|
|
227
|
+
*
|
|
228
|
+
* @public
|
|
229
|
+
*/
|
|
230
|
+
class Breakscape {
|
|
231
|
+
breakscape(val, opts = {}) {
|
|
232
|
+
const { format: fmt, location: loc } = Object.assign(Object.assign({}, DEF), opts);
|
|
233
|
+
if (val == null)
|
|
234
|
+
return undefined;
|
|
235
|
+
const proc = (s) => breakscapeBuf(s, fmt, loc);
|
|
236
|
+
if (Array.isArray(val)) {
|
|
237
|
+
const a = opts.inPlaceArray ? val : [...val];
|
|
238
|
+
for (let i = 0; i < a.length; i++)
|
|
239
|
+
if (isString(a[i]))
|
|
240
|
+
a[i] = proc(a[i]);
|
|
241
|
+
return a;
|
|
242
|
+
}
|
|
243
|
+
return proc(val);
|
|
244
|
+
}
|
|
245
|
+
unbreakscape(val, opts = {}) {
|
|
246
|
+
const { format: fmt, location: loc } = Object.assign(Object.assign({}, DEF), opts);
|
|
247
|
+
if (val == null)
|
|
248
|
+
return undefined;
|
|
249
|
+
const proc = (s) => unbreakscapeBuf(s, fmt, loc);
|
|
250
|
+
if (Array.isArray(val)) {
|
|
251
|
+
const a = opts.inPlaceArray ? val : [...val];
|
|
252
|
+
for (let i = 0; i < a.length; i++)
|
|
253
|
+
if (isString(a[i]))
|
|
254
|
+
a[i] = proc(a[i]);
|
|
255
|
+
return a;
|
|
256
|
+
}
|
|
257
|
+
return proc(val);
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Breakscape a code string or an array of code strings.
|
|
261
|
+
* If the input is an array, a new array will be returned.
|
|
262
|
+
*
|
|
263
|
+
* @param val input value
|
|
264
|
+
* @param modifyArray if true, the original array will be modified rather than a copy being made
|
|
265
|
+
* @returns the input value with any strings breakscaped
|
|
266
|
+
*/
|
|
267
|
+
breakscapeCode(_val, _options) {
|
|
268
|
+
_val; // to avoid unused variable warning
|
|
269
|
+
_options; // to avoid unused variable warning
|
|
270
|
+
throw new Error('breakscapeCode is not implemented.');
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Gets the version of the breakscape library.
|
|
274
|
+
*
|
|
275
|
+
* @returns The current version string of the library.
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* ```typescript
|
|
279
|
+
* const breakscape = new Breakscape();
|
|
280
|
+
* console.log(breakscape.version()); // e.g., "1.0.0"
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
version() {
|
|
284
|
+
return buildInfo.version;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Gets the license information for the breakscape library.
|
|
288
|
+
*
|
|
289
|
+
* @returns The license string for the library.
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* ```typescript
|
|
293
|
+
* const breakscape = new Breakscape();
|
|
294
|
+
* console.log(breakscape.license()); // e.g., "MIT"
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
license() {
|
|
298
|
+
return buildInfo.license;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
export { Breakscape };
|
|
302
|
+
//# sourceMappingURL=BreakscapeLoop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BreakscapeLoop.js","sourceRoot":"","sources":["../../../src/breakscaping/BreakscapeLoop.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,cAAc,EAA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AAU,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BreakscapeOptions.js","sourceRoot":"","sources":["../../../src/breakscaping/BreakscapeOptions.ts"],"names":[],"mappings":""}
|
|
@@ -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,EAAE,CAAC;gBACP,OAAO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
@@ -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,MAAM,EAAE,CAAC;AAC3H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,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"}
|
|
@@ -606,6 +606,24 @@ const BITS = {
|
|
|
606
606
|
[BitType.conversationRight1]: { since: '1.3.0', baseBitType: BitType.conversationLeft1 },
|
|
607
607
|
[BitType.conversationRight1Scream]: { since: '1.3.0', baseBitType: BitType.conversationLeft1 },
|
|
608
608
|
[BitType.conversationRight1Thought]: { since: '1.3.0', baseBitType: BitType.conversationLeft1 },
|
|
609
|
+
[BitType.clozeAndMultipleChoiceTextConversationLeft1]: { since: '1.3.0', baseBitType: BitType.conversationLeft1 },
|
|
610
|
+
[BitType.clozeAndMultipleChoiceTextConversationLeft1Scream]: {
|
|
611
|
+
since: '1.3.0',
|
|
612
|
+
baseBitType: BitType.conversationLeft1,
|
|
613
|
+
},
|
|
614
|
+
[BitType.clozeAndMultipleChoiceTextConversationLeft1Thought]: {
|
|
615
|
+
since: '1.3.0',
|
|
616
|
+
baseBitType: BitType.conversationLeft1,
|
|
617
|
+
},
|
|
618
|
+
[BitType.clozeAndMultipleChoiceTextConversationRight1]: { since: '1.3.0', baseBitType: BitType.conversationLeft1 },
|
|
619
|
+
[BitType.clozeAndMultipleChoiceTextConversationRight1Scream]: {
|
|
620
|
+
since: '1.3.0',
|
|
621
|
+
baseBitType: BitType.conversationLeft1,
|
|
622
|
+
},
|
|
623
|
+
[BitType.clozeAndMultipleChoiceTextConversationRight1Thought]: {
|
|
624
|
+
since: '1.3.0',
|
|
625
|
+
baseBitType: BitType.conversationLeft1,
|
|
626
|
+
},
|
|
609
627
|
[BitType.cookPreparation]: { since: '1.3.0', baseBitType: BitType.article },
|
|
610
628
|
[BitType.cookStep]: { since: '1.3.0', baseBitType: BitType.article },
|
|
611
629
|
[BitType.cookIngredients]: {
|
|
@@ -1509,6 +1527,7 @@ const BITS = {
|
|
|
1509
1527
|
},
|
|
1510
1528
|
],
|
|
1511
1529
|
},
|
|
1530
|
+
[BitType.leMultiDayEvent]: { since: '3.32.0', baseBitType: BitType.leClassroomEvent },
|
|
1512
1531
|
[BitType.leCompletion]: {
|
|
1513
1532
|
since: '1.25.0',
|
|
1514
1533
|
baseBitType: BitType.learningPathClosing,
|
|
@@ -2275,6 +2294,25 @@ const BITS = {
|
|
|
2275
2294
|
configKey: PropertyConfigKey.tocResource,
|
|
2276
2295
|
maxCount: Count.infinity,
|
|
2277
2296
|
},
|
|
2297
|
+
{
|
|
2298
|
+
type: BitTagType.property,
|
|
2299
|
+
configKey: PropertyConfigKey.buttonCaption,
|
|
2300
|
+
},
|
|
2301
|
+
],
|
|
2302
|
+
},
|
|
2303
|
+
[BitType.tocContent]: {
|
|
2304
|
+
since: '3.31.0',
|
|
2305
|
+
baseBitType: BitType.toc,
|
|
2306
|
+
tags: [
|
|
2307
|
+
{
|
|
2308
|
+
type: BitTagType.property,
|
|
2309
|
+
configKey: PropertyConfigKey.tocContent,
|
|
2310
|
+
maxCount: Count.infinity,
|
|
2311
|
+
},
|
|
2312
|
+
{
|
|
2313
|
+
type: BitTagType.property,
|
|
2314
|
+
configKey: PropertyConfigKey.buttonCaption,
|
|
2315
|
+
},
|
|
2278
2316
|
],
|
|
2279
2317
|
},
|
|
2280
2318
|
[BitType.anchor]: { since: '1.3.0', baseBitType: BitType._standard },
|