@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,305 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* breakscape.ts
|
|
4
|
+
* ------------------------------------------------------------
|
|
5
|
+
* Breakscaping for bitmark text.
|
|
6
|
+
* (c) 2025 — MIT / public domain
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.Breakscape = void 0;
|
|
10
|
+
const build_info_1 = require("../generated/build-info");
|
|
11
|
+
const BodyTextFormat_1 = require("../model/enum/BodyTextFormat");
|
|
12
|
+
const TextLocation_1 = require("../model/enum/TextLocation");
|
|
13
|
+
const DEF = {
|
|
14
|
+
format: BodyTextFormat_1.BodyTextFormat.bitmarkPlusPlus,
|
|
15
|
+
location: TextLocation_1.TextLocation.body,
|
|
16
|
+
};
|
|
17
|
+
// -----------------------------------------------------------------------------
|
|
18
|
+
// ╭──────────────────────────────────────────────────────────────────────────╮
|
|
19
|
+
// │ 1. LOW‑LEVEL helpers │
|
|
20
|
+
// ╰──────────────────────────────────────────────────────────────────────────╯
|
|
21
|
+
// 1‑a) Trigger characters that start a bit tag construct when they follow "["
|
|
22
|
+
const TRIGGERS = new Set('.@#▼►%!?+-$_=&');
|
|
23
|
+
// 1‑b) Paired punctuation we have to split with a caret
|
|
24
|
+
const HALF_TAGS = new Set(['*', '`', '_', '!', '=']);
|
|
25
|
+
/**
|
|
26
|
+
* Predicate – true for every flavour that the spec calls “bitmark text”
|
|
27
|
+
*/
|
|
28
|
+
function isBitmarkText(fmt) {
|
|
29
|
+
// Only bitmarkPlusPlus is defined in TextFormat, so only check for that
|
|
30
|
+
return fmt === BodyTextFormat_1.BodyTextFormat.bitmarkPlusPlus || fmt === 'bitmark+' || fmt === 'bitmark--';
|
|
31
|
+
}
|
|
32
|
+
// -----------------------------------------------------------------------------
|
|
33
|
+
// 1‑c) Single‑buffer worker (BREAKSCAPE)
|
|
34
|
+
// -----------------------------------------------------------------------------
|
|
35
|
+
function breakscapeBuf(src, fmt, loc) {
|
|
36
|
+
// If an unrecognized type is passed, return it as is (e.g. true, false, 0, 1, etc.)
|
|
37
|
+
if (!isString(src))
|
|
38
|
+
return src;
|
|
39
|
+
const bitmarkText = isBitmarkText(fmt);
|
|
40
|
+
const body = loc === TextLocation_1.TextLocation.body;
|
|
41
|
+
const inTag = loc === TextLocation_1.TextLocation.tag;
|
|
42
|
+
const len = src.length;
|
|
43
|
+
// Assume breakscaping will usually increas the length of the string by less than 20%
|
|
44
|
+
// we can allocate a buffer of that size as reallocation is expensive
|
|
45
|
+
const out = new Array(Math.ceil(len * 1.1)); // upper bound
|
|
46
|
+
let atLineStart = true;
|
|
47
|
+
let col = 0;
|
|
48
|
+
for (let i = 0; i < len;) {
|
|
49
|
+
const ch = src.charCodeAt(i); // number
|
|
50
|
+
const nxt = i + 1 < len ? src.charCodeAt(i + 1) : 0;
|
|
51
|
+
// 1) newline ----------------------------------------------------------
|
|
52
|
+
if (ch === 0x0a) {
|
|
53
|
+
// '\n'
|
|
54
|
+
out.push('\n');
|
|
55
|
+
atLineStart = true;
|
|
56
|
+
col = 0;
|
|
57
|
+
i++;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const space = ch === 0x20 || ch === 0x09; // ' ' or '\t'
|
|
61
|
+
const physicalBOC = col === 0; // zero indent
|
|
62
|
+
// 2) hats -------------------------------------------------------------
|
|
63
|
+
if (bitmarkText || inTag) {
|
|
64
|
+
if (ch === 0x5e) {
|
|
65
|
+
// '^'
|
|
66
|
+
let j = i + 1;
|
|
67
|
+
while (j < len && src.charCodeAt(j) === 0x5e)
|
|
68
|
+
j++;
|
|
69
|
+
out.push('^'); // extra one
|
|
70
|
+
out.push(src.slice(i, j)); // original run
|
|
71
|
+
col += j - i;
|
|
72
|
+
i = j;
|
|
73
|
+
atLineStart = false;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// 3) inline doubles ---------------------------------------------------
|
|
78
|
+
if (bitmarkText && HALF_TAGS.has(String.fromCharCode(ch))) {
|
|
79
|
+
out.push(String.fromCharCode(ch));
|
|
80
|
+
if (nxt === ch)
|
|
81
|
+
out.push('^');
|
|
82
|
+
i++;
|
|
83
|
+
col++;
|
|
84
|
+
atLineStart = false;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
// 4) end-of-tag -------------------------------------------------------
|
|
88
|
+
if (inTag && ch === 0x5d /* ']' */ && (i === 0 || src.charCodeAt(i - 1) !== 0x5e)) {
|
|
89
|
+
out.push('^', ']');
|
|
90
|
+
i++;
|
|
91
|
+
col++;
|
|
92
|
+
atLineStart = false;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
// 5) body-only rules --------------------------------------------------
|
|
96
|
+
if (body) {
|
|
97
|
+
// (a) ### | • at BOL
|
|
98
|
+
if (atLineStart && physicalBOC && bitmarkText && (ch === 0x23 || ch === 0x7c || ch === 0x2022)) {
|
|
99
|
+
let j = i;
|
|
100
|
+
while (j < len && src.charCodeAt(j) === ch)
|
|
101
|
+
j++;
|
|
102
|
+
out.push(src.slice(i, j));
|
|
103
|
+
if (nxt !== 0x5e)
|
|
104
|
+
out.push('^');
|
|
105
|
+
col += j - i;
|
|
106
|
+
i = j;
|
|
107
|
+
atLineStart = false;
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
// (b) '[' + trigger
|
|
111
|
+
if (bitmarkText && ch === 0x5b /* '[' */ && TRIGGERS.has(String.fromCharCode(nxt))) {
|
|
112
|
+
out.push('[', '^');
|
|
113
|
+
i++;
|
|
114
|
+
col++;
|
|
115
|
+
atLineStart = false;
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// 6) plain-text "[." or "[^^... ." at BOL
|
|
120
|
+
if (!bitmarkText && body && atLineStart && physicalBOC && ch === 0x5b /* '[' */) {
|
|
121
|
+
// count carets after '['
|
|
122
|
+
let j = i + 1;
|
|
123
|
+
let count = 0;
|
|
124
|
+
while (j < len && src.charCodeAt(j) === 0x5e /* '^' */) {
|
|
125
|
+
count++;
|
|
126
|
+
j++;
|
|
127
|
+
}
|
|
128
|
+
// if next char is dot, escape by adding one more caret
|
|
129
|
+
if (j < len && src.charCodeAt(j) === 0x2e /* '.' */) {
|
|
130
|
+
out.push('[');
|
|
131
|
+
for (let k = 0; k < count + 1; k++)
|
|
132
|
+
out.push('^');
|
|
133
|
+
col += count + 1;
|
|
134
|
+
i = j; // skip '[' and all carets, next iteration handles '.'
|
|
135
|
+
atLineStart = false;
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
// default copy --------------------------------------------------------
|
|
140
|
+
out.push(String.fromCharCode(ch));
|
|
141
|
+
if (!space)
|
|
142
|
+
atLineStart = false;
|
|
143
|
+
col++;
|
|
144
|
+
i++;
|
|
145
|
+
}
|
|
146
|
+
return out.join('');
|
|
147
|
+
}
|
|
148
|
+
// -----------------------------------------------------------------------------
|
|
149
|
+
// 1‑d) Single‑buffer worker (UNBREAKSCAPE)
|
|
150
|
+
// -----------------------------------------------------------------------------
|
|
151
|
+
function unbreakscapeBuf(src, fmt, loc) {
|
|
152
|
+
// If an unrecognized type is passed, return it as is (e.g. true, false, 0, 1, etc.)
|
|
153
|
+
if (!isString(src))
|
|
154
|
+
return src;
|
|
155
|
+
const bitmarkText = isBitmarkText(fmt);
|
|
156
|
+
const isTag = loc === TextLocation_1.TextLocation.tag;
|
|
157
|
+
const isPlainBody = loc === TextLocation_1.TextLocation.body && !bitmarkText;
|
|
158
|
+
const len = src.length;
|
|
159
|
+
const out = new Array(len); // upper bound
|
|
160
|
+
let outPos = 0;
|
|
161
|
+
let bol = true; // beginning-of-line flag
|
|
162
|
+
for (let i = 0; i < len;) {
|
|
163
|
+
const ch = src[i];
|
|
164
|
+
// 1) HATS – remove exactly one ^ from each run
|
|
165
|
+
if ((bitmarkText || isTag) && ch === '^') {
|
|
166
|
+
let j = i + 1;
|
|
167
|
+
while (j < len && src[j] === '^')
|
|
168
|
+
j++;
|
|
169
|
+
if (j - i > 1)
|
|
170
|
+
out[outPos++] = src.slice(i + 1, j); // keep the rest
|
|
171
|
+
i = j;
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
// 2) PLAIN-body “[ ^ .” with zero indent
|
|
175
|
+
if (isPlainBody && bol && ch === '[') {
|
|
176
|
+
let j = i + 1;
|
|
177
|
+
let count = 0;
|
|
178
|
+
while (j < len && src[j] === '^') {
|
|
179
|
+
count++;
|
|
180
|
+
j++;
|
|
181
|
+
}
|
|
182
|
+
if (count >= 1 && j < len && src[j] === '.') {
|
|
183
|
+
out[outPos++] = '[';
|
|
184
|
+
for (let k = 0; k < count - 1; k++)
|
|
185
|
+
out[outPos++] = '^';
|
|
186
|
+
out[outPos++] = '.';
|
|
187
|
+
i = j + 1;
|
|
188
|
+
bol = false;
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
// 3) default copy
|
|
193
|
+
out[outPos++] = ch;
|
|
194
|
+
i++;
|
|
195
|
+
// keep bol up to date
|
|
196
|
+
if (ch === '\n')
|
|
197
|
+
bol = true;
|
|
198
|
+
else if (bol && ch !== ' ' && ch !== '\t')
|
|
199
|
+
bol = false;
|
|
200
|
+
}
|
|
201
|
+
return out.slice(0, outPos).join('');
|
|
202
|
+
}
|
|
203
|
+
// -----------------------------------------------------------------------------
|
|
204
|
+
// ╭──────────────────────────────────────────────────────────────────────────╮
|
|
205
|
+
// │ 2. PUBLIC API │
|
|
206
|
+
// ╰──────────────────────────────────────────────────────────────────────────╯
|
|
207
|
+
function isString(x) {
|
|
208
|
+
return typeof x === 'string' || x instanceof String;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Main class for performing breakscape and unbreakscape operations on bitmark text.
|
|
212
|
+
*
|
|
213
|
+
* Breakscaping is the process of escaping special characters in bitmark text to prevent
|
|
214
|
+
* them from being interpreted as markup. This includes adding caret (^) characters before
|
|
215
|
+
* special characters that would otherwise be interpreted as bitmark syntax.
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* ```typescript
|
|
219
|
+
* const breakscape = new Breakscape();
|
|
220
|
+
*
|
|
221
|
+
* // Breakscape a string
|
|
222
|
+
* const escaped = breakscape.breakscape('[.hello]');
|
|
223
|
+
*
|
|
224
|
+
* // Unbreakscape a string
|
|
225
|
+
* const unescaped = breakscape.unbreakscape('[^.hello]');
|
|
226
|
+
*
|
|
227
|
+
* // Process arrays
|
|
228
|
+
* const escapedArray = breakscape.breakscape(['[.hello]', '[.world]']);
|
|
229
|
+
* ```
|
|
230
|
+
*
|
|
231
|
+
* @public
|
|
232
|
+
*/
|
|
233
|
+
class Breakscape {
|
|
234
|
+
breakscape(val, opts = {}) {
|
|
235
|
+
const { format: fmt, location: loc } = Object.assign(Object.assign({}, DEF), opts);
|
|
236
|
+
if (val == null)
|
|
237
|
+
return undefined;
|
|
238
|
+
const proc = (s) => breakscapeBuf(s, fmt, loc);
|
|
239
|
+
if (Array.isArray(val)) {
|
|
240
|
+
const a = opts.inPlaceArray ? val : [...val];
|
|
241
|
+
for (let i = 0; i < a.length; i++)
|
|
242
|
+
if (isString(a[i]))
|
|
243
|
+
a[i] = proc(a[i]);
|
|
244
|
+
return a;
|
|
245
|
+
}
|
|
246
|
+
return proc(val);
|
|
247
|
+
}
|
|
248
|
+
unbreakscape(val, opts = {}) {
|
|
249
|
+
const { format: fmt, location: loc } = Object.assign(Object.assign({}, DEF), opts);
|
|
250
|
+
if (val == null)
|
|
251
|
+
return undefined;
|
|
252
|
+
const proc = (s) => unbreakscapeBuf(s, fmt, loc);
|
|
253
|
+
if (Array.isArray(val)) {
|
|
254
|
+
const a = opts.inPlaceArray ? val : [...val];
|
|
255
|
+
for (let i = 0; i < a.length; i++)
|
|
256
|
+
if (isString(a[i]))
|
|
257
|
+
a[i] = proc(a[i]);
|
|
258
|
+
return a;
|
|
259
|
+
}
|
|
260
|
+
return proc(val);
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Breakscape a code string or an array of code strings.
|
|
264
|
+
* If the input is an array, a new array will be returned.
|
|
265
|
+
*
|
|
266
|
+
* @param val input value
|
|
267
|
+
* @param modifyArray if true, the original array will be modified rather than a copy being made
|
|
268
|
+
* @returns the input value with any strings breakscaped
|
|
269
|
+
*/
|
|
270
|
+
breakscapeCode(_val, _options) {
|
|
271
|
+
_val; // to avoid unused variable warning
|
|
272
|
+
_options; // to avoid unused variable warning
|
|
273
|
+
throw new Error('breakscapeCode is not implemented.');
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Gets the version of the breakscape library.
|
|
277
|
+
*
|
|
278
|
+
* @returns The current version string of the library.
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* ```typescript
|
|
282
|
+
* const breakscape = new Breakscape();
|
|
283
|
+
* console.log(breakscape.version()); // e.g., "1.0.0"
|
|
284
|
+
* ```
|
|
285
|
+
*/
|
|
286
|
+
version() {
|
|
287
|
+
return build_info_1.buildInfo.version;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Gets the license information for the breakscape library.
|
|
291
|
+
*
|
|
292
|
+
* @returns The license string for the library.
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
* ```typescript
|
|
296
|
+
* const breakscape = new Breakscape();
|
|
297
|
+
* console.log(breakscape.license()); // e.g., "MIT"
|
|
298
|
+
* ```
|
|
299
|
+
*/
|
|
300
|
+
license() {
|
|
301
|
+
return build_info_1.buildInfo.license;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
exports.Breakscape = Breakscape;
|
|
305
|
+
//# sourceMappingURL=BreakscapeLoop.js.map
|
|
@@ -0,0 +1 @@
|
|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;;;;OAUG;IACH,OAAO;QACL,OAAO,sBAAS,CAAC,OAAO,CAAC;IAC3B,CAAC;CACF;AAEQ,gCAAU"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BreakscapeOptions.js","sourceRoot":"","sources":["../../../src/breakscaping/BreakscapeOptions.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* breakscape.ts
|
|
4
|
+
* ------------------------------------------------------------
|
|
5
|
+
* Breakscaping for bitmark text.
|
|
6
|
+
* (c) 2025 — MIT / public domain
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.Breakscape = void 0;
|
|
43
|
+
const build_info_1 = require("../generated/build-info");
|
|
44
|
+
const BodyTextFormat_1 = require("../model/enum/BodyTextFormat");
|
|
45
|
+
const TextLocation_1 = require("../model/enum/TextLocation");
|
|
46
|
+
const RC = __importStar(require("./RegexConfigs"));
|
|
47
|
+
// default options
|
|
48
|
+
const DEF = {
|
|
49
|
+
format: BodyTextFormat_1.BodyTextFormat.bitmarkPlusPlus,
|
|
50
|
+
location: TextLocation_1.TextLocation.body,
|
|
51
|
+
v2: false,
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Check if an object is a string.
|
|
55
|
+
*
|
|
56
|
+
* @param obj - The object to check.
|
|
57
|
+
* @returns true if the object is a string, otherwise false.
|
|
58
|
+
*/
|
|
59
|
+
function isString(obj) {
|
|
60
|
+
return typeof obj === 'string' || obj instanceof String;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* For breakscaping, select the correct regex and replacer for the text format, location, and v2 flag.
|
|
64
|
+
*/
|
|
65
|
+
function selectBreakscapeRegexAndReplacer(textFormat, textLocation, v2 = false) {
|
|
66
|
+
if (textLocation === TextLocation_1.TextLocation.tag) {
|
|
67
|
+
if (!v2 && textFormat === BodyTextFormat_1.BodyTextFormat.bitmarkPlusPlus) {
|
|
68
|
+
return {
|
|
69
|
+
regex: RC.BREAKSCAPE_BITMARK_TAG_REGEX,
|
|
70
|
+
replacer: RC.BREAKSCAPE_BITMARK_TAG_REGEX_REPLACER,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
regex: RC.BREAKSCAPE_PLAIN_TAG_REGEX,
|
|
75
|
+
replacer: RC.BREAKSCAPE_PLAIN_TAG_REGEX_REPLACER,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
if (textFormat === BodyTextFormat_1.BodyTextFormat.bitmarkPlusPlus) {
|
|
80
|
+
if (v2) {
|
|
81
|
+
return {
|
|
82
|
+
regex: RC.BREAKSCAPE_V2_BODY_REGEX,
|
|
83
|
+
replacer: RC.BREAKSCAPE_V2_BODY_REGEX_REPLACER,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
regex: RC.BREAKSCAPE_BITMARK_BODY_REGEX,
|
|
88
|
+
replacer: RC.BREAKSCAPE_BITMARK_BODY_REGEX_REPLACER,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
regex: RC.BREAKSCAPE_PLAIN_BODY_REGEX,
|
|
93
|
+
replacer: RC.BREAKSCAPE_PLAIN_BODY_REGEX_REPLACER,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* For unbreakscaping, select the correct regex and replacer for the text format and location.
|
|
99
|
+
*/
|
|
100
|
+
function selectUnbreakscapeRegexAndReplacer(textFormat, textLocation) {
|
|
101
|
+
const isPlain = textFormat !== BodyTextFormat_1.BodyTextFormat.bitmarkPlusPlus;
|
|
102
|
+
if (textLocation === TextLocation_1.TextLocation.body && isPlain) {
|
|
103
|
+
return {
|
|
104
|
+
regex: RC.UNBREAKSCAPE_PLAIN_IN_BODY_REGEX,
|
|
105
|
+
replacer: RC.UNBREAKSCAPE_PLAIN_IN_BODY_REGEX_REPLACER,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
regex: RC.UNBREAKSCAPE_REGEX,
|
|
110
|
+
replacer: RC.UNBREAKSCAPE_REGEX_REPLACER,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
// -----------------------------------------------------------------------------
|
|
114
|
+
// ╭──────────────────────────────────────────────────────────────────────────╮
|
|
115
|
+
// │ 2. PUBLIC API │
|
|
116
|
+
// ╰──────────────────────────────────────────────────────────────────────────╯
|
|
117
|
+
class Breakscape {
|
|
118
|
+
constructor() {
|
|
119
|
+
this.EMPTY_STRING = '';
|
|
120
|
+
}
|
|
121
|
+
breakscape(val, opts = {}) {
|
|
122
|
+
if (val == null)
|
|
123
|
+
return undefined;
|
|
124
|
+
const options = Object.assign({}, DEF, opts);
|
|
125
|
+
if (Array.isArray(val)) {
|
|
126
|
+
return val.map((v) => this.breakscape(v, options));
|
|
127
|
+
}
|
|
128
|
+
// If an unrecognized type is passed, return it as is (e.g. true, false, 0, 1, etc.)
|
|
129
|
+
if (!isString(val))
|
|
130
|
+
return val;
|
|
131
|
+
const { regex, replacer } = selectBreakscapeRegexAndReplacer(options.format, options.location, options.v2);
|
|
132
|
+
let str = val;
|
|
133
|
+
str = str.replace(regex, replacer);
|
|
134
|
+
return str;
|
|
135
|
+
}
|
|
136
|
+
unbreakscape(val, opts = {}) {
|
|
137
|
+
if (val == null)
|
|
138
|
+
return undefined;
|
|
139
|
+
const options = Object.assign({}, DEF, opts);
|
|
140
|
+
if (Array.isArray(val)) {
|
|
141
|
+
return val.map((v) => this.unbreakscape(v, options));
|
|
142
|
+
}
|
|
143
|
+
// If an unrecognized type is passed, return it as is (e.g. true, false, 0, 1, etc.)
|
|
144
|
+
if (!isString(val))
|
|
145
|
+
return val;
|
|
146
|
+
const { regex, replacer } = selectUnbreakscapeRegexAndReplacer(options.format, options.location);
|
|
147
|
+
let str = val;
|
|
148
|
+
str = str.replace(regex, replacer);
|
|
149
|
+
return str;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Breakscape a code string or an array of code strings.
|
|
153
|
+
* If the input is an array, a new array will be returned.
|
|
154
|
+
*
|
|
155
|
+
* @param val input value
|
|
156
|
+
* @param modifyArray if true, the original array will be modified rather than a copy being made
|
|
157
|
+
* @returns the input value with any strings breakscaped
|
|
158
|
+
*/
|
|
159
|
+
breakscapeCode(val, options) {
|
|
160
|
+
if (val == null)
|
|
161
|
+
return val;
|
|
162
|
+
const opts = Object.assign({}, DEF, options);
|
|
163
|
+
const breakscapeStr = (str) => {
|
|
164
|
+
if (!str)
|
|
165
|
+
return str;
|
|
166
|
+
return str.replace(RC.BREAKSCAPE_CODE_REGEX, RC.BREAKSCAPE_CODE_REGEX_REPLACER);
|
|
167
|
+
};
|
|
168
|
+
if (Array.isArray(val)) {
|
|
169
|
+
const newVal = opts.inPlaceArray ? val : [val.length];
|
|
170
|
+
for (let i = 0, len = val.length; i < len; i++) {
|
|
171
|
+
const v = val[i];
|
|
172
|
+
if (isString(v)) {
|
|
173
|
+
val[i] = breakscapeStr(v);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
val = newVal;
|
|
177
|
+
}
|
|
178
|
+
else if (isString(val)) {
|
|
179
|
+
val = breakscapeStr(val);
|
|
180
|
+
}
|
|
181
|
+
return val;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Gets the version of the breakscape library.
|
|
185
|
+
*
|
|
186
|
+
* @returns The current version string of the library.
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```typescript
|
|
190
|
+
* const breakscape = new Breakscape();
|
|
191
|
+
* console.log(breakscape.version()); // e.g., "1.0.0"
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
version() {
|
|
195
|
+
return build_info_1.buildInfo.version;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Gets the license information for the breakscape library.
|
|
199
|
+
*
|
|
200
|
+
* @returns The license string for the library.
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```typescript
|
|
204
|
+
* const breakscape = new Breakscape();
|
|
205
|
+
* console.log(breakscape.license()); // e.g., "MIT"
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
license() {
|
|
209
|
+
return build_info_1.buildInfo.license;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
exports.Breakscape = Breakscape;
|
|
213
|
+
//# sourceMappingURL=BreakscapeRegex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BreakscapeRegex.js","sourceRoot":"","sources":["../../../src/breakscaping/BreakscapeRegex.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,wDAAoD;AACpD,iEAAkF;AAClF,6DAA4E;AAG5E,mDAAqC;AAErC,kBAAkB;AAClB,MAAM,GAAG,GAAG;IACV,MAAM,EAAE,+BAAc,CAAC,eAAe;IACtC,QAAQ,EAAE,2BAAY,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,2BAAY,CAAC,GAAG,EAAE,CAAC;QACtC,IAAI,CAAC,EAAE,IAAI,UAAU,KAAK,+BAAc,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,+BAAc,CAAC,eAAe,EAAE,CAAC;YAClD,IAAI,EAAE,EAA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|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Centralized regex and replacer constants for breakscape and unbreakscape.
|
|
4
|
+
* Extracted from breakscape-regex.ts to simplify core logic.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.BREAKSCAPE_CODE_REGEX_REPLACER = exports.BREAKSCAPE_CODE_REGEX = exports.UNBREAKSCAPE_PLAIN_IN_BODY_REGEX_REPLACER = exports.UNBREAKSCAPE_PLAIN_IN_BODY_REGEX = exports.UNBREAKSCAPE_REGEX_REPLACER = exports.UNBREAKSCAPE_REGEX = exports.BREAKSCAPE_V2_BODY_REGEX_REPLACER = exports.BREAKSCAPE_V2_BODY_REGEX = exports.BREAKSCAPE_PLAIN_BODY_REGEX_REPLACER = exports.BREAKSCAPE_PLAIN_BODY_REGEX = exports.BREAKSCAPE_BITMARK_BODY_REGEX_REPLACER = exports.BREAKSCAPE_BITMARK_BODY_REGEX = exports.BREAKSCAPE_PLAIN_TAG_REGEX_REPLACER = exports.BREAKSCAPE_PLAIN_TAG_REGEX = exports.BREAKSCAPE_BITMARK_TAG_REGEX_REPLACER = exports.BREAKSCAPE_BITMARK_TAG_REGEX = exports.BREAKSCAPE_PLAIN_BODY_REGEX_SOURCE = exports.BREAKSCAPE_BITMARK_BODY_REGEX_SOURCE = exports.BREAKSCAPE_PLAIN_TAG_REGEX_SOURCE = exports.BREAKSCAPE_BITMARK_TAG_REGEX_SOURCE = exports.REGEX_HATS = exports.REGEX_BIT_START = exports.REGEX_END_OF_TAG = exports.REGEX_PLAIN_TEXT_DIVIDER = exports.REGEX_FOOTER_DIVIDER = exports.REGEX_START_OF_TAG = exports.REGEX_LIST_BLOCKS = exports.REGEX_TITLE_BLOCKS = exports.REGEX_BLOCKS = exports.REGEX_MARKS = void 0;
|
|
8
|
+
exports.REGEX_MARKS = /([*`_!=])(?=\1)/; // BM_TAG: $1^ --BODY: $1^ ++BODY: $1^
|
|
9
|
+
exports.REGEX_BLOCKS = /^(\|)(code[\s]*|code:|image:|[\s]*$)/; // ++BODY: $2^$3
|
|
10
|
+
exports.REGEX_TITLE_BLOCKS = /^([#]{1,3})([^\S\r\n]+)/; // ++BODY: $4^$5
|
|
11
|
+
exports.REGEX_LIST_BLOCKS = /^(•)([0-9]+[iI]*|[a-zA-Z]{1}|_|\+|-|)([^\S\r\n]+)/; // ++BODY: $6^$7$8
|
|
12
|
+
exports.REGEX_START_OF_TAG = /(\[)([.@#▼►%!?+\-$_=&])/; // --BODY: $2^$3 ++BODY: $9^$10
|
|
13
|
+
exports.REGEX_FOOTER_DIVIDER = /^(~)(~~~[ \t]*)$/; // --BODY: $4^$5 ++BODY: $11^$12
|
|
14
|
+
exports.REGEX_PLAIN_TEXT_DIVIDER = /^(\$)(\$\$\$[ \t]*)$/; // --BODY: $6^$7 ++BODY: $13^$14
|
|
15
|
+
exports.REGEX_END_OF_TAG = /(\^*])/; // BM_TAG: ^$2 PLAIN_TAG: ^$1
|
|
16
|
+
exports.REGEX_BIT_START = /^(\[)(\^*)(\.)/; // PLAIN_BODY: $1^$2$3
|
|
17
|
+
exports.REGEX_HATS = /(\^+)/; // BM_TAG: $3^ PLAIN_TAG: $2^ --BODY: ^$8 ++BODY: $15^ // Must be last
|
|
18
|
+
exports.BREAKSCAPE_BITMARK_TAG_REGEX_SOURCE = `${exports.REGEX_MARKS.source}|${exports.REGEX_END_OF_TAG.source}|${exports.REGEX_HATS.source}`;
|
|
19
|
+
exports.BREAKSCAPE_PLAIN_TAG_REGEX_SOURCE = `${exports.REGEX_END_OF_TAG.source}|${exports.REGEX_HATS.source}`;
|
|
20
|
+
exports.BREAKSCAPE_BITMARK_BODY_REGEX_SOURCE = `${exports.REGEX_MARKS.source}|${exports.REGEX_BLOCKS.source}|${exports.REGEX_TITLE_BLOCKS.source}|${exports.REGEX_LIST_BLOCKS.source}|${exports.REGEX_START_OF_TAG.source}|${exports.REGEX_FOOTER_DIVIDER.source}|${exports.REGEX_PLAIN_TEXT_DIVIDER.source}|${exports.REGEX_HATS.source}`;
|
|
21
|
+
exports.BREAKSCAPE_PLAIN_BODY_REGEX_SOURCE = `${exports.REGEX_BIT_START.source}`;
|
|
22
|
+
exports.BREAKSCAPE_BITMARK_TAG_REGEX = new RegExp(exports.BREAKSCAPE_BITMARK_TAG_REGEX_SOURCE, 'gm');
|
|
23
|
+
exports.BREAKSCAPE_BITMARK_TAG_REGEX_REPLACER = '$1$3^$2';
|
|
24
|
+
exports.BREAKSCAPE_PLAIN_TAG_REGEX = new RegExp(exports.BREAKSCAPE_PLAIN_TAG_REGEX_SOURCE, 'gm');
|
|
25
|
+
exports.BREAKSCAPE_PLAIN_TAG_REGEX_REPLACER = '$2^$1';
|
|
26
|
+
exports.BREAKSCAPE_BITMARK_BODY_REGEX = new RegExp(exports.BREAKSCAPE_BITMARK_BODY_REGEX_SOURCE, 'gm');
|
|
27
|
+
exports.BREAKSCAPE_BITMARK_BODY_REGEX_REPLACER = '$1$2$4$6$9$11$13$15^$3$5$7$8$10$12$14';
|
|
28
|
+
exports.BREAKSCAPE_PLAIN_BODY_REGEX = new RegExp(exports.BREAKSCAPE_PLAIN_BODY_REGEX_SOURCE, 'gm');
|
|
29
|
+
exports.BREAKSCAPE_PLAIN_BODY_REGEX_REPLACER = '$1^$2$3';
|
|
30
|
+
exports.BREAKSCAPE_V2_BODY_REGEX = new RegExp('^(?:(\\[)(\\^*)(\\.))|(\\^+)', 'gm');
|
|
31
|
+
exports.BREAKSCAPE_V2_BODY_REGEX_REPLACER = '$1$4^$2$3';
|
|
32
|
+
exports.UNBREAKSCAPE_REGEX = new RegExp('\\^([\\^]*)', 'gm');
|
|
33
|
+
exports.UNBREAKSCAPE_REGEX_REPLACER = '$1';
|
|
34
|
+
exports.UNBREAKSCAPE_PLAIN_IN_BODY_REGEX = new RegExp('^(\\[)\\^(\\^*)(\\.)', 'gm');
|
|
35
|
+
exports.UNBREAKSCAPE_PLAIN_IN_BODY_REGEX_REPLACER = '$1$2$3';
|
|
36
|
+
exports.BREAKSCAPE_CODE_REGEX = new RegExp('^(\\||•|#)', 'gm');
|
|
37
|
+
exports.BREAKSCAPE_CODE_REGEX_REPLACER = '$1^';
|
|
38
|
+
//# sourceMappingURL=RegexConfigs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RegexConfigs.js","sourceRoot":"","sources":["../../../src/breakscaping/RegexConfigs.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEU,QAAA,WAAW,GAAG,iBAAiB,CAAC,CAAC,wCAAwC;AACzE,QAAA,YAAY,GAAG,sCAAsC,CAAC,CAAC,gBAAgB;AACvE,QAAA,kBAAkB,GAAG,yBAAyB,CAAC,CAAC,gBAAgB;AAChE,QAAA,iBAAiB,GAAG,mDAAmD,CAAC,CAAC,kBAAkB;AAC3F,QAAA,kBAAkB,GAAG,yBAAyB,CAAC,CAAC,gCAAgC;AAChF,QAAA,oBAAoB,GAAG,kBAAkB,CAAC,CAAC,iCAAiC;AAC5E,QAAA,wBAAwB,GAAG,sBAAsB,CAAC,CAAC,iCAAiC;AACpF,QAAA,gBAAgB,GAAG,QAAQ,CAAC,CAAC,8BAA8B;AAC3D,QAAA,eAAe,GAAG,gBAAgB,CAAC,CAAC,sBAAsB;AAC1D,QAAA,UAAU,GAAG,OAAO,CAAC,CAAC,0EAA0E;AAEhG,QAAA,mCAAmC,GAAG,GAAG,mBAAW,CAAC,MAAM,IAAI,wBAAgB,CAAC,MAAM,IAAI,kBAAU,CAAC,MAAM,EAAE,CAAC;AAC9G,QAAA,iCAAiC,GAAG,GAAG,wBAAgB,CAAC,MAAM,IAAI,kBAAU,CAAC,MAAM,EAAE,CAAC;AACtF,QAAA,oCAAoC,GAAG,GAAG,mBAAW,CAAC,MAAM,IAAI,oBAAY,CAAC,MAAM,IAAI,0BAAkB,CAAC,MAAM,IAAI,yBAAiB,CAAC,MAAM,IAAI,0BAAkB,CAA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BitType.conversationRight1Scream]: { since: '1.3.0', baseBitType: BitType_1.BitType.conversationLeft1 },
|
|
611
611
|
[BitType_1.BitType.conversationRight1Thought]: { since: '1.3.0', baseBitType: BitType_1.BitType.conversationLeft1 },
|
|
612
|
+
[BitType_1.BitType.clozeAndMultipleChoiceTextConversationLeft1]: { since: '1.3.0', baseBitType: BitType_1.BitType.conversationLeft1 },
|
|
613
|
+
[BitType_1.BitType.clozeAndMultipleChoiceTextConversationLeft1Scream]: {
|
|
614
|
+
since: '1.3.0',
|
|
615
|
+
baseBitType: BitType_1.BitType.conversationLeft1,
|
|
616
|
+
},
|
|
617
|
+
[BitType_1.BitType.clozeAndMultipleChoiceTextConversationLeft1Thought]: {
|
|
618
|
+
since: '1.3.0',
|
|
619
|
+
baseBitType: BitType_1.BitType.conversationLeft1,
|
|
620
|
+
},
|
|
621
|
+
[BitType_1.BitType.clozeAndMultipleChoiceTextConversationRight1]: { since: '1.3.0', baseBitType: BitType_1.BitType.conversationLeft1 },
|
|
622
|
+
[BitType_1.BitType.clozeAndMultipleChoiceTextConversationRight1Scream]: {
|
|
623
|
+
since: '1.3.0',
|
|
624
|
+
baseBitType: BitType_1.BitType.conversationLeft1,
|
|
625
|
+
},
|
|
626
|
+
[BitType_1.BitType.clozeAndMultipleChoiceTextConversationRight1Thought]: {
|
|
627
|
+
since: '1.3.0',
|
|
628
|
+
baseBitType: BitType_1.BitType.conversationLeft1,
|
|
629
|
+
},
|
|
612
630
|
[BitType_1.BitType.cookPreparation]: { since: '1.3.0', baseBitType: BitType_1.BitType.article },
|
|
613
631
|
[BitType_1.BitType.cookStep]: { since: '1.3.0', baseBitType: BitType_1.BitType.article },
|
|
614
632
|
[BitType_1.BitType.cookIngredients]: {
|
|
@@ -1512,6 +1530,7 @@ const BITS = {
|
|
|
1512
1530
|
},
|
|
1513
1531
|
],
|
|
1514
1532
|
},
|
|
1533
|
+
[BitType_1.BitType.leMultiDayEvent]: { since: '3.32.0', baseBitType: BitType_1.BitType.leClassroomEvent },
|
|
1515
1534
|
[BitType_1.BitType.leCompletion]: {
|
|
1516
1535
|
since: '1.25.0',
|
|
1517
1536
|
baseBitType: BitType_1.BitType.learningPathClosing,
|
|
@@ -2278,6 +2297,25 @@ const BITS = {
|
|
|
2278
2297
|
configKey: PropertyConfigKey_1.PropertyConfigKey.tocResource,
|
|
2279
2298
|
maxCount: Count_1.Count.infinity,
|
|
2280
2299
|
},
|
|
2300
|
+
{
|
|
2301
|
+
type: BitTagType_1.BitTagType.property,
|
|
2302
|
+
configKey: PropertyConfigKey_1.PropertyConfigKey.buttonCaption,
|
|
2303
|
+
},
|
|
2304
|
+
],
|
|
2305
|
+
},
|
|
2306
|
+
[BitType_1.BitType.tocContent]: {
|
|
2307
|
+
since: '3.31.0',
|
|
2308
|
+
baseBitType: BitType_1.BitType.toc,
|
|
2309
|
+
tags: [
|
|
2310
|
+
{
|
|
2311
|
+
type: BitTagType_1.BitTagType.property,
|
|
2312
|
+
configKey: PropertyConfigKey_1.PropertyConfigKey.tocContent,
|
|
2313
|
+
maxCount: Count_1.Count.infinity,
|
|
2314
|
+
},
|
|
2315
|
+
{
|
|
2316
|
+
type: BitTagType_1.BitTagType.property,
|
|
2317
|
+
configKey: PropertyConfigKey_1.PropertyConfigKey.buttonCaption,
|
|
2318
|
+
},
|
|
2281
2319
|
],
|
|
2282
2320
|
},
|
|
2283
2321
|
[BitType_1.BitType.anchor]: { since: '1.3.0', baseBitType: BitType_1.BitType._standard },
|