@gmb/bitmark-parser-generator 3.24.0 → 3.25.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/dist/browser/bitmark-parser-generator.min.js +1 -1
- package/dist/browser/bundle-report.html +2 -2
- package/dist/cjs/BitmarkParserGenerator.js +10 -2
- package/dist/cjs/BitmarkParserGenerator.js.map +1 -1
- package/dist/cjs/ast/BaseBuilder.js +4 -0
- package/dist/cjs/ast/BaseBuilder.js.map +1 -1
- package/dist/cjs/ast/Builder.js +10 -6
- package/dist/cjs/ast/Builder.js.map +1 -1
- package/dist/cjs/breakscaping/Breakscape.js +185 -128
- package/dist/cjs/breakscaping/Breakscape.js.map +1 -1
- package/dist/cjs/config/raw/bits.js +1 -0
- package/dist/cjs/config/raw/bits.js.map +1 -1
- package/dist/cjs/generated/build-info.js +1 -1
- package/dist/cjs/generated/parser/text/text-peggy-parser.js +76 -15
- package/dist/cjs/generated/parser/text/text-peggy-parser.js.map +1 -1
- package/dist/cjs/generator/bitmark/BitmarkGenerator.js +254 -168
- package/dist/cjs/generator/bitmark/BitmarkGenerator.js.map +1 -1
- package/dist/cjs/generator/json/JsonGenerator.js +10 -7
- package/dist/cjs/generator/json/JsonGenerator.js.map +1 -1
- package/dist/cjs/generator/text/TextGenerator.js +42 -12
- package/dist/cjs/generator/text/TextGenerator.js.map +1 -1
- package/dist/cjs/model/enum/BitType.js +1 -0
- package/dist/cjs/model/enum/BitType.js.map +1 -1
- package/dist/cjs/model/enum/TextFormat.js +16 -7
- package/dist/cjs/model/enum/TextFormat.js.map +1 -1
- package/dist/cjs/model/enum/TextLocation.js +15 -0
- package/dist/cjs/model/enum/TextLocation.js.map +1 -0
- package/dist/cjs/parser/bitmark/peg/BitmarkPegParserHelper.js +5 -2
- package/dist/cjs/parser/bitmark/peg/BitmarkPegParserHelper.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/BitmarkPegParserProcessor.js +5 -2
- package/dist/cjs/parser/bitmark/peg/BitmarkPegParserProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/BodyContentProcessor.js +4 -0
- package/dist/cjs/parser/bitmark/peg/contentProcessors/BodyContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/BookChainContentProcessor.js +3 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/BookChainContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/CardContentProcessor.js +1 -2
- package/dist/cjs/parser/bitmark/peg/contentProcessors/CardContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/ClozeTagContentProcessor.js +3 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/ClozeTagContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/DefaultTagContentProcessor.js +17 -5
- package/dist/cjs/parser/bitmark/peg/contentProcessors/DefaultTagContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/ExampleTagContentProcessor.js +8 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/ExampleTagContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/FooterContentProcessor.js +3 -0
- package/dist/cjs/parser/bitmark/peg/contentProcessors/FooterContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/ImageSourceChainContentProcessor.js +3 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/ImageSourceChainContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/MarkConfigChainContentProcessor.js +3 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/MarkConfigChainContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/MarkTagContentProcessor.js +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/MarkTagContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/PersonChainContentProcessor.js +4 -2
- package/dist/cjs/parser/bitmark/peg/contentProcessors/PersonChainContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.js +11 -5
- package/dist/cjs/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/ReferenceTagContentProcessor.js +5 -2
- package/dist/cjs/parser/bitmark/peg/contentProcessors/ReferenceTagContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/ResourceContentProcessor.js +7 -2
- package/dist/cjs/parser/bitmark/peg/contentProcessors/ResourceContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/TechnicalTermChainContentProcessor.js +3 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/TechnicalTermChainContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/TrueFalseTagContentProcessor.js +3 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/TrueFalseTagContentProcessor.js.map +1 -1
- package/dist/cjs/parser/text/TextParser.js +0 -15
- package/dist/cjs/parser/text/TextParser.js.map +1 -1
- package/dist/esm/BitmarkParserGenerator.js +10 -2
- package/dist/esm/BitmarkParserGenerator.js.map +1 -1
- package/dist/esm/ast/BaseBuilder.js +4 -0
- package/dist/esm/ast/BaseBuilder.js.map +1 -1
- package/dist/esm/ast/Builder.js +10 -6
- package/dist/esm/ast/Builder.js.map +1 -1
- package/dist/esm/breakscaping/Breakscape.js +185 -128
- package/dist/esm/breakscaping/Breakscape.js.map +1 -1
- package/dist/esm/config/raw/bits.js +1 -0
- package/dist/esm/config/raw/bits.js.map +1 -1
- package/dist/esm/generated/build-info.js +1 -1
- package/dist/esm/generated/parser/text/text-peggy-parser.js +76 -15
- package/dist/esm/generated/parser/text/text-peggy-parser.js.map +1 -1
- package/dist/esm/generator/bitmark/BitmarkGenerator.js +254 -168
- package/dist/esm/generator/bitmark/BitmarkGenerator.js.map +1 -1
- package/dist/esm/generator/json/JsonGenerator.js +10 -7
- package/dist/esm/generator/json/JsonGenerator.js.map +1 -1
- package/dist/esm/generator/text/TextGenerator.js +42 -12
- package/dist/esm/generator/text/TextGenerator.js.map +1 -1
- package/dist/esm/model/enum/BitType.js +1 -0
- package/dist/esm/model/enum/BitType.js.map +1 -1
- package/dist/esm/model/enum/TextFormat.js +16 -7
- package/dist/esm/model/enum/TextFormat.js.map +1 -1
- package/dist/esm/model/enum/TextLocation.js +12 -0
- package/dist/esm/model/enum/TextLocation.js.map +1 -0
- package/dist/esm/parser/bitmark/peg/BitmarkPegParserHelper.js +5 -2
- package/dist/esm/parser/bitmark/peg/BitmarkPegParserHelper.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/BitmarkPegParserProcessor.js +5 -2
- package/dist/esm/parser/bitmark/peg/BitmarkPegParserProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/BodyContentProcessor.js +4 -0
- package/dist/esm/parser/bitmark/peg/contentProcessors/BodyContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/BookChainContentProcessor.js +3 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/BookChainContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/CardContentProcessor.js +1 -2
- package/dist/esm/parser/bitmark/peg/contentProcessors/CardContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/ClozeTagContentProcessor.js +3 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/ClozeTagContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/DefaultTagContentProcessor.js +17 -5
- package/dist/esm/parser/bitmark/peg/contentProcessors/DefaultTagContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/ExampleTagContentProcessor.js +8 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/ExampleTagContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/FooterContentProcessor.js +3 -0
- package/dist/esm/parser/bitmark/peg/contentProcessors/FooterContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/ImageSourceChainContentProcessor.js +3 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/ImageSourceChainContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/MarkConfigChainContentProcessor.js +3 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/MarkConfigChainContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/MarkTagContentProcessor.js +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/MarkTagContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/PersonChainContentProcessor.js +4 -2
- package/dist/esm/parser/bitmark/peg/contentProcessors/PersonChainContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.js +11 -5
- package/dist/esm/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/ReferenceTagContentProcessor.js +5 -2
- package/dist/esm/parser/bitmark/peg/contentProcessors/ReferenceTagContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/ResourceContentProcessor.js +7 -2
- package/dist/esm/parser/bitmark/peg/contentProcessors/ResourceContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/TechnicalTermChainContentProcessor.js +3 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/TechnicalTermChainContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/TrueFalseTagContentProcessor.js +3 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/TrueFalseTagContentProcessor.js.map +1 -1
- package/dist/esm/parser/text/TextParser.js +0 -15
- package/dist/esm/parser/text/TextParser.js.map +1 -1
- package/dist/types/BitmarkParserGenerator.d.ts +13 -0
- package/dist/types/BitmarkParserGenerator.d.ts.map +1 -1
- package/dist/types/ast/BaseBuilder.d.ts.map +1 -1
- package/dist/types/ast/Builder.d.ts.map +1 -1
- package/dist/types/breakscaping/Breakscape.d.ts +23 -1
- package/dist/types/breakscaping/Breakscape.d.ts.map +1 -1
- package/dist/types/config/raw/bits.d.ts.map +1 -1
- package/dist/types/generated/parser/text/text-peggy-parser.d.ts.map +1 -1
- package/dist/types/generator/bitmark/BitmarkGenerator.d.ts +60 -18
- package/dist/types/generator/bitmark/BitmarkGenerator.d.ts.map +1 -1
- package/dist/types/generator/json/JsonGenerator.d.ts.map +1 -1
- package/dist/types/generator/text/TextGenerator.d.ts +9 -2
- package/dist/types/generator/text/TextGenerator.d.ts.map +1 -1
- package/dist/types/model/enum/BitType.d.ts +2 -0
- package/dist/types/model/enum/BitType.d.ts.map +1 -1
- package/dist/types/model/enum/TextFormat.d.ts +0 -2
- package/dist/types/model/enum/TextFormat.d.ts.map +1 -1
- package/dist/types/model/enum/TextLocation.d.ts +16 -0
- package/dist/types/model/enum/TextLocation.d.ts.map +1 -0
- package/dist/types/model/json/BitJson.d.ts +3 -3
- package/dist/types/model/json/BitJson.d.ts.map +1 -1
- package/dist/types/parser/bitmark/peg/BitmarkPegParserHelper.d.ts.map +1 -1
- package/dist/types/parser/bitmark/peg/BitmarkPegParserProcessor.d.ts.map +1 -1
- package/dist/types/parser/bitmark/peg/contentProcessors/BodyContentProcessor.d.ts.map +1 -1
- package/dist/types/parser/bitmark/peg/contentProcessors/BookChainContentProcessor.d.ts.map +1 -1
- package/dist/types/parser/bitmark/peg/contentProcessors/CardContentProcessor.d.ts.map +1 -1
- package/dist/types/parser/bitmark/peg/contentProcessors/ClozeTagContentProcessor.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/bitmark/peg/contentProcessors/FooterContentProcessor.d.ts.map +1 -1
- package/dist/types/parser/bitmark/peg/contentProcessors/ImageSourceChainContentProcessor.d.ts.map +1 -1
- package/dist/types/parser/bitmark/peg/contentProcessors/MarkConfigChainContentProcessor.d.ts.map +1 -1
- package/dist/types/parser/bitmark/peg/contentProcessors/PersonChainContentProcessor.d.ts.map +1 -1
- package/dist/types/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.d.ts.map +1 -1
- package/dist/types/parser/bitmark/peg/contentProcessors/ReferenceTagContentProcessor.d.ts.map +1 -1
- package/dist/types/parser/bitmark/peg/contentProcessors/ResourceContentProcessor.d.ts.map +1 -1
- package/dist/types/parser/bitmark/peg/contentProcessors/TechnicalTermChainContentProcessor.d.ts.map +1 -1
- package/dist/types/parser/bitmark/peg/contentProcessors/TrueFalseTagContentProcessor.d.ts.map +1 -1
- package/dist/types/parser/text/TextParser.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -8,6 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { Ast } from '../../ast/Ast';
|
|
11
|
+
import { StringWriter } from '../../ast/writer/StringWriter';
|
|
11
12
|
import { Breakscape } from '../../breakscaping/Breakscape';
|
|
12
13
|
import { Config } from '../../config/Config';
|
|
13
14
|
import { NodeType } from '../../model/ast/NodeType';
|
|
@@ -19,6 +20,7 @@ import { PropertyFormat } from '../../model/enum/PropertyFormat';
|
|
|
19
20
|
import { PropertyTag } from '../../model/enum/PropertyTag';
|
|
20
21
|
import { ResourceTag } from '../../model/enum/ResourceTag';
|
|
21
22
|
import { TextFormat } from '../../model/enum/TextFormat';
|
|
23
|
+
import { TextLocation } from '../../model/enum/TextLocation';
|
|
22
24
|
import { BooleanUtils } from '../../utils/BooleanUtils';
|
|
23
25
|
import { ObjectUtils } from '../../utils/ObjectUtils';
|
|
24
26
|
import { StringUtils } from '../../utils/StringUtils';
|
|
@@ -27,6 +29,8 @@ import { TextGenerator } from '../text/TextGenerator';
|
|
|
27
29
|
const DEFAULT_OPTIONS = {
|
|
28
30
|
debugGenerationInline: false,
|
|
29
31
|
};
|
|
32
|
+
const DEFAULT_SPACES_AROUND_VALUES = 1;
|
|
33
|
+
const MAX_SPACES_AROUND_VALUES = 10;
|
|
30
34
|
/**
|
|
31
35
|
* Generate bitmark markup from a bitmark AST
|
|
32
36
|
*
|
|
@@ -54,6 +58,11 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
54
58
|
super();
|
|
55
59
|
this.ast = new Ast();
|
|
56
60
|
// State
|
|
61
|
+
this.bitType = BitType._error;
|
|
62
|
+
this.textFormat = TextFormat.bitmarkMinusMinus;
|
|
63
|
+
this.tagTextFormat = TextFormat.bitmarkMinusMinus;
|
|
64
|
+
this.isBodyBitmarkText = false;
|
|
65
|
+
this.isCardAllowed = false;
|
|
57
66
|
this.firstBit = true;
|
|
58
67
|
this.hasCardSet = false;
|
|
59
68
|
this.hasFooter = false;
|
|
@@ -84,13 +93,18 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
84
93
|
}
|
|
85
94
|
// Calculate the prettify space
|
|
86
95
|
this.prettifySpace = this.options.prettifyJson === true ? 2 : this.options.prettifyJson || undefined;
|
|
96
|
+
// Calculate the spaces around values
|
|
97
|
+
this.spacesAroundValues = this.calcSpacesAroundValues();
|
|
98
|
+
this.spacesAroundValuesStr = ' '.repeat(this.spacesAroundValues);
|
|
87
99
|
// Create the text generator
|
|
88
100
|
this.textGenerator = new TextGenerator(this.bitmarkVersion, {
|
|
89
101
|
writeCallback: this.write,
|
|
90
102
|
bodyBitCallback: this.bodyBitCallback,
|
|
91
103
|
debugGenerationInline: this.debugGenerationInline,
|
|
92
104
|
});
|
|
93
|
-
this.
|
|
105
|
+
this.mainWriter = writer;
|
|
106
|
+
this.partWriter = new StringWriter();
|
|
107
|
+
this.writer = this.mainWriter;
|
|
94
108
|
this.generateResourceHandlers();
|
|
95
109
|
this.generatePropertyHandlers();
|
|
96
110
|
}
|
|
@@ -129,6 +143,11 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
129
143
|
this.writer.closeSync();
|
|
130
144
|
}
|
|
131
145
|
resetState() {
|
|
146
|
+
this.bitType = BitType._error;
|
|
147
|
+
this.textFormat = TextFormat.bitmarkMinusMinus;
|
|
148
|
+
this.tagTextFormat = TextFormat.bitmarkMinusMinus;
|
|
149
|
+
this.isBodyBitmarkText = false;
|
|
150
|
+
this.isCardAllowed = false;
|
|
132
151
|
this.firstBit = true;
|
|
133
152
|
this.hasCardSet = false;
|
|
134
153
|
this.hasFooter = false;
|
|
@@ -150,9 +169,24 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
150
169
|
// bitmark
|
|
151
170
|
// bitmarkAst -> bits -> bitsValue
|
|
152
171
|
enter_bitsValue(node, _route) {
|
|
172
|
+
var _a;
|
|
153
173
|
const bit = node.value;
|
|
154
174
|
const bitConfig = Config.getBitConfig(bit.bitType);
|
|
155
175
|
const bitResourcesConfig = Config.getBitResourcesConfig(bit.bitType, bit.resourceType);
|
|
176
|
+
// Set state variables
|
|
177
|
+
this.bitType = bit.bitType;
|
|
178
|
+
this.textFormat = (_a = bit.textFormat) !== null && _a !== void 0 ? _a : bitConfig.textFormatDefault;
|
|
179
|
+
this.isBodyBitmarkText =
|
|
180
|
+
this.textFormat === TextFormat.bitmarkMinusMinus || this.textFormat === TextFormat.bitmarkPlusPlus;
|
|
181
|
+
this.isCardAllowed = this.calculateIsCardAllowed();
|
|
182
|
+
// NOTE:
|
|
183
|
+
// If the bit text format is bitmark++ then the tagTextFormat should be bitmark+, but that is not implemented yet.
|
|
184
|
+
// It works anyhow, and would require a lot of changes to implement.
|
|
185
|
+
// Since this may well change in the future, we will keep the code as is for now.
|
|
186
|
+
this.tagTextFormat =
|
|
187
|
+
this.textFormat === TextFormat.bitmarkPlusPlus
|
|
188
|
+
? TextFormat.bitmarkPlusPlus // NOTE: should be bitmarkPlus
|
|
189
|
+
: TextFormat.bitmarkMinusMinus;
|
|
156
190
|
this.hasCardSet = this.haveValidCardSet(bit);
|
|
157
191
|
this.hasFooter = this.haveValidFooter(bit);
|
|
158
192
|
// Separate the bits with 3 newlines
|
|
@@ -165,12 +199,12 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
165
199
|
this.writeOPD(bit.bitLevel);
|
|
166
200
|
if (bit.isCommented)
|
|
167
201
|
this.writeString('|');
|
|
168
|
-
this.
|
|
202
|
+
this.writeTagKey(bit.bitType);
|
|
169
203
|
if (bit.textFormat) {
|
|
170
204
|
const write = this.isWriteTextFormat(bit.textFormat, bitConfig.textFormatDefault);
|
|
171
205
|
if (write) {
|
|
172
206
|
this.writeColon();
|
|
173
|
-
this.
|
|
207
|
+
this.writeTagKey(bit.textFormat);
|
|
174
208
|
}
|
|
175
209
|
}
|
|
176
210
|
// Use the bitConfig to see if we need to write the resourceType attachment
|
|
@@ -193,7 +227,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
193
227
|
}
|
|
194
228
|
if (resourceType) {
|
|
195
229
|
this.writeAmpersand();
|
|
196
|
-
this.
|
|
230
|
+
this.writeTagKey(resourceType);
|
|
197
231
|
}
|
|
198
232
|
this.writeCL();
|
|
199
233
|
// this.writeNL();
|
|
@@ -367,13 +401,8 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
367
401
|
}
|
|
368
402
|
if (hint != null) {
|
|
369
403
|
this.writeOPQ();
|
|
370
|
-
this.
|
|
404
|
+
this.writeTextOrValue(hint, TextFormat.text, TextLocation.tag);
|
|
371
405
|
this.writeCL();
|
|
372
|
-
// this.writeProperty('hint', hint, {
|
|
373
|
-
// format: PropertyFormat.trimmedString,
|
|
374
|
-
// single: true,
|
|
375
|
-
// ignoreEmpty: true,
|
|
376
|
-
// });
|
|
377
406
|
}
|
|
378
407
|
return false;
|
|
379
408
|
}
|
|
@@ -399,7 +428,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
399
428
|
});
|
|
400
429
|
}
|
|
401
430
|
if (avatarImage) {
|
|
402
|
-
this.writeResource(ResourceTag.image, avatarImage.src);
|
|
431
|
+
this.writeResource(ResourceTag.image, avatarImage.image.src);
|
|
403
432
|
}
|
|
404
433
|
// Stop traversal of this branch
|
|
405
434
|
return false;
|
|
@@ -413,8 +442,6 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
413
442
|
// bitmarkAst -> bits -> bitsValue -> cardNode -> flashcards -> flashcardsValue -> alternativeAnswers ->
|
|
414
443
|
// -> alternativeAnswersValue -> text
|
|
415
444
|
enter_text(node, route) {
|
|
416
|
-
var _a;
|
|
417
|
-
const textFormat = (_a = this.getTextFormat(route)) !== null && _a !== void 0 ? _a : TextFormat.bitmarkMinusMinus;
|
|
418
445
|
const parent = this.getParentNode(route);
|
|
419
446
|
if (!parent ||
|
|
420
447
|
(parent.key !== NodeType.term &&
|
|
@@ -427,7 +454,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
427
454
|
}
|
|
428
455
|
if (node.value) {
|
|
429
456
|
this.writeNL();
|
|
430
|
-
this.
|
|
457
|
+
this.writeTextOrValue(node.value, this.textFormat, TextLocation.body);
|
|
431
458
|
}
|
|
432
459
|
// Stop traversal of this branch
|
|
433
460
|
return false;
|
|
@@ -445,11 +472,8 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
445
472
|
return true;
|
|
446
473
|
}
|
|
447
474
|
if (StringUtils.isString(node.value)) {
|
|
448
|
-
const str = node.value;
|
|
449
475
|
this.writeNL();
|
|
450
|
-
this.
|
|
451
|
-
textFormat: TextFormat.text,
|
|
452
|
-
}));
|
|
476
|
+
this.writeTextOrValue(node.value, this.textFormat, TextLocation.body);
|
|
453
477
|
}
|
|
454
478
|
// Stop traversal of this branch
|
|
455
479
|
return false;
|
|
@@ -653,7 +677,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
653
677
|
return true; // Will be handled by marginNumber
|
|
654
678
|
this.writeNL_IfNotChain(route);
|
|
655
679
|
this.writeOPC();
|
|
656
|
-
this.
|
|
680
|
+
this.writeTextOrValue(item, this.tagTextFormat, TextLocation.tag);
|
|
657
681
|
this.writeCL();
|
|
658
682
|
return true;
|
|
659
683
|
}
|
|
@@ -670,10 +694,10 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
670
694
|
return true; // Will be handled by marginNumber
|
|
671
695
|
this.writeNL_IfNotChain(route);
|
|
672
696
|
this.writeOPC();
|
|
673
|
-
this.
|
|
697
|
+
this.writeTextOrValue((_d = (_c = parent === null || parent === void 0 ? void 0 : parent.value) === null || _c === void 0 ? void 0 : _c.item) !== null && _d !== void 0 ? _d : '', this.tagTextFormat, TextLocation.tag);
|
|
674
698
|
this.writeCL();
|
|
675
699
|
this.writeOPC();
|
|
676
|
-
this.
|
|
700
|
+
this.writeTextOrValue(lead, this.tagTextFormat, TextLocation.tag);
|
|
677
701
|
this.writeCL();
|
|
678
702
|
return true;
|
|
679
703
|
}
|
|
@@ -688,13 +712,13 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
688
712
|
return true; // Will be handled by marginNumber
|
|
689
713
|
this.writeNL_IfNotChain(route);
|
|
690
714
|
this.writeOPC();
|
|
691
|
-
this.
|
|
715
|
+
this.writeTextOrValue((_c = (_b = parent === null || parent === void 0 ? void 0 : parent.value) === null || _b === void 0 ? void 0 : _b.item) !== null && _c !== void 0 ? _c : '', this.tagTextFormat, TextLocation.tag);
|
|
692
716
|
this.writeCL();
|
|
693
717
|
this.writeOPC();
|
|
694
|
-
this.
|
|
718
|
+
this.writeTextOrValue((_e = (_d = parent === null || parent === void 0 ? void 0 : parent.value) === null || _d === void 0 ? void 0 : _d.lead) !== null && _e !== void 0 ? _e : '', this.tagTextFormat, TextLocation.tag);
|
|
695
719
|
this.writeCL();
|
|
696
720
|
this.writeOPC();
|
|
697
|
-
this.
|
|
721
|
+
this.writeTextOrValue(pageNumber !== null && pageNumber !== void 0 ? pageNumber : '', this.tagTextFormat, TextLocation.tag);
|
|
698
722
|
this.writeCL();
|
|
699
723
|
return true;
|
|
700
724
|
}
|
|
@@ -707,16 +731,16 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
707
731
|
return false; // Ignore empty
|
|
708
732
|
this.writeNL_IfNotChain(route);
|
|
709
733
|
this.writeOPC();
|
|
710
|
-
this.
|
|
734
|
+
this.writeTextOrValue((_b = (_a = parent === null || parent === void 0 ? void 0 : parent.value) === null || _a === void 0 ? void 0 : _a.item) !== null && _b !== void 0 ? _b : '', this.tagTextFormat, TextLocation.tag);
|
|
711
735
|
this.writeCL();
|
|
712
736
|
this.writeOPC();
|
|
713
|
-
this.
|
|
737
|
+
this.writeTextOrValue((_d = (_c = parent === null || parent === void 0 ? void 0 : parent.value) === null || _c === void 0 ? void 0 : _c.lead) !== null && _d !== void 0 ? _d : '', this.tagTextFormat, TextLocation.tag);
|
|
714
738
|
this.writeCL();
|
|
715
739
|
this.writeOPC();
|
|
716
|
-
this.
|
|
740
|
+
this.writeTextOrValue((_f = (_e = parent === null || parent === void 0 ? void 0 : parent.value) === null || _e === void 0 ? void 0 : _e.pageNumber) !== null && _f !== void 0 ? _f : '', this.tagTextFormat, TextLocation.tag);
|
|
717
741
|
this.writeCL();
|
|
718
742
|
this.writeOPC();
|
|
719
|
-
this.
|
|
743
|
+
this.writeTextOrValue(marginNumber, this.tagTextFormat, TextLocation.tag);
|
|
720
744
|
this.writeCL();
|
|
721
745
|
return true;
|
|
722
746
|
}
|
|
@@ -730,29 +754,25 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
730
754
|
this.inTag = false;
|
|
731
755
|
// Always write a NL before the body content if there is any (see Handle body)
|
|
732
756
|
const body = node.value;
|
|
733
|
-
const textFormat = this.getTextFormat(route);
|
|
734
|
-
const isBitmarkText = textFormat === TextFormat.bitmarkPlusPlus || textFormat === TextFormat.bitmarkMinusMinus;
|
|
735
757
|
// Handle body
|
|
736
|
-
if (textFormat === TextFormat.json) {
|
|
758
|
+
if (this.textFormat === TextFormat.json) {
|
|
737
759
|
const json = (_a = body.body) !== null && _a !== void 0 ? _a : null;
|
|
738
760
|
if (Array.isArray(json) || ObjectUtils.isObject(json)) {
|
|
739
761
|
const text = JSON.stringify(json, null, this.prettifySpace);
|
|
740
762
|
if (text) {
|
|
741
763
|
this.writePlainTextDivider();
|
|
742
764
|
this.writeNL();
|
|
743
|
-
this.
|
|
744
|
-
textFormat: TextFormat.text,
|
|
745
|
-
}));
|
|
765
|
+
this.writeTextOrValue(text, TextFormat.text, TextLocation.body);
|
|
746
766
|
}
|
|
747
767
|
}
|
|
748
768
|
}
|
|
749
|
-
else if (
|
|
769
|
+
else if (this.isBodyBitmarkText) {
|
|
750
770
|
// handle bitmark text
|
|
751
771
|
const plainTextDividerAllowed = !(this.hasCardSet || this.hasFooter);
|
|
752
772
|
this.writeNL();
|
|
753
773
|
// The text generator will write to the writer
|
|
754
774
|
const b = (Array.isArray(body.body) ? body.body : []);
|
|
755
|
-
this.
|
|
775
|
+
this.writeTextOrValue(b, this.textFormat, TextLocation.body, {
|
|
756
776
|
plainTextDividerAllowed,
|
|
757
777
|
});
|
|
758
778
|
}
|
|
@@ -761,9 +781,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
761
781
|
this.writePlainTextDivider();
|
|
762
782
|
this.writeNL();
|
|
763
783
|
const s = (StringUtils.isString(body.body) ? body.body : '');
|
|
764
|
-
this.
|
|
765
|
-
textFormat: TextFormat.text,
|
|
766
|
-
}));
|
|
784
|
+
this.writeTextOrValue(`${s}`, TextFormat.text, TextLocation.body);
|
|
767
785
|
}
|
|
768
786
|
// Stop traversal of this branch
|
|
769
787
|
return false;
|
|
@@ -790,7 +808,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
790
808
|
else {
|
|
791
809
|
for (const solution of gap.solutions) {
|
|
792
810
|
this.writeOPU();
|
|
793
|
-
this.
|
|
811
|
+
this.writeTextOrValue(solution, TextFormat.text, TextLocation.tag);
|
|
794
812
|
this.writeCL();
|
|
795
813
|
}
|
|
796
814
|
}
|
|
@@ -801,7 +819,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
801
819
|
enter_mark(node, _route) {
|
|
802
820
|
const mark = node.value;
|
|
803
821
|
this.writeOPE();
|
|
804
|
-
this.
|
|
822
|
+
this.writeTextOrValue(mark.solution, TextFormat.text, TextLocation.tag);
|
|
805
823
|
this.writeCL();
|
|
806
824
|
// Continue traversal
|
|
807
825
|
return true;
|
|
@@ -822,21 +840,19 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
822
840
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.bitsValue)
|
|
823
841
|
return true;
|
|
824
842
|
const footer = node.value;
|
|
825
|
-
const textFormat = this.getTextFormat(route);
|
|
826
843
|
// Handle footer
|
|
827
|
-
if (textFormat === TextFormat.json) {
|
|
844
|
+
if (this.textFormat === TextFormat.json) {
|
|
828
845
|
// Json footer?!
|
|
829
846
|
// Not valid, ignore
|
|
830
847
|
}
|
|
831
848
|
else if (footer.footer && footer.footer.length > 0) {
|
|
832
|
-
|
|
833
|
-
if (isBitmarkText) {
|
|
849
|
+
if (this.isBodyBitmarkText) {
|
|
834
850
|
// handle bitmark text
|
|
835
851
|
this.writeNL();
|
|
836
|
-
this.
|
|
852
|
+
this.writeTextOrValue('==== footer ====', TextFormat.text, TextLocation.body);
|
|
837
853
|
this.writeNL();
|
|
838
854
|
// The text generator will write to the writer
|
|
839
|
-
this.
|
|
855
|
+
this.writeTextOrValue(footer.footer, this.textFormat, TextLocation.body, {
|
|
840
856
|
plainTextDividerAllowed: true, // Always allowed for the footer.
|
|
841
857
|
});
|
|
842
858
|
}
|
|
@@ -875,7 +891,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
875
891
|
return;
|
|
876
892
|
if (solution) {
|
|
877
893
|
this.writeOPE();
|
|
878
|
-
this.
|
|
894
|
+
this.writeTextOrValue(solution, TextFormat.text, TextLocation.tag);
|
|
879
895
|
this.writeCL();
|
|
880
896
|
}
|
|
881
897
|
}
|
|
@@ -902,7 +918,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
902
918
|
else {
|
|
903
919
|
this.writeOPM();
|
|
904
920
|
}
|
|
905
|
-
this.
|
|
921
|
+
this.writeTextOrValue(selectOption.text, TextFormat.text, TextLocation.tag);
|
|
906
922
|
this.writeCL();
|
|
907
923
|
// Continue traversal
|
|
908
924
|
return true;
|
|
@@ -916,29 +932,29 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
916
932
|
else {
|
|
917
933
|
this.writeOPM();
|
|
918
934
|
}
|
|
919
|
-
this.
|
|
935
|
+
this.writeTextOrValue(highlightText.text, TextFormat.text, TextLocation.tag);
|
|
920
936
|
this.writeCL();
|
|
921
937
|
// Continue traversal
|
|
922
938
|
return true;
|
|
923
939
|
}
|
|
924
940
|
// bitmarkAst -> bits -> bitsValue -> cardNode
|
|
925
|
-
enter_cardNode(_node,
|
|
941
|
+
enter_cardNode(_node, _route) {
|
|
926
942
|
// Ignore cards if not allowed
|
|
927
|
-
if (!this.isCardAllowed
|
|
943
|
+
if (!this.isCardAllowed)
|
|
928
944
|
return true;
|
|
929
945
|
this.writeCardSetStart();
|
|
930
946
|
// Continue traversal
|
|
931
947
|
return true;
|
|
932
948
|
}
|
|
933
|
-
between_cardNode(_node, _left, _right,
|
|
949
|
+
between_cardNode(_node, _left, _right, _route) {
|
|
934
950
|
// Ignore cards if not allowed
|
|
935
|
-
if (!this.isCardAllowed
|
|
951
|
+
if (!this.isCardAllowed)
|
|
936
952
|
return;
|
|
937
953
|
this.writeCardSetCardDivider();
|
|
938
954
|
}
|
|
939
|
-
exit_cardNode(_node,
|
|
955
|
+
exit_cardNode(_node, _route) {
|
|
940
956
|
// Ignore cards if not allowed
|
|
941
|
-
if (!this.isCardAllowed
|
|
957
|
+
if (!this.isCardAllowed)
|
|
942
958
|
return;
|
|
943
959
|
this.writeCardSetEnd();
|
|
944
960
|
if (this.options.cardSetVersion === CardSetVersion.v1) {
|
|
@@ -957,10 +973,10 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
957
973
|
this.writeCardSetCardDivider();
|
|
958
974
|
}
|
|
959
975
|
// bitmarkAst -> bits -> bitsValue -> cardNode -> flashcards -> flashcardsValue
|
|
960
|
-
between_flashcardsValue(_node, _left, right,
|
|
976
|
+
between_flashcardsValue(_node, _left, right, _route) {
|
|
961
977
|
var _a;
|
|
962
978
|
// Ignore cards if not allowed
|
|
963
|
-
if (!this.isCardAllowed
|
|
979
|
+
if (!this.isCardAllowed)
|
|
964
980
|
return;
|
|
965
981
|
if (right.key === NodeType.answer) {
|
|
966
982
|
this.writeCardSetSideDivider();
|
|
@@ -981,8 +997,8 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
981
997
|
enter_statements(_node, _route) {
|
|
982
998
|
//
|
|
983
999
|
}
|
|
984
|
-
between_statements(_node, _left, _right,
|
|
985
|
-
const isTrueFalse1 = this.isOfBitType(
|
|
1000
|
+
between_statements(_node, _left, _right, _route) {
|
|
1001
|
+
const isTrueFalse1 = this.isOfBitType(BitType.trueFalse1);
|
|
986
1002
|
if (!isTrueFalse1) {
|
|
987
1003
|
this.writeCardSetCardDivider();
|
|
988
1004
|
}
|
|
@@ -997,7 +1013,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
997
1013
|
else {
|
|
998
1014
|
this.writeOPM();
|
|
999
1015
|
}
|
|
1000
|
-
this.
|
|
1016
|
+
this.writeTextOrValue(statement.statement, TextFormat.text, TextLocation.tag);
|
|
1001
1017
|
this.writeCL();
|
|
1002
1018
|
// Continue traversal
|
|
1003
1019
|
return true;
|
|
@@ -1014,7 +1030,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1014
1030
|
else {
|
|
1015
1031
|
this.writeOPM();
|
|
1016
1032
|
}
|
|
1017
|
-
this.
|
|
1033
|
+
this.writeTextOrValue(choice.choice, TextFormat.text, TextLocation.tag);
|
|
1018
1034
|
this.writeCL();
|
|
1019
1035
|
// Continue traversal
|
|
1020
1036
|
return true;
|
|
@@ -1030,7 +1046,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1030
1046
|
else {
|
|
1031
1047
|
this.writeOPM();
|
|
1032
1048
|
}
|
|
1033
|
-
this.
|
|
1049
|
+
this.writeTextOrValue(response.response, TextFormat.text, TextLocation.tag);
|
|
1034
1050
|
this.writeCL();
|
|
1035
1051
|
// Continue traversal
|
|
1036
1052
|
return true;
|
|
@@ -1056,9 +1072,9 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1056
1072
|
enter_heading(_node, _route) {
|
|
1057
1073
|
//
|
|
1058
1074
|
}
|
|
1059
|
-
between_heading(_node, _left, _right,
|
|
1075
|
+
between_heading(_node, _left, _right, _route) {
|
|
1060
1076
|
// Ignore cards if not allowed
|
|
1061
|
-
if (!this.isCardAllowed
|
|
1077
|
+
if (!this.isCardAllowed)
|
|
1062
1078
|
return;
|
|
1063
1079
|
this.writeCardSetSideDivider();
|
|
1064
1080
|
}
|
|
@@ -1066,9 +1082,9 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1066
1082
|
enter_forValues(_node, _route) {
|
|
1067
1083
|
//
|
|
1068
1084
|
}
|
|
1069
|
-
between_forValues(_node, _left, _right,
|
|
1085
|
+
between_forValues(_node, _left, _right, _route) {
|
|
1070
1086
|
// Ignore cards if not allowed
|
|
1071
|
-
if (!this.isCardAllowed
|
|
1087
|
+
if (!this.isCardAllowed)
|
|
1072
1088
|
return;
|
|
1073
1089
|
this.writeCardSetSideDivider();
|
|
1074
1090
|
}
|
|
@@ -1106,15 +1122,15 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1106
1122
|
}
|
|
1107
1123
|
// bitmarkAst -> bits -> bitsValue -> cardNode -> pairs -> pairsValue -> values
|
|
1108
1124
|
// bitmarkAst -> bits -> bitsValue -> cardNode -> matrix -> matrixValue -> cells -> cellsValue -> values
|
|
1109
|
-
enter_values(_node,
|
|
1125
|
+
enter_values(_node, _route) {
|
|
1110
1126
|
// Ignore cards if not allowed
|
|
1111
|
-
if (!this.isCardAllowed
|
|
1127
|
+
if (!this.isCardAllowed)
|
|
1112
1128
|
return;
|
|
1113
1129
|
this.writeCardSetSideDivider();
|
|
1114
1130
|
}
|
|
1115
|
-
between_values(_node, _left, _right,
|
|
1131
|
+
between_values(_node, _left, _right, _route) {
|
|
1116
1132
|
// Ignore cards if not allowed
|
|
1117
|
-
if (!this.isCardAllowed
|
|
1133
|
+
if (!this.isCardAllowed)
|
|
1118
1134
|
return;
|
|
1119
1135
|
this.writeCardSetVariantDivider();
|
|
1120
1136
|
}
|
|
@@ -1124,7 +1140,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1124
1140
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.cardNode)
|
|
1125
1141
|
return;
|
|
1126
1142
|
// Ignore cards if not allowed
|
|
1127
|
-
if (!this.isCardAllowed
|
|
1143
|
+
if (!this.isCardAllowed)
|
|
1128
1144
|
return;
|
|
1129
1145
|
this.writeCardSetCardDivider();
|
|
1130
1146
|
}
|
|
@@ -1134,7 +1150,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1134
1150
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.cardNode)
|
|
1135
1151
|
return;
|
|
1136
1152
|
// Ignore cards if not allowed
|
|
1137
|
-
if (!this.isCardAllowed
|
|
1153
|
+
if (!this.isCardAllowed)
|
|
1138
1154
|
return;
|
|
1139
1155
|
this.writeCardSetCardDivider();
|
|
1140
1156
|
}
|
|
@@ -1154,7 +1170,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1154
1170
|
if (parentKey !== NodeType.table && parentKey !== NodeType.captionDefinitionList)
|
|
1155
1171
|
return;
|
|
1156
1172
|
// Ignore cards if not allowed
|
|
1157
|
-
if (!this.isCardAllowed
|
|
1173
|
+
if (!this.isCardAllowed)
|
|
1158
1174
|
return;
|
|
1159
1175
|
this.writeCardSetSideDivider();
|
|
1160
1176
|
}
|
|
@@ -1163,16 +1179,13 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1163
1179
|
leaf_columnsValue(node, _route) {
|
|
1164
1180
|
this.writeNL();
|
|
1165
1181
|
this.writeOPHASH();
|
|
1166
|
-
|
|
1167
|
-
this.writeBreakscapedTagString(node.value);
|
|
1182
|
+
this.writeTextOrValue(node.value, TextFormat.text, TextLocation.tag);
|
|
1168
1183
|
this.writeCL();
|
|
1169
1184
|
}
|
|
1170
1185
|
enter_columnsValue(node, _route) {
|
|
1171
1186
|
this.writeNL();
|
|
1172
1187
|
this.writeOPHASH();
|
|
1173
|
-
|
|
1174
|
-
this.textGenerator.generateSync(node.value, TextFormat.bitmarkMinusMinus);
|
|
1175
|
-
}
|
|
1188
|
+
this.writeTextOrValue(node.value, this.tagTextFormat, TextLocation.tag);
|
|
1176
1189
|
this.writeCL();
|
|
1177
1190
|
}
|
|
1178
1191
|
// bitmarkAst -> bits -> bitsValue -> cardNode -> table -> data -> dataValue
|
|
@@ -1182,7 +1195,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1182
1195
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.table && (parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.pronunciationTable)
|
|
1183
1196
|
return;
|
|
1184
1197
|
// Ignore cards if not allowed
|
|
1185
|
-
if (!this.isCardAllowed
|
|
1198
|
+
if (!this.isCardAllowed)
|
|
1186
1199
|
return;
|
|
1187
1200
|
this.writeCardSetSideDivider();
|
|
1188
1201
|
}
|
|
@@ -1192,16 +1205,14 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1192
1205
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.table)
|
|
1193
1206
|
return;
|
|
1194
1207
|
this.writeNL();
|
|
1195
|
-
this.
|
|
1208
|
+
this.writeTextOrValue(node.value, this.textFormat, TextLocation.body);
|
|
1196
1209
|
}
|
|
1197
1210
|
// bitmarkAst -> bits -> bitsValue -> cardNode -> table -> data -> dataValue -> dataValueValue
|
|
1198
1211
|
// bitmarkAst -> bits -> bitsValue -> cardNode -> pronunciationTable -> data -> dataValue -> dataValueValue
|
|
1199
1212
|
enter_dataValueValue(node, route) {
|
|
1200
|
-
var _a;
|
|
1201
1213
|
const parent = this.getParentNode(route, 3);
|
|
1202
1214
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.table && (parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.pronunciationTable)
|
|
1203
1215
|
return;
|
|
1204
|
-
const textFormat = (_a = this.getTextFormat(route)) !== null && _a !== void 0 ? _a : TextFormat.bitmarkMinusMinus;
|
|
1205
1216
|
if (node.value) {
|
|
1206
1217
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) === NodeType.pronunciationTable) {
|
|
1207
1218
|
// Pronunciation Table
|
|
@@ -1210,16 +1221,16 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1210
1221
|
this.writeNL();
|
|
1211
1222
|
this.writeOP();
|
|
1212
1223
|
this.writeHash();
|
|
1213
|
-
this.
|
|
1224
|
+
this.writeTextOrValue(cell.title, this.tagTextFormat, TextLocation.tag);
|
|
1214
1225
|
this.writeCL();
|
|
1215
1226
|
}
|
|
1216
1227
|
if (cell.audio) {
|
|
1217
1228
|
this.writeNL();
|
|
1218
|
-
this.writeResource(ResourceTag.audio, cell.audio.src);
|
|
1229
|
+
this.writeResource(ResourceTag.audio, cell.audio.audio.src);
|
|
1219
1230
|
}
|
|
1220
1231
|
if (cell.body) {
|
|
1221
1232
|
this.writeNL();
|
|
1222
|
-
this.
|
|
1233
|
+
this.writeTextOrValue(cell.body, this.textFormat, TextLocation.body);
|
|
1223
1234
|
}
|
|
1224
1235
|
// Stop traversal of this branch
|
|
1225
1236
|
return false;
|
|
@@ -1227,10 +1238,9 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1227
1238
|
else {
|
|
1228
1239
|
// Table
|
|
1229
1240
|
this.writeNL();
|
|
1230
|
-
this.
|
|
1241
|
+
this.writeTextOrValue(node.value, this.textFormat, TextLocation.body);
|
|
1231
1242
|
}
|
|
1232
1243
|
}
|
|
1233
|
-
// this.write(node.value);
|
|
1234
1244
|
}
|
|
1235
1245
|
// bitmarkAst -> bits -> bitsValue -> cardNode -> captionDefinitionList
|
|
1236
1246
|
between_captionDefinitionList(_node, _left, _right, route) {
|
|
@@ -1246,7 +1256,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1246
1256
|
return true;
|
|
1247
1257
|
if (node.value) {
|
|
1248
1258
|
this.writeNL();
|
|
1249
|
-
this.
|
|
1259
|
+
this.writeTextOrValue(node.value, this.textFormat, TextLocation.body);
|
|
1250
1260
|
}
|
|
1251
1261
|
// Stop traversal of this branch
|
|
1252
1262
|
return false;
|
|
@@ -1258,7 +1268,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1258
1268
|
return true;
|
|
1259
1269
|
if (node.value) {
|
|
1260
1270
|
this.writeNL();
|
|
1261
|
-
this.
|
|
1271
|
+
this.writeTextOrValue(node.value, this.textFormat, TextLocation.body);
|
|
1262
1272
|
}
|
|
1263
1273
|
// Stop traversal of this branch
|
|
1264
1274
|
return false;
|
|
@@ -1278,7 +1288,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1278
1288
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.definitions)
|
|
1279
1289
|
return;
|
|
1280
1290
|
// Ignore cards if not allowed
|
|
1281
|
-
if (!this.isCardAllowed
|
|
1291
|
+
if (!this.isCardAllowed)
|
|
1282
1292
|
return;
|
|
1283
1293
|
if (right.key === NodeType.definition) {
|
|
1284
1294
|
this.writeCardSetSideDivider();
|
|
@@ -1307,7 +1317,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1307
1317
|
if (ingredient.title != null) {
|
|
1308
1318
|
this.writeNL();
|
|
1309
1319
|
this.writeOPHASH();
|
|
1310
|
-
this.
|
|
1320
|
+
this.writeTextOrValue(ingredient.title, TextFormat.text, TextLocation.tag);
|
|
1311
1321
|
this.writeCL();
|
|
1312
1322
|
// this.writeNL();
|
|
1313
1323
|
}
|
|
@@ -1323,7 +1333,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1323
1333
|
// [!43]
|
|
1324
1334
|
if (ingredient.quantity != null) {
|
|
1325
1335
|
this.writeOPB();
|
|
1326
|
-
this.
|
|
1336
|
+
this.writeTextOrValue(`${ingredient.quantity}`, TextFormat.text, TextLocation.tag);
|
|
1327
1337
|
this.writeCL();
|
|
1328
1338
|
}
|
|
1329
1339
|
// [@unit:kilograms]
|
|
@@ -1357,7 +1367,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1357
1367
|
// item
|
|
1358
1368
|
if (ingredient.item != null) {
|
|
1359
1369
|
this.writeNL();
|
|
1360
|
-
this.
|
|
1370
|
+
this.writeTextOrValue(ingredient.item, this.textFormat, TextLocation.body);
|
|
1361
1371
|
}
|
|
1362
1372
|
// Stop traversal of this branch
|
|
1363
1373
|
return false;
|
|
@@ -1383,7 +1393,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1383
1393
|
return;
|
|
1384
1394
|
this.writeNL();
|
|
1385
1395
|
this.writeOPB();
|
|
1386
|
-
this.
|
|
1396
|
+
this.writeTextOrValue(node.value, TextFormat.text, TextLocation.tag);
|
|
1387
1397
|
this.writeCL();
|
|
1388
1398
|
}
|
|
1389
1399
|
// bitmarkAst -> bits -> bitsValue -> cardNode -> botResponses -> botResponsesValue -> reaction
|
|
@@ -1403,10 +1413,10 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1403
1413
|
const parent = this.getParentNode(route);
|
|
1404
1414
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.botResponsesValue)
|
|
1405
1415
|
return;
|
|
1406
|
-
const
|
|
1407
|
-
if (
|
|
1416
|
+
const feedback = node.value;
|
|
1417
|
+
if (feedback) {
|
|
1408
1418
|
this.writeNL();
|
|
1409
|
-
this.
|
|
1419
|
+
this.writeTextOrValue(feedback, this.textFormat, TextLocation.body);
|
|
1410
1420
|
}
|
|
1411
1421
|
}
|
|
1412
1422
|
// bitmarkAst -> bits -> bitsValue -> imagePlaceholder
|
|
@@ -1481,8 +1491,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1481
1491
|
if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.bitsValue)
|
|
1482
1492
|
return true;
|
|
1483
1493
|
// Ensure this is a chapter bit
|
|
1484
|
-
|
|
1485
|
-
if (!Config.isOfBitType(bitType, [BitType.chapter]))
|
|
1494
|
+
if (!Config.isOfBitType(this.bitType, [BitType.chapter]))
|
|
1486
1495
|
return true;
|
|
1487
1496
|
const level = node.value;
|
|
1488
1497
|
const bit = parent === null || parent === void 0 ? void 0 : parent.value;
|
|
@@ -1513,7 +1522,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1513
1522
|
this.writeOP();
|
|
1514
1523
|
for (let i = 0; i < +level; i++)
|
|
1515
1524
|
this.writeHash();
|
|
1516
|
-
this.
|
|
1525
|
+
this.writeTextOrValue(title, this.tagTextFormat, TextLocation.tag);
|
|
1517
1526
|
this.writeCL();
|
|
1518
1527
|
}
|
|
1519
1528
|
// Stop traversal of this branch
|
|
@@ -1533,7 +1542,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1533
1542
|
this.writeOP();
|
|
1534
1543
|
for (let i = 0; i < level; i++)
|
|
1535
1544
|
this.writeHash();
|
|
1536
|
-
this.
|
|
1545
|
+
this.writeTextOrValue(subtitle, this.tagTextFormat, TextLocation.tag);
|
|
1537
1546
|
this.writeCL();
|
|
1538
1547
|
}
|
|
1539
1548
|
// Stop traversal of this branch
|
|
@@ -1557,11 +1566,11 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1557
1566
|
});
|
|
1558
1567
|
if (book.reference) {
|
|
1559
1568
|
this.writeOPRANGLE();
|
|
1560
|
-
this.
|
|
1569
|
+
this.writeTextOrValue(book.reference, TextFormat.text, TextLocation.tag);
|
|
1561
1570
|
this.writeCL();
|
|
1562
1571
|
if (book.referenceEnd) {
|
|
1563
1572
|
this.writeOPRANGLE();
|
|
1564
|
-
this.
|
|
1573
|
+
this.writeTextOrValue(book.referenceEnd, TextFormat.text, TextLocation.tag);
|
|
1565
1574
|
this.writeCL();
|
|
1566
1575
|
}
|
|
1567
1576
|
}
|
|
@@ -1582,11 +1591,11 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1582
1591
|
});
|
|
1583
1592
|
if (bit.reference) {
|
|
1584
1593
|
this.writeOPRANGLE();
|
|
1585
|
-
this.
|
|
1594
|
+
this.writeTextOrValue(bit.reference, TextFormat.text, TextLocation.tag);
|
|
1586
1595
|
this.writeCL();
|
|
1587
1596
|
if (bit.referenceEnd) {
|
|
1588
1597
|
this.writeOPRANGLE();
|
|
1589
|
-
this.
|
|
1598
|
+
this.writeTextOrValue(bit.referenceEnd, TextFormat.text, TextLocation.tag);
|
|
1590
1599
|
this.writeCL();
|
|
1591
1600
|
}
|
|
1592
1601
|
}
|
|
@@ -1597,7 +1606,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1597
1606
|
if (node.value) {
|
|
1598
1607
|
this.writeNL();
|
|
1599
1608
|
this.writeOPDANGLE();
|
|
1600
|
-
this.
|
|
1609
|
+
this.writeTextOrValue(node.value, TextFormat.text, TextLocation.tag);
|
|
1601
1610
|
this.writeCL();
|
|
1602
1611
|
}
|
|
1603
1612
|
}
|
|
@@ -1610,7 +1619,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1610
1619
|
if (!bit.book) {
|
|
1611
1620
|
this.writeNL();
|
|
1612
1621
|
this.writeOPRANGLE();
|
|
1613
|
-
this.
|
|
1622
|
+
this.writeTextOrValue(node.value, TextFormat.text, TextLocation.tag);
|
|
1614
1623
|
this.writeCL();
|
|
1615
1624
|
}
|
|
1616
1625
|
}
|
|
@@ -1624,7 +1633,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1624
1633
|
if (!this.isEmptyText(text)) {
|
|
1625
1634
|
this.writeNL_IfNotChain(route);
|
|
1626
1635
|
this.writeOPQ();
|
|
1627
|
-
this.
|
|
1636
|
+
this.writeTextOrValue(text, this.tagTextFormat, TextLocation.tag);
|
|
1628
1637
|
this.writeCL();
|
|
1629
1638
|
}
|
|
1630
1639
|
// Stop traversal of this branch
|
|
@@ -1637,7 +1646,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1637
1646
|
if (!this.isEmptyText(text)) {
|
|
1638
1647
|
this.writeNL_IfNotChain(route);
|
|
1639
1648
|
this.writeOPB();
|
|
1640
|
-
this.
|
|
1649
|
+
this.writeTextOrValue(text, this.tagTextFormat, TextLocation.tag);
|
|
1641
1650
|
this.writeCL();
|
|
1642
1651
|
}
|
|
1643
1652
|
// Stop traversal of this branch
|
|
@@ -1725,18 +1734,18 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1725
1734
|
this.writeString('example');
|
|
1726
1735
|
this.writeColon();
|
|
1727
1736
|
if (example === true) {
|
|
1728
|
-
this.writeString('true');
|
|
1737
|
+
this.writeString(' true ');
|
|
1729
1738
|
}
|
|
1730
1739
|
else if (example === false) {
|
|
1731
|
-
this.writeString('false');
|
|
1740
|
+
this.writeString(' false ');
|
|
1732
1741
|
}
|
|
1733
1742
|
else if (Array.isArray(example)) {
|
|
1734
1743
|
// TextAst
|
|
1735
|
-
this.
|
|
1744
|
+
this.writeTextOrValue(example, this.tagTextFormat, TextLocation.tag);
|
|
1736
1745
|
}
|
|
1737
1746
|
else {
|
|
1738
1747
|
// String
|
|
1739
|
-
this.
|
|
1748
|
+
this.writeTextOrValue(example, TextFormat.text, TextLocation.tag);
|
|
1740
1749
|
}
|
|
1741
1750
|
this.writeCL();
|
|
1742
1751
|
}
|
|
@@ -1751,7 +1760,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1751
1760
|
leaf_elementsValue(node, _route) {
|
|
1752
1761
|
if (node.value) {
|
|
1753
1762
|
this.writeNL();
|
|
1754
|
-
this.
|
|
1763
|
+
this.writeTextOrValue(node.value, this.textFormat, TextLocation.body);
|
|
1755
1764
|
}
|
|
1756
1765
|
}
|
|
1757
1766
|
// bitmarkAst -> bits -> bitsValue -> body -> bodyValue -> gap -> solutions -> solution
|
|
@@ -1762,7 +1771,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1762
1771
|
return;
|
|
1763
1772
|
if (node.value != null) {
|
|
1764
1773
|
this.writeOPU();
|
|
1765
|
-
this.
|
|
1774
|
+
this.writeTextOrValue(node.value, TextFormat.text, TextLocation.tag);
|
|
1766
1775
|
this.writeCL();
|
|
1767
1776
|
}
|
|
1768
1777
|
}
|
|
@@ -1771,7 +1780,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1771
1780
|
leaf_prefix(node, _route) {
|
|
1772
1781
|
if (node.value) {
|
|
1773
1782
|
this.writeOPPRE();
|
|
1774
|
-
this.
|
|
1783
|
+
this.writeTextOrValue(node.value, TextFormat.text, TextLocation.tag);
|
|
1775
1784
|
this.writeCL();
|
|
1776
1785
|
}
|
|
1777
1786
|
}
|
|
@@ -1780,7 +1789,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1780
1789
|
leaf_postfix(node, _route) {
|
|
1781
1790
|
if (node.value) {
|
|
1782
1791
|
this.writeOPPOST();
|
|
1783
|
-
this.
|
|
1792
|
+
this.writeTextOrValue(node.value, TextFormat.text, TextLocation.tag);
|
|
1784
1793
|
this.writeCL();
|
|
1785
1794
|
}
|
|
1786
1795
|
}
|
|
@@ -1798,21 +1807,21 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1798
1807
|
leaf_forKeys(node, _route) {
|
|
1799
1808
|
this.writeNL();
|
|
1800
1809
|
this.writeOPHASH();
|
|
1801
|
-
this.
|
|
1810
|
+
this.writeTextOrValue(node.value, TextFormat.text, TextLocation.tag);
|
|
1802
1811
|
this.writeCL();
|
|
1803
1812
|
}
|
|
1804
1813
|
// bitmarkAst -> bits -> bitsValue -> heading -> forValues
|
|
1805
1814
|
leaf_forValues(node, _route) {
|
|
1806
1815
|
this.writeNL();
|
|
1807
1816
|
this.writeOPHASH();
|
|
1808
|
-
this.
|
|
1817
|
+
this.writeTextOrValue(node.value, TextFormat.text, TextLocation.tag);
|
|
1809
1818
|
this.writeCL();
|
|
1810
1819
|
}
|
|
1811
1820
|
// bitmarkAst -> bits -> bitsValue -> heading -> forValuesValue
|
|
1812
1821
|
leaf_forValuesValue(node, _route) {
|
|
1813
1822
|
this.writeNL();
|
|
1814
1823
|
this.writeOPHASH();
|
|
1815
|
-
this.
|
|
1824
|
+
this.writeTextOrValue(node.value, TextFormat.text, TextLocation.tag);
|
|
1816
1825
|
this.writeCL();
|
|
1817
1826
|
}
|
|
1818
1827
|
// bitmarkAst -> bits -> bitsValue -> pairs -> pairsValue -> key
|
|
@@ -1820,7 +1829,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1820
1829
|
leaf_key(node, _route) {
|
|
1821
1830
|
if (node.value) {
|
|
1822
1831
|
this.writeNL();
|
|
1823
|
-
this.
|
|
1832
|
+
this.writeTextOrValue(node.value, this.textFormat, TextLocation.body);
|
|
1824
1833
|
}
|
|
1825
1834
|
}
|
|
1826
1835
|
// bitmarkAst -> bits -> bitsValue -> pairs -> pairsValue -> values -> valuesValue
|
|
@@ -1828,7 +1837,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1828
1837
|
leaf_valuesValue(node, _route) {
|
|
1829
1838
|
if (node.value) {
|
|
1830
1839
|
this.writeNL();
|
|
1831
|
-
this.
|
|
1840
|
+
this.writeTextOrValue(node.value, this.textFormat, TextLocation.body);
|
|
1832
1841
|
}
|
|
1833
1842
|
}
|
|
1834
1843
|
// bitmarkAst -> bits -> bitsValue -> questions -> questionsValue -> question
|
|
@@ -1840,7 +1849,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1840
1849
|
return;
|
|
1841
1850
|
if (node.value) {
|
|
1842
1851
|
this.writeNL();
|
|
1843
|
-
this.
|
|
1852
|
+
this.writeTextOrValue(node.value, this.textFormat, TextLocation.body);
|
|
1844
1853
|
}
|
|
1845
1854
|
}
|
|
1846
1855
|
// bitmarkAst -> bits -> bitsValue -> statements -> text
|
|
@@ -1897,9 +1906,8 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
1897
1906
|
ignoreEmpty: true,
|
|
1898
1907
|
});
|
|
1899
1908
|
}
|
|
1900
|
-
leaf_zoomDisabled(node,
|
|
1901
|
-
|
|
1902
|
-
if (Config.isOfBitType(bitType, [
|
|
1909
|
+
leaf_zoomDisabled(node, _route) {
|
|
1910
|
+
if (Config.isOfBitType(this.bitType, [
|
|
1903
1911
|
BitType.imageSeparator,
|
|
1904
1912
|
BitType.pageBanner,
|
|
1905
1913
|
BitType.imagesLogoGrave,
|
|
@@ -2164,8 +2172,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
2164
2172
|
return false;
|
|
2165
2173
|
}
|
|
2166
2174
|
else if (footer.footer && footer.footer.length > 0) {
|
|
2167
|
-
|
|
2168
|
-
if (isBitmarkText) {
|
|
2175
|
+
if (this.isBodyBitmarkText) {
|
|
2169
2176
|
// handle bitmark text
|
|
2170
2177
|
return true;
|
|
2171
2178
|
}
|
|
@@ -2177,17 +2184,108 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
2177
2184
|
}
|
|
2178
2185
|
return false;
|
|
2179
2186
|
}
|
|
2187
|
+
/**
|
|
2188
|
+
* Calculate the number of spaces around values from the options.
|
|
2189
|
+
*
|
|
2190
|
+
* This function should only be called from the constructor.
|
|
2191
|
+
* Otherwise use this.spacesAroundValues.
|
|
2192
|
+
*
|
|
2193
|
+
* @returns
|
|
2194
|
+
*/
|
|
2195
|
+
calcSpacesAroundValues() {
|
|
2196
|
+
const val = this.options.spacesAroundValues;
|
|
2197
|
+
let spaces = DEFAULT_SPACES_AROUND_VALUES;
|
|
2198
|
+
if (val != null) {
|
|
2199
|
+
if (val === true) {
|
|
2200
|
+
spaces = DEFAULT_SPACES_AROUND_VALUES;
|
|
2201
|
+
}
|
|
2202
|
+
else if (val === false) {
|
|
2203
|
+
spaces = 0;
|
|
2204
|
+
}
|
|
2205
|
+
else {
|
|
2206
|
+
spaces = val;
|
|
2207
|
+
}
|
|
2208
|
+
}
|
|
2209
|
+
spaces = Math.min(Math.max(spaces, 0), MAX_SPACES_AROUND_VALUES);
|
|
2210
|
+
return spaces;
|
|
2211
|
+
}
|
|
2180
2212
|
// END UTILITY FUNCTIONS
|
|
2181
2213
|
//
|
|
2182
2214
|
// WRITE FUNCTIONS
|
|
2183
2215
|
//
|
|
2184
|
-
|
|
2216
|
+
/**
|
|
2217
|
+
* Helper function to write a tag key, breakscaping appropriately.
|
|
2218
|
+
* Use only to write a tag key.
|
|
2219
|
+
*
|
|
2220
|
+
* @param s
|
|
2221
|
+
*/
|
|
2222
|
+
writeTagKey(s) {
|
|
2185
2223
|
if (s != null) {
|
|
2186
2224
|
this.write(Breakscape.breakscape(`${s}`, {
|
|
2187
|
-
textFormat: TextFormat.
|
|
2225
|
+
textFormat: TextFormat.text,
|
|
2226
|
+
textLocation: TextLocation.tag,
|
|
2188
2227
|
}));
|
|
2189
2228
|
}
|
|
2190
2229
|
}
|
|
2230
|
+
/**
|
|
2231
|
+
* Write text or value, handling the format and location (i.e. conversion to text and breakscaping).
|
|
2232
|
+
*
|
|
2233
|
+
* @param text
|
|
2234
|
+
* @param format
|
|
2235
|
+
* @param location
|
|
2236
|
+
* @param options
|
|
2237
|
+
*/
|
|
2238
|
+
writeTextOrValue(text, format, location, options) {
|
|
2239
|
+
const isTagValue = location === TextLocation.tag;
|
|
2240
|
+
const s = StringUtils.isString(text) ? text : undefined;
|
|
2241
|
+
const ast = Array.isArray(text) ? text : undefined;
|
|
2242
|
+
const isBitmarkText = format === TextFormat.bitmarkPlusPlus || format === TextFormat.bitmarkMinusMinus;
|
|
2243
|
+
const isPlainText = !isBitmarkText;
|
|
2244
|
+
const spacesAroundValues = isTagValue ? this.spacesAroundValuesStr : '';
|
|
2245
|
+
if (isPlainText) {
|
|
2246
|
+
// Plain text
|
|
2247
|
+
if (s != null) {
|
|
2248
|
+
this.write(`${spacesAroundValues}${Breakscape.breakscape(`${s}`, {
|
|
2249
|
+
textFormat: TextFormat.text,
|
|
2250
|
+
textLocation: location,
|
|
2251
|
+
})}${spacesAroundValues}`);
|
|
2252
|
+
}
|
|
2253
|
+
}
|
|
2254
|
+
else {
|
|
2255
|
+
// Bitmark text (but might not be AST as some values are just strings (and all v2 values are strings))
|
|
2256
|
+
if (s != null) {
|
|
2257
|
+
this.write(`${spacesAroundValues}${Breakscape.breakscape(`${s}`, {
|
|
2258
|
+
textFormat: format,
|
|
2259
|
+
textLocation: location,
|
|
2260
|
+
})}${spacesAroundValues}`);
|
|
2261
|
+
}
|
|
2262
|
+
else if (ast != null) {
|
|
2263
|
+
// When writing a tag value, we don't know if it is empty until we write it, so we need to
|
|
2264
|
+
// write it using the part writer, and then check if it is empty before writing to the main writer.
|
|
2265
|
+
// Body values can be written directly to the main writer.
|
|
2266
|
+
if (isTagValue) {
|
|
2267
|
+
// Change the writer to the part writer
|
|
2268
|
+
this.writer = this.partWriter;
|
|
2269
|
+
this.partWriter.openSync();
|
|
2270
|
+
// Write the text
|
|
2271
|
+
this.textGenerator.generateSync(ast, format, location, options);
|
|
2272
|
+
// Get the written text
|
|
2273
|
+
this.partWriter.closeSync();
|
|
2274
|
+
const text = this.partWriter.getString();
|
|
2275
|
+
// Restore the main writer
|
|
2276
|
+
this.writer = this.mainWriter;
|
|
2277
|
+
// Write the text to the main writer, adding spaces around it where required
|
|
2278
|
+
if (text) {
|
|
2279
|
+
this.write(`${spacesAroundValues}${text.trim()}${spacesAroundValues}`);
|
|
2280
|
+
}
|
|
2281
|
+
}
|
|
2282
|
+
else {
|
|
2283
|
+
// Write the text directly to the main writer
|
|
2284
|
+
this.textGenerator.generateSync(ast, format, location, options);
|
|
2285
|
+
}
|
|
2286
|
+
}
|
|
2287
|
+
}
|
|
2288
|
+
}
|
|
2191
2289
|
writeString(s) {
|
|
2192
2290
|
if (s != null)
|
|
2193
2291
|
this.write(`${s}`);
|
|
@@ -2256,8 +2354,14 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
2256
2354
|
this.write('[');
|
|
2257
2355
|
}
|
|
2258
2356
|
writeCL() {
|
|
2259
|
-
// HACK to fix breakscaping when string ends with a ^ (must add a space)
|
|
2260
|
-
|
|
2357
|
+
// HACK to fix breakscaping when string ends with a ^ (must add a space) if
|
|
2358
|
+
// options.spacesAroundValues is 0
|
|
2359
|
+
if (this.spacesAroundValues === 0) {
|
|
2360
|
+
this.writer.getLastWrite().endsWith('^') ? this.write(' ]') : this.write(']');
|
|
2361
|
+
}
|
|
2362
|
+
else {
|
|
2363
|
+
this.write(']');
|
|
2364
|
+
}
|
|
2261
2365
|
}
|
|
2262
2366
|
writeAmpersand() {
|
|
2263
2367
|
this.write('&');
|
|
@@ -2271,6 +2375,9 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
2271
2375
|
writeHash() {
|
|
2272
2376
|
this.write('#');
|
|
2273
2377
|
}
|
|
2378
|
+
writeSpacesAroundValues() {
|
|
2379
|
+
this.write(this.spacesAroundValuesStr);
|
|
2380
|
+
}
|
|
2274
2381
|
writePlainTextDivider() {
|
|
2275
2382
|
this.writeNL();
|
|
2276
2383
|
this.write('==== text ====');
|
|
@@ -2340,9 +2447,9 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
2340
2447
|
const resourceData = resource[resourceTag];
|
|
2341
2448
|
const src = resourceData ? resourceData.src || resourceData.url || resourceData.body || '' : '';
|
|
2342
2449
|
this.writeOPA();
|
|
2343
|
-
this.
|
|
2450
|
+
this.writeTagKey(key);
|
|
2344
2451
|
this.writeColon();
|
|
2345
|
-
this.
|
|
2452
|
+
this.writeTextOrValue(src, TextFormat.text, TextLocation.tag);
|
|
2346
2453
|
if (resource.type === ResourceTag.article) {
|
|
2347
2454
|
// this.writeNL();
|
|
2348
2455
|
}
|
|
@@ -2354,9 +2461,9 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
2354
2461
|
if (type) {
|
|
2355
2462
|
// Standard case
|
|
2356
2463
|
this.writeOPAMP();
|
|
2357
|
-
this.
|
|
2464
|
+
this.writeTagKey(type);
|
|
2358
2465
|
this.writeColon();
|
|
2359
|
-
this.
|
|
2466
|
+
this.writeTextOrValue(value, TextFormat.text, TextLocation.tag);
|
|
2360
2467
|
if (type === ResourceTag.article) {
|
|
2361
2468
|
// this.writeNL();
|
|
2362
2469
|
}
|
|
@@ -2373,9 +2480,9 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
2373
2480
|
if (options.ignoreEmpty && isBitmarkText && this.isEmptyText(values))
|
|
2374
2481
|
return;
|
|
2375
2482
|
this.writeOPA();
|
|
2376
|
-
this.
|
|
2483
|
+
this.writeTagKey(name);
|
|
2377
2484
|
this.writeColon();
|
|
2378
|
-
this.
|
|
2485
|
+
this.writeTextOrValue(values, (_a = TextFormat.fromValue(options.format)) !== null && _a !== void 0 ? _a : TextFormat.bitmarkMinusMinus, TextLocation.tag);
|
|
2379
2486
|
this.writeCL();
|
|
2380
2487
|
}
|
|
2381
2488
|
else {
|
|
@@ -2398,9 +2505,9 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
2398
2505
|
if (options.ignoreEmpty && val === '')
|
|
2399
2506
|
continue;
|
|
2400
2507
|
this.writeOPA();
|
|
2401
|
-
this.
|
|
2508
|
+
this.writeTagKey(name);
|
|
2402
2509
|
this.writeColon();
|
|
2403
|
-
this.
|
|
2510
|
+
this.writeTextOrValue(`${val}`, TextFormat.text, TextLocation.tag);
|
|
2404
2511
|
this.writeCL();
|
|
2405
2512
|
// propertyIndex++;
|
|
2406
2513
|
}
|
|
@@ -2437,35 +2544,14 @@ class BitmarkGenerator extends AstWalkerGenerator {
|
|
|
2437
2544
|
const writeFormat = !isDefault || this.options.explicitTextFormat;
|
|
2438
2545
|
return !!writeFormat;
|
|
2439
2546
|
}
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
if (node.key === NodeType.bitsValue) {
|
|
2443
|
-
const n = node.value;
|
|
2444
|
-
return n === null || n === void 0 ? void 0 : n.textFormat;
|
|
2445
|
-
}
|
|
2446
|
-
}
|
|
2447
|
-
return undefined;
|
|
2448
|
-
}
|
|
2449
|
-
isCardAllowed(route) {
|
|
2450
|
-
const textFormat = this.getTextFormat(route);
|
|
2451
|
-
const isBitmarkText = textFormat === TextFormat.bitmarkMinusMinus || textFormat === TextFormat.bitmarkPlusPlus;
|
|
2452
|
-
return isBitmarkText && !this.isOfBitType1(route);
|
|
2547
|
+
calculateIsCardAllowed() {
|
|
2548
|
+
return this.isBodyBitmarkText && !this.isOfBitType1();
|
|
2453
2549
|
}
|
|
2454
|
-
isOfBitType1(
|
|
2455
|
-
return this.isOfBitType(
|
|
2550
|
+
isOfBitType1() {
|
|
2551
|
+
return this.isOfBitType([BitType.trueFalse1, BitType.multipleChoice1, BitType.multipleResponse1]);
|
|
2456
2552
|
}
|
|
2457
|
-
isOfBitType(
|
|
2458
|
-
|
|
2459
|
-
return Config.isOfBitType(bt, baseBitType);
|
|
2460
|
-
}
|
|
2461
|
-
getBitType(route) {
|
|
2462
|
-
for (const node of route) {
|
|
2463
|
-
if (node.key === NodeType.bitsValue) {
|
|
2464
|
-
const n = node.value;
|
|
2465
|
-
return n === null || n === void 0 ? void 0 : n.bitType;
|
|
2466
|
-
}
|
|
2467
|
-
}
|
|
2468
|
-
return undefined;
|
|
2553
|
+
isOfBitType(baseBitType) {
|
|
2554
|
+
return Config.isOfBitType(this.bitType, baseBitType);
|
|
2469
2555
|
}
|
|
2470
2556
|
//
|
|
2471
2557
|
// Writer interface
|