@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.
Files changed (168) hide show
  1. package/dist/browser/bitmark-parser-generator.min.js +1 -1
  2. package/dist/browser/bundle-report.html +2 -2
  3. package/dist/cjs/BitmarkParserGenerator.js +10 -2
  4. package/dist/cjs/BitmarkParserGenerator.js.map +1 -1
  5. package/dist/cjs/ast/BaseBuilder.js +4 -0
  6. package/dist/cjs/ast/BaseBuilder.js.map +1 -1
  7. package/dist/cjs/ast/Builder.js +10 -6
  8. package/dist/cjs/ast/Builder.js.map +1 -1
  9. package/dist/cjs/breakscaping/Breakscape.js +185 -128
  10. package/dist/cjs/breakscaping/Breakscape.js.map +1 -1
  11. package/dist/cjs/config/raw/bits.js +1 -0
  12. package/dist/cjs/config/raw/bits.js.map +1 -1
  13. package/dist/cjs/generated/build-info.js +1 -1
  14. package/dist/cjs/generated/parser/text/text-peggy-parser.js +76 -15
  15. package/dist/cjs/generated/parser/text/text-peggy-parser.js.map +1 -1
  16. package/dist/cjs/generator/bitmark/BitmarkGenerator.js +254 -168
  17. package/dist/cjs/generator/bitmark/BitmarkGenerator.js.map +1 -1
  18. package/dist/cjs/generator/json/JsonGenerator.js +10 -7
  19. package/dist/cjs/generator/json/JsonGenerator.js.map +1 -1
  20. package/dist/cjs/generator/text/TextGenerator.js +42 -12
  21. package/dist/cjs/generator/text/TextGenerator.js.map +1 -1
  22. package/dist/cjs/model/enum/BitType.js +1 -0
  23. package/dist/cjs/model/enum/BitType.js.map +1 -1
  24. package/dist/cjs/model/enum/TextFormat.js +16 -7
  25. package/dist/cjs/model/enum/TextFormat.js.map +1 -1
  26. package/dist/cjs/model/enum/TextLocation.js +15 -0
  27. package/dist/cjs/model/enum/TextLocation.js.map +1 -0
  28. package/dist/cjs/parser/bitmark/peg/BitmarkPegParserHelper.js +5 -2
  29. package/dist/cjs/parser/bitmark/peg/BitmarkPegParserHelper.js.map +1 -1
  30. package/dist/cjs/parser/bitmark/peg/BitmarkPegParserProcessor.js +5 -2
  31. package/dist/cjs/parser/bitmark/peg/BitmarkPegParserProcessor.js.map +1 -1
  32. package/dist/cjs/parser/bitmark/peg/contentProcessors/BodyContentProcessor.js +4 -0
  33. package/dist/cjs/parser/bitmark/peg/contentProcessors/BodyContentProcessor.js.map +1 -1
  34. package/dist/cjs/parser/bitmark/peg/contentProcessors/BookChainContentProcessor.js +3 -1
  35. package/dist/cjs/parser/bitmark/peg/contentProcessors/BookChainContentProcessor.js.map +1 -1
  36. package/dist/cjs/parser/bitmark/peg/contentProcessors/CardContentProcessor.js +1 -2
  37. package/dist/cjs/parser/bitmark/peg/contentProcessors/CardContentProcessor.js.map +1 -1
  38. package/dist/cjs/parser/bitmark/peg/contentProcessors/ClozeTagContentProcessor.js +3 -1
  39. package/dist/cjs/parser/bitmark/peg/contentProcessors/ClozeTagContentProcessor.js.map +1 -1
  40. package/dist/cjs/parser/bitmark/peg/contentProcessors/DefaultTagContentProcessor.js +17 -5
  41. package/dist/cjs/parser/bitmark/peg/contentProcessors/DefaultTagContentProcessor.js.map +1 -1
  42. package/dist/cjs/parser/bitmark/peg/contentProcessors/ExampleTagContentProcessor.js +8 -1
  43. package/dist/cjs/parser/bitmark/peg/contentProcessors/ExampleTagContentProcessor.js.map +1 -1
  44. package/dist/cjs/parser/bitmark/peg/contentProcessors/FooterContentProcessor.js +3 -0
  45. package/dist/cjs/parser/bitmark/peg/contentProcessors/FooterContentProcessor.js.map +1 -1
  46. package/dist/cjs/parser/bitmark/peg/contentProcessors/ImageSourceChainContentProcessor.js +3 -1
  47. package/dist/cjs/parser/bitmark/peg/contentProcessors/ImageSourceChainContentProcessor.js.map +1 -1
  48. package/dist/cjs/parser/bitmark/peg/contentProcessors/MarkConfigChainContentProcessor.js +3 -1
  49. package/dist/cjs/parser/bitmark/peg/contentProcessors/MarkConfigChainContentProcessor.js.map +1 -1
  50. package/dist/cjs/parser/bitmark/peg/contentProcessors/MarkTagContentProcessor.js +1 -1
  51. package/dist/cjs/parser/bitmark/peg/contentProcessors/MarkTagContentProcessor.js.map +1 -1
  52. package/dist/cjs/parser/bitmark/peg/contentProcessors/PersonChainContentProcessor.js +4 -2
  53. package/dist/cjs/parser/bitmark/peg/contentProcessors/PersonChainContentProcessor.js.map +1 -1
  54. package/dist/cjs/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.js +11 -5
  55. package/dist/cjs/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.js.map +1 -1
  56. package/dist/cjs/parser/bitmark/peg/contentProcessors/ReferenceTagContentProcessor.js +5 -2
  57. package/dist/cjs/parser/bitmark/peg/contentProcessors/ReferenceTagContentProcessor.js.map +1 -1
  58. package/dist/cjs/parser/bitmark/peg/contentProcessors/ResourceContentProcessor.js +7 -2
  59. package/dist/cjs/parser/bitmark/peg/contentProcessors/ResourceContentProcessor.js.map +1 -1
  60. package/dist/cjs/parser/bitmark/peg/contentProcessors/TechnicalTermChainContentProcessor.js +3 -1
  61. package/dist/cjs/parser/bitmark/peg/contentProcessors/TechnicalTermChainContentProcessor.js.map +1 -1
  62. package/dist/cjs/parser/bitmark/peg/contentProcessors/TrueFalseTagContentProcessor.js +3 -1
  63. package/dist/cjs/parser/bitmark/peg/contentProcessors/TrueFalseTagContentProcessor.js.map +1 -1
  64. package/dist/cjs/parser/text/TextParser.js +0 -15
  65. package/dist/cjs/parser/text/TextParser.js.map +1 -1
  66. package/dist/esm/BitmarkParserGenerator.js +10 -2
  67. package/dist/esm/BitmarkParserGenerator.js.map +1 -1
  68. package/dist/esm/ast/BaseBuilder.js +4 -0
  69. package/dist/esm/ast/BaseBuilder.js.map +1 -1
  70. package/dist/esm/ast/Builder.js +10 -6
  71. package/dist/esm/ast/Builder.js.map +1 -1
  72. package/dist/esm/breakscaping/Breakscape.js +185 -128
  73. package/dist/esm/breakscaping/Breakscape.js.map +1 -1
  74. package/dist/esm/config/raw/bits.js +1 -0
  75. package/dist/esm/config/raw/bits.js.map +1 -1
  76. package/dist/esm/generated/build-info.js +1 -1
  77. package/dist/esm/generated/parser/text/text-peggy-parser.js +76 -15
  78. package/dist/esm/generated/parser/text/text-peggy-parser.js.map +1 -1
  79. package/dist/esm/generator/bitmark/BitmarkGenerator.js +254 -168
  80. package/dist/esm/generator/bitmark/BitmarkGenerator.js.map +1 -1
  81. package/dist/esm/generator/json/JsonGenerator.js +10 -7
  82. package/dist/esm/generator/json/JsonGenerator.js.map +1 -1
  83. package/dist/esm/generator/text/TextGenerator.js +42 -12
  84. package/dist/esm/generator/text/TextGenerator.js.map +1 -1
  85. package/dist/esm/model/enum/BitType.js +1 -0
  86. package/dist/esm/model/enum/BitType.js.map +1 -1
  87. package/dist/esm/model/enum/TextFormat.js +16 -7
  88. package/dist/esm/model/enum/TextFormat.js.map +1 -1
  89. package/dist/esm/model/enum/TextLocation.js +12 -0
  90. package/dist/esm/model/enum/TextLocation.js.map +1 -0
  91. package/dist/esm/parser/bitmark/peg/BitmarkPegParserHelper.js +5 -2
  92. package/dist/esm/parser/bitmark/peg/BitmarkPegParserHelper.js.map +1 -1
  93. package/dist/esm/parser/bitmark/peg/BitmarkPegParserProcessor.js +5 -2
  94. package/dist/esm/parser/bitmark/peg/BitmarkPegParserProcessor.js.map +1 -1
  95. package/dist/esm/parser/bitmark/peg/contentProcessors/BodyContentProcessor.js +4 -0
  96. package/dist/esm/parser/bitmark/peg/contentProcessors/BodyContentProcessor.js.map +1 -1
  97. package/dist/esm/parser/bitmark/peg/contentProcessors/BookChainContentProcessor.js +3 -1
  98. package/dist/esm/parser/bitmark/peg/contentProcessors/BookChainContentProcessor.js.map +1 -1
  99. package/dist/esm/parser/bitmark/peg/contentProcessors/CardContentProcessor.js +1 -2
  100. package/dist/esm/parser/bitmark/peg/contentProcessors/CardContentProcessor.js.map +1 -1
  101. package/dist/esm/parser/bitmark/peg/contentProcessors/ClozeTagContentProcessor.js +3 -1
  102. package/dist/esm/parser/bitmark/peg/contentProcessors/ClozeTagContentProcessor.js.map +1 -1
  103. package/dist/esm/parser/bitmark/peg/contentProcessors/DefaultTagContentProcessor.js +17 -5
  104. package/dist/esm/parser/bitmark/peg/contentProcessors/DefaultTagContentProcessor.js.map +1 -1
  105. package/dist/esm/parser/bitmark/peg/contentProcessors/ExampleTagContentProcessor.js +8 -1
  106. package/dist/esm/parser/bitmark/peg/contentProcessors/ExampleTagContentProcessor.js.map +1 -1
  107. package/dist/esm/parser/bitmark/peg/contentProcessors/FooterContentProcessor.js +3 -0
  108. package/dist/esm/parser/bitmark/peg/contentProcessors/FooterContentProcessor.js.map +1 -1
  109. package/dist/esm/parser/bitmark/peg/contentProcessors/ImageSourceChainContentProcessor.js +3 -1
  110. package/dist/esm/parser/bitmark/peg/contentProcessors/ImageSourceChainContentProcessor.js.map +1 -1
  111. package/dist/esm/parser/bitmark/peg/contentProcessors/MarkConfigChainContentProcessor.js +3 -1
  112. package/dist/esm/parser/bitmark/peg/contentProcessors/MarkConfigChainContentProcessor.js.map +1 -1
  113. package/dist/esm/parser/bitmark/peg/contentProcessors/MarkTagContentProcessor.js +1 -1
  114. package/dist/esm/parser/bitmark/peg/contentProcessors/MarkTagContentProcessor.js.map +1 -1
  115. package/dist/esm/parser/bitmark/peg/contentProcessors/PersonChainContentProcessor.js +4 -2
  116. package/dist/esm/parser/bitmark/peg/contentProcessors/PersonChainContentProcessor.js.map +1 -1
  117. package/dist/esm/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.js +11 -5
  118. package/dist/esm/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.js.map +1 -1
  119. package/dist/esm/parser/bitmark/peg/contentProcessors/ReferenceTagContentProcessor.js +5 -2
  120. package/dist/esm/parser/bitmark/peg/contentProcessors/ReferenceTagContentProcessor.js.map +1 -1
  121. package/dist/esm/parser/bitmark/peg/contentProcessors/ResourceContentProcessor.js +7 -2
  122. package/dist/esm/parser/bitmark/peg/contentProcessors/ResourceContentProcessor.js.map +1 -1
  123. package/dist/esm/parser/bitmark/peg/contentProcessors/TechnicalTermChainContentProcessor.js +3 -1
  124. package/dist/esm/parser/bitmark/peg/contentProcessors/TechnicalTermChainContentProcessor.js.map +1 -1
  125. package/dist/esm/parser/bitmark/peg/contentProcessors/TrueFalseTagContentProcessor.js +3 -1
  126. package/dist/esm/parser/bitmark/peg/contentProcessors/TrueFalseTagContentProcessor.js.map +1 -1
  127. package/dist/esm/parser/text/TextParser.js +0 -15
  128. package/dist/esm/parser/text/TextParser.js.map +1 -1
  129. package/dist/types/BitmarkParserGenerator.d.ts +13 -0
  130. package/dist/types/BitmarkParserGenerator.d.ts.map +1 -1
  131. package/dist/types/ast/BaseBuilder.d.ts.map +1 -1
  132. package/dist/types/ast/Builder.d.ts.map +1 -1
  133. package/dist/types/breakscaping/Breakscape.d.ts +23 -1
  134. package/dist/types/breakscaping/Breakscape.d.ts.map +1 -1
  135. package/dist/types/config/raw/bits.d.ts.map +1 -1
  136. package/dist/types/generated/parser/text/text-peggy-parser.d.ts.map +1 -1
  137. package/dist/types/generator/bitmark/BitmarkGenerator.d.ts +60 -18
  138. package/dist/types/generator/bitmark/BitmarkGenerator.d.ts.map +1 -1
  139. package/dist/types/generator/json/JsonGenerator.d.ts.map +1 -1
  140. package/dist/types/generator/text/TextGenerator.d.ts +9 -2
  141. package/dist/types/generator/text/TextGenerator.d.ts.map +1 -1
  142. package/dist/types/model/enum/BitType.d.ts +2 -0
  143. package/dist/types/model/enum/BitType.d.ts.map +1 -1
  144. package/dist/types/model/enum/TextFormat.d.ts +0 -2
  145. package/dist/types/model/enum/TextFormat.d.ts.map +1 -1
  146. package/dist/types/model/enum/TextLocation.d.ts +16 -0
  147. package/dist/types/model/enum/TextLocation.d.ts.map +1 -0
  148. package/dist/types/model/json/BitJson.d.ts +3 -3
  149. package/dist/types/model/json/BitJson.d.ts.map +1 -1
  150. package/dist/types/parser/bitmark/peg/BitmarkPegParserHelper.d.ts.map +1 -1
  151. package/dist/types/parser/bitmark/peg/BitmarkPegParserProcessor.d.ts.map +1 -1
  152. package/dist/types/parser/bitmark/peg/contentProcessors/BodyContentProcessor.d.ts.map +1 -1
  153. package/dist/types/parser/bitmark/peg/contentProcessors/BookChainContentProcessor.d.ts.map +1 -1
  154. package/dist/types/parser/bitmark/peg/contentProcessors/CardContentProcessor.d.ts.map +1 -1
  155. package/dist/types/parser/bitmark/peg/contentProcessors/ClozeTagContentProcessor.d.ts.map +1 -1
  156. package/dist/types/parser/bitmark/peg/contentProcessors/DefaultTagContentProcessor.d.ts.map +1 -1
  157. package/dist/types/parser/bitmark/peg/contentProcessors/ExampleTagContentProcessor.d.ts.map +1 -1
  158. package/dist/types/parser/bitmark/peg/contentProcessors/FooterContentProcessor.d.ts.map +1 -1
  159. package/dist/types/parser/bitmark/peg/contentProcessors/ImageSourceChainContentProcessor.d.ts.map +1 -1
  160. package/dist/types/parser/bitmark/peg/contentProcessors/MarkConfigChainContentProcessor.d.ts.map +1 -1
  161. package/dist/types/parser/bitmark/peg/contentProcessors/PersonChainContentProcessor.d.ts.map +1 -1
  162. package/dist/types/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.d.ts.map +1 -1
  163. package/dist/types/parser/bitmark/peg/contentProcessors/ReferenceTagContentProcessor.d.ts.map +1 -1
  164. package/dist/types/parser/bitmark/peg/contentProcessors/ResourceContentProcessor.d.ts.map +1 -1
  165. package/dist/types/parser/bitmark/peg/contentProcessors/TechnicalTermChainContentProcessor.d.ts.map +1 -1
  166. package/dist/types/parser/bitmark/peg/contentProcessors/TrueFalseTagContentProcessor.d.ts.map +1 -1
  167. package/dist/types/parser/text/TextParser.d.ts.map +1 -1
  168. package/package.json +1 -1
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.BitmarkGenerator = void 0;
13
13
  const Ast_1 = require("../../ast/Ast");
14
+ const StringWriter_1 = require("../../ast/writer/StringWriter");
14
15
  const Breakscape_1 = require("../../breakscaping/Breakscape");
15
16
  const Config_1 = require("../../config/Config");
16
17
  const NodeType_1 = require("../../model/ast/NodeType");
@@ -22,6 +23,7 @@ const PropertyFormat_1 = require("../../model/enum/PropertyFormat");
22
23
  const PropertyTag_1 = require("../../model/enum/PropertyTag");
23
24
  const ResourceTag_1 = require("../../model/enum/ResourceTag");
24
25
  const TextFormat_1 = require("../../model/enum/TextFormat");
26
+ const TextLocation_1 = require("../../model/enum/TextLocation");
25
27
  const BooleanUtils_1 = require("../../utils/BooleanUtils");
26
28
  const ObjectUtils_1 = require("../../utils/ObjectUtils");
27
29
  const StringUtils_1 = require("../../utils/StringUtils");
@@ -30,6 +32,8 @@ const TextGenerator_1 = require("../text/TextGenerator");
30
32
  const DEFAULT_OPTIONS = {
31
33
  debugGenerationInline: false,
32
34
  };
35
+ const DEFAULT_SPACES_AROUND_VALUES = 1;
36
+ const MAX_SPACES_AROUND_VALUES = 10;
33
37
  /**
34
38
  * Generate bitmark markup from a bitmark AST
35
39
  *
@@ -57,6 +61,11 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
57
61
  super();
58
62
  this.ast = new Ast_1.Ast();
59
63
  // State
64
+ this.bitType = BitType_1.BitType._error;
65
+ this.textFormat = TextFormat_1.TextFormat.bitmarkMinusMinus;
66
+ this.tagTextFormat = TextFormat_1.TextFormat.bitmarkMinusMinus;
67
+ this.isBodyBitmarkText = false;
68
+ this.isCardAllowed = false;
60
69
  this.firstBit = true;
61
70
  this.hasCardSet = false;
62
71
  this.hasFooter = false;
@@ -87,13 +96,18 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
87
96
  }
88
97
  // Calculate the prettify space
89
98
  this.prettifySpace = this.options.prettifyJson === true ? 2 : this.options.prettifyJson || undefined;
99
+ // Calculate the spaces around values
100
+ this.spacesAroundValues = this.calcSpacesAroundValues();
101
+ this.spacesAroundValuesStr = ' '.repeat(this.spacesAroundValues);
90
102
  // Create the text generator
91
103
  this.textGenerator = new TextGenerator_1.TextGenerator(this.bitmarkVersion, {
92
104
  writeCallback: this.write,
93
105
  bodyBitCallback: this.bodyBitCallback,
94
106
  debugGenerationInline: this.debugGenerationInline,
95
107
  });
96
- this.writer = writer;
108
+ this.mainWriter = writer;
109
+ this.partWriter = new StringWriter_1.StringWriter();
110
+ this.writer = this.mainWriter;
97
111
  this.generateResourceHandlers();
98
112
  this.generatePropertyHandlers();
99
113
  }
@@ -132,6 +146,11 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
132
146
  this.writer.closeSync();
133
147
  }
134
148
  resetState() {
149
+ this.bitType = BitType_1.BitType._error;
150
+ this.textFormat = TextFormat_1.TextFormat.bitmarkMinusMinus;
151
+ this.tagTextFormat = TextFormat_1.TextFormat.bitmarkMinusMinus;
152
+ this.isBodyBitmarkText = false;
153
+ this.isCardAllowed = false;
135
154
  this.firstBit = true;
136
155
  this.hasCardSet = false;
137
156
  this.hasFooter = false;
@@ -153,9 +172,24 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
153
172
  // bitmark
154
173
  // bitmarkAst -> bits -> bitsValue
155
174
  enter_bitsValue(node, _route) {
175
+ var _a;
156
176
  const bit = node.value;
157
177
  const bitConfig = Config_1.Config.getBitConfig(bit.bitType);
158
178
  const bitResourcesConfig = Config_1.Config.getBitResourcesConfig(bit.bitType, bit.resourceType);
179
+ // Set state variables
180
+ this.bitType = bit.bitType;
181
+ this.textFormat = (_a = bit.textFormat) !== null && _a !== void 0 ? _a : bitConfig.textFormatDefault;
182
+ this.isBodyBitmarkText =
183
+ this.textFormat === TextFormat_1.TextFormat.bitmarkMinusMinus || this.textFormat === TextFormat_1.TextFormat.bitmarkPlusPlus;
184
+ this.isCardAllowed = this.calculateIsCardAllowed();
185
+ // NOTE:
186
+ // If the bit text format is bitmark++ then the tagTextFormat should be bitmark+, but that is not implemented yet.
187
+ // It works anyhow, and would require a lot of changes to implement.
188
+ // Since this may well change in the future, we will keep the code as is for now.
189
+ this.tagTextFormat =
190
+ this.textFormat === TextFormat_1.TextFormat.bitmarkPlusPlus
191
+ ? TextFormat_1.TextFormat.bitmarkPlusPlus // NOTE: should be bitmarkPlus
192
+ : TextFormat_1.TextFormat.bitmarkMinusMinus;
159
193
  this.hasCardSet = this.haveValidCardSet(bit);
160
194
  this.hasFooter = this.haveValidFooter(bit);
161
195
  // Separate the bits with 3 newlines
@@ -168,12 +202,12 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
168
202
  this.writeOPD(bit.bitLevel);
169
203
  if (bit.isCommented)
170
204
  this.writeString('|');
171
- this.writeBreakscapedTagString(bit.bitType);
205
+ this.writeTagKey(bit.bitType);
172
206
  if (bit.textFormat) {
173
207
  const write = this.isWriteTextFormat(bit.textFormat, bitConfig.textFormatDefault);
174
208
  if (write) {
175
209
  this.writeColon();
176
- this.writeBreakscapedTagString(bit.textFormat);
210
+ this.writeTagKey(bit.textFormat);
177
211
  }
178
212
  }
179
213
  // Use the bitConfig to see if we need to write the resourceType attachment
@@ -196,7 +230,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
196
230
  }
197
231
  if (resourceType) {
198
232
  this.writeAmpersand();
199
- this.writeBreakscapedTagString(resourceType);
233
+ this.writeTagKey(resourceType);
200
234
  }
201
235
  this.writeCL();
202
236
  // this.writeNL();
@@ -370,13 +404,8 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
370
404
  }
371
405
  if (hint != null) {
372
406
  this.writeOPQ();
373
- this.writeBreakscapedTagString(hint);
407
+ this.writeTextOrValue(hint, TextFormat_1.TextFormat.text, TextLocation_1.TextLocation.tag);
374
408
  this.writeCL();
375
- // this.writeProperty('hint', hint, {
376
- // format: PropertyFormat.trimmedString,
377
- // single: true,
378
- // ignoreEmpty: true,
379
- // });
380
409
  }
381
410
  return false;
382
411
  }
@@ -402,7 +431,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
402
431
  });
403
432
  }
404
433
  if (avatarImage) {
405
- this.writeResource(ResourceTag_1.ResourceTag.image, avatarImage.src);
434
+ this.writeResource(ResourceTag_1.ResourceTag.image, avatarImage.image.src);
406
435
  }
407
436
  // Stop traversal of this branch
408
437
  return false;
@@ -416,8 +445,6 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
416
445
  // bitmarkAst -> bits -> bitsValue -> cardNode -> flashcards -> flashcardsValue -> alternativeAnswers ->
417
446
  // -> alternativeAnswersValue -> text
418
447
  enter_text(node, route) {
419
- var _a;
420
- const textFormat = (_a = this.getTextFormat(route)) !== null && _a !== void 0 ? _a : TextFormat_1.TextFormat.bitmarkMinusMinus;
421
448
  const parent = this.getParentNode(route);
422
449
  if (!parent ||
423
450
  (parent.key !== NodeType_1.NodeType.term &&
@@ -430,7 +457,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
430
457
  }
431
458
  if (node.value) {
432
459
  this.writeNL();
433
- this.textGenerator.generateSync(node.value, textFormat);
460
+ this.writeTextOrValue(node.value, this.textFormat, TextLocation_1.TextLocation.body);
434
461
  }
435
462
  // Stop traversal of this branch
436
463
  return false;
@@ -448,11 +475,8 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
448
475
  return true;
449
476
  }
450
477
  if (StringUtils_1.StringUtils.isString(node.value)) {
451
- const str = node.value;
452
478
  this.writeNL();
453
- this.write(Breakscape_1.Breakscape.breakscape(str, {
454
- textFormat: TextFormat_1.TextFormat.text,
455
- }));
479
+ this.writeTextOrValue(node.value, this.textFormat, TextLocation_1.TextLocation.body);
456
480
  }
457
481
  // Stop traversal of this branch
458
482
  return false;
@@ -656,7 +680,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
656
680
  return true; // Will be handled by marginNumber
657
681
  this.writeNL_IfNotChain(route);
658
682
  this.writeOPC();
659
- this.textGenerator.generateSync(item, TextFormat_1.TextFormat.bitmarkMinusMinus);
683
+ this.writeTextOrValue(item, this.tagTextFormat, TextLocation_1.TextLocation.tag);
660
684
  this.writeCL();
661
685
  return true;
662
686
  }
@@ -673,10 +697,10 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
673
697
  return true; // Will be handled by marginNumber
674
698
  this.writeNL_IfNotChain(route);
675
699
  this.writeOPC();
676
- this.textGenerator.generateSync((_d = (_c = parent === null || parent === void 0 ? void 0 : parent.value) === null || _c === void 0 ? void 0 : _c.item) !== null && _d !== void 0 ? _d : '', TextFormat_1.TextFormat.bitmarkMinusMinus);
700
+ 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_1.TextLocation.tag);
677
701
  this.writeCL();
678
702
  this.writeOPC();
679
- this.textGenerator.generateSync(lead, TextFormat_1.TextFormat.bitmarkMinusMinus);
703
+ this.writeTextOrValue(lead, this.tagTextFormat, TextLocation_1.TextLocation.tag);
680
704
  this.writeCL();
681
705
  return true;
682
706
  }
@@ -691,13 +715,13 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
691
715
  return true; // Will be handled by marginNumber
692
716
  this.writeNL_IfNotChain(route);
693
717
  this.writeOPC();
694
- this.textGenerator.generateSync((_c = (_b = parent === null || parent === void 0 ? void 0 : parent.value) === null || _b === void 0 ? void 0 : _b.item) !== null && _c !== void 0 ? _c : '', TextFormat_1.TextFormat.bitmarkMinusMinus);
718
+ 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_1.TextLocation.tag);
695
719
  this.writeCL();
696
720
  this.writeOPC();
697
- this.textGenerator.generateSync((_e = (_d = parent === null || parent === void 0 ? void 0 : parent.value) === null || _d === void 0 ? void 0 : _d.lead) !== null && _e !== void 0 ? _e : '', TextFormat_1.TextFormat.bitmarkMinusMinus);
721
+ 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_1.TextLocation.tag);
698
722
  this.writeCL();
699
723
  this.writeOPC();
700
- this.textGenerator.generateSync(pageNumber !== null && pageNumber !== void 0 ? pageNumber : '', TextFormat_1.TextFormat.bitmarkMinusMinus);
724
+ this.writeTextOrValue(pageNumber !== null && pageNumber !== void 0 ? pageNumber : '', this.tagTextFormat, TextLocation_1.TextLocation.tag);
701
725
  this.writeCL();
702
726
  return true;
703
727
  }
@@ -710,16 +734,16 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
710
734
  return false; // Ignore empty
711
735
  this.writeNL_IfNotChain(route);
712
736
  this.writeOPC();
713
- this.textGenerator.generateSync((_b = (_a = parent === null || parent === void 0 ? void 0 : parent.value) === null || _a === void 0 ? void 0 : _a.item) !== null && _b !== void 0 ? _b : '', TextFormat_1.TextFormat.bitmarkMinusMinus);
737
+ 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_1.TextLocation.tag);
714
738
  this.writeCL();
715
739
  this.writeOPC();
716
- this.textGenerator.generateSync((_d = (_c = parent === null || parent === void 0 ? void 0 : parent.value) === null || _c === void 0 ? void 0 : _c.lead) !== null && _d !== void 0 ? _d : '', TextFormat_1.TextFormat.bitmarkMinusMinus);
740
+ 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_1.TextLocation.tag);
717
741
  this.writeCL();
718
742
  this.writeOPC();
719
- this.textGenerator.generateSync((_f = (_e = parent === null || parent === void 0 ? void 0 : parent.value) === null || _e === void 0 ? void 0 : _e.pageNumber) !== null && _f !== void 0 ? _f : '', TextFormat_1.TextFormat.bitmarkMinusMinus);
743
+ 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_1.TextLocation.tag);
720
744
  this.writeCL();
721
745
  this.writeOPC();
722
- this.textGenerator.generateSync(marginNumber, TextFormat_1.TextFormat.bitmarkMinusMinus);
746
+ this.writeTextOrValue(marginNumber, this.tagTextFormat, TextLocation_1.TextLocation.tag);
723
747
  this.writeCL();
724
748
  return true;
725
749
  }
@@ -733,29 +757,25 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
733
757
  this.inTag = false;
734
758
  // Always write a NL before the body content if there is any (see Handle body)
735
759
  const body = node.value;
736
- const textFormat = this.getTextFormat(route);
737
- const isBitmarkText = textFormat === TextFormat_1.TextFormat.bitmarkPlusPlus || textFormat === TextFormat_1.TextFormat.bitmarkMinusMinus;
738
760
  // Handle body
739
- if (textFormat === TextFormat_1.TextFormat.json) {
761
+ if (this.textFormat === TextFormat_1.TextFormat.json) {
740
762
  const json = (_a = body.body) !== null && _a !== void 0 ? _a : null;
741
763
  if (Array.isArray(json) || ObjectUtils_1.ObjectUtils.isObject(json)) {
742
764
  const text = JSON.stringify(json, null, this.prettifySpace);
743
765
  if (text) {
744
766
  this.writePlainTextDivider();
745
767
  this.writeNL();
746
- this.write(Breakscape_1.Breakscape.breakscape(text, {
747
- textFormat: TextFormat_1.TextFormat.text,
748
- }));
768
+ this.writeTextOrValue(text, TextFormat_1.TextFormat.text, TextLocation_1.TextLocation.body);
749
769
  }
750
770
  }
751
771
  }
752
- else if (isBitmarkText) {
772
+ else if (this.isBodyBitmarkText) {
753
773
  // handle bitmark text
754
774
  const plainTextDividerAllowed = !(this.hasCardSet || this.hasFooter);
755
775
  this.writeNL();
756
776
  // The text generator will write to the writer
757
777
  const b = (Array.isArray(body.body) ? body.body : []);
758
- this.textGenerator.generateSync(b, textFormat, {
778
+ this.writeTextOrValue(b, this.textFormat, TextLocation_1.TextLocation.body, {
759
779
  plainTextDividerAllowed,
760
780
  });
761
781
  }
@@ -764,9 +784,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
764
784
  this.writePlainTextDivider();
765
785
  this.writeNL();
766
786
  const s = (StringUtils_1.StringUtils.isString(body.body) ? body.body : '');
767
- this.write(Breakscape_1.Breakscape.breakscape(`${s}`, {
768
- textFormat: TextFormat_1.TextFormat.text,
769
- }));
787
+ this.writeTextOrValue(`${s}`, TextFormat_1.TextFormat.text, TextLocation_1.TextLocation.body);
770
788
  }
771
789
  // Stop traversal of this branch
772
790
  return false;
@@ -793,7 +811,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
793
811
  else {
794
812
  for (const solution of gap.solutions) {
795
813
  this.writeOPU();
796
- this.writeBreakscapedTagString(solution);
814
+ this.writeTextOrValue(solution, TextFormat_1.TextFormat.text, TextLocation_1.TextLocation.tag);
797
815
  this.writeCL();
798
816
  }
799
817
  }
@@ -804,7 +822,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
804
822
  enter_mark(node, _route) {
805
823
  const mark = node.value;
806
824
  this.writeOPE();
807
- this.writeBreakscapedTagString(mark.solution);
825
+ this.writeTextOrValue(mark.solution, TextFormat_1.TextFormat.text, TextLocation_1.TextLocation.tag);
808
826
  this.writeCL();
809
827
  // Continue traversal
810
828
  return true;
@@ -825,21 +843,19 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
825
843
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.bitsValue)
826
844
  return true;
827
845
  const footer = node.value;
828
- const textFormat = this.getTextFormat(route);
829
846
  // Handle footer
830
- if (textFormat === TextFormat_1.TextFormat.json) {
847
+ if (this.textFormat === TextFormat_1.TextFormat.json) {
831
848
  // Json footer?!
832
849
  // Not valid, ignore
833
850
  }
834
851
  else if (footer.footer && footer.footer.length > 0) {
835
- const isBitmarkText = textFormat === TextFormat_1.TextFormat.bitmarkPlusPlus || textFormat === TextFormat_1.TextFormat.bitmarkMinusMinus;
836
- if (isBitmarkText) {
852
+ if (this.isBodyBitmarkText) {
837
853
  // handle bitmark text
838
854
  this.writeNL();
839
- this.write('==== footer ====');
855
+ this.writeTextOrValue('==== footer ====', TextFormat_1.TextFormat.text, TextLocation_1.TextLocation.body);
840
856
  this.writeNL();
841
857
  // The text generator will write to the writer
842
- this.textGenerator.generateSync(footer.footer, textFormat, {
858
+ this.writeTextOrValue(footer.footer, this.textFormat, TextLocation_1.TextLocation.body, {
843
859
  plainTextDividerAllowed: true, // Always allowed for the footer.
844
860
  });
845
861
  }
@@ -878,7 +894,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
878
894
  return;
879
895
  if (solution) {
880
896
  this.writeOPE();
881
- this.writeBreakscapedTagString(solution);
897
+ this.writeTextOrValue(solution, TextFormat_1.TextFormat.text, TextLocation_1.TextLocation.tag);
882
898
  this.writeCL();
883
899
  }
884
900
  }
@@ -905,7 +921,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
905
921
  else {
906
922
  this.writeOPM();
907
923
  }
908
- this.write(selectOption.text);
924
+ this.writeTextOrValue(selectOption.text, TextFormat_1.TextFormat.text, TextLocation_1.TextLocation.tag);
909
925
  this.writeCL();
910
926
  // Continue traversal
911
927
  return true;
@@ -919,29 +935,29 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
919
935
  else {
920
936
  this.writeOPM();
921
937
  }
922
- this.write(highlightText.text);
938
+ this.writeTextOrValue(highlightText.text, TextFormat_1.TextFormat.text, TextLocation_1.TextLocation.tag);
923
939
  this.writeCL();
924
940
  // Continue traversal
925
941
  return true;
926
942
  }
927
943
  // bitmarkAst -> bits -> bitsValue -> cardNode
928
- enter_cardNode(_node, route) {
944
+ enter_cardNode(_node, _route) {
929
945
  // Ignore cards if not allowed
930
- if (!this.isCardAllowed(route))
946
+ if (!this.isCardAllowed)
931
947
  return true;
932
948
  this.writeCardSetStart();
933
949
  // Continue traversal
934
950
  return true;
935
951
  }
936
- between_cardNode(_node, _left, _right, route) {
952
+ between_cardNode(_node, _left, _right, _route) {
937
953
  // Ignore cards if not allowed
938
- if (!this.isCardAllowed(route))
954
+ if (!this.isCardAllowed)
939
955
  return;
940
956
  this.writeCardSetCardDivider();
941
957
  }
942
- exit_cardNode(_node, route) {
958
+ exit_cardNode(_node, _route) {
943
959
  // Ignore cards if not allowed
944
- if (!this.isCardAllowed(route))
960
+ if (!this.isCardAllowed)
945
961
  return;
946
962
  this.writeCardSetEnd();
947
963
  if (this.options.cardSetVersion === CardSetVersion_1.CardSetVersion.v1) {
@@ -960,10 +976,10 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
960
976
  this.writeCardSetCardDivider();
961
977
  }
962
978
  // bitmarkAst -> bits -> bitsValue -> cardNode -> flashcards -> flashcardsValue
963
- between_flashcardsValue(_node, _left, right, route) {
979
+ between_flashcardsValue(_node, _left, right, _route) {
964
980
  var _a;
965
981
  // Ignore cards if not allowed
966
- if (!this.isCardAllowed(route))
982
+ if (!this.isCardAllowed)
967
983
  return;
968
984
  if (right.key === NodeType_1.NodeType.answer) {
969
985
  this.writeCardSetSideDivider();
@@ -984,8 +1000,8 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
984
1000
  enter_statements(_node, _route) {
985
1001
  //
986
1002
  }
987
- between_statements(_node, _left, _right, route) {
988
- const isTrueFalse1 = this.isOfBitType(route, BitType_1.BitType.trueFalse1);
1003
+ between_statements(_node, _left, _right, _route) {
1004
+ const isTrueFalse1 = this.isOfBitType(BitType_1.BitType.trueFalse1);
989
1005
  if (!isTrueFalse1) {
990
1006
  this.writeCardSetCardDivider();
991
1007
  }
@@ -1000,7 +1016,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1000
1016
  else {
1001
1017
  this.writeOPM();
1002
1018
  }
1003
- this.write(statement.statement);
1019
+ this.writeTextOrValue(statement.statement, TextFormat_1.TextFormat.text, TextLocation_1.TextLocation.tag);
1004
1020
  this.writeCL();
1005
1021
  // Continue traversal
1006
1022
  return true;
@@ -1017,7 +1033,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1017
1033
  else {
1018
1034
  this.writeOPM();
1019
1035
  }
1020
- this.write(choice.choice);
1036
+ this.writeTextOrValue(choice.choice, TextFormat_1.TextFormat.text, TextLocation_1.TextLocation.tag);
1021
1037
  this.writeCL();
1022
1038
  // Continue traversal
1023
1039
  return true;
@@ -1033,7 +1049,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1033
1049
  else {
1034
1050
  this.writeOPM();
1035
1051
  }
1036
- this.write(response.response);
1052
+ this.writeTextOrValue(response.response, TextFormat_1.TextFormat.text, TextLocation_1.TextLocation.tag);
1037
1053
  this.writeCL();
1038
1054
  // Continue traversal
1039
1055
  return true;
@@ -1059,9 +1075,9 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1059
1075
  enter_heading(_node, _route) {
1060
1076
  //
1061
1077
  }
1062
- between_heading(_node, _left, _right, route) {
1078
+ between_heading(_node, _left, _right, _route) {
1063
1079
  // Ignore cards if not allowed
1064
- if (!this.isCardAllowed(route))
1080
+ if (!this.isCardAllowed)
1065
1081
  return;
1066
1082
  this.writeCardSetSideDivider();
1067
1083
  }
@@ -1069,9 +1085,9 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1069
1085
  enter_forValues(_node, _route) {
1070
1086
  //
1071
1087
  }
1072
- between_forValues(_node, _left, _right, route) {
1088
+ between_forValues(_node, _left, _right, _route) {
1073
1089
  // Ignore cards if not allowed
1074
- if (!this.isCardAllowed(route))
1090
+ if (!this.isCardAllowed)
1075
1091
  return;
1076
1092
  this.writeCardSetSideDivider();
1077
1093
  }
@@ -1109,15 +1125,15 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1109
1125
  }
1110
1126
  // bitmarkAst -> bits -> bitsValue -> cardNode -> pairs -> pairsValue -> values
1111
1127
  // bitmarkAst -> bits -> bitsValue -> cardNode -> matrix -> matrixValue -> cells -> cellsValue -> values
1112
- enter_values(_node, route) {
1128
+ enter_values(_node, _route) {
1113
1129
  // Ignore cards if not allowed
1114
- if (!this.isCardAllowed(route))
1130
+ if (!this.isCardAllowed)
1115
1131
  return;
1116
1132
  this.writeCardSetSideDivider();
1117
1133
  }
1118
- between_values(_node, _left, _right, route) {
1134
+ between_values(_node, _left, _right, _route) {
1119
1135
  // Ignore cards if not allowed
1120
- if (!this.isCardAllowed(route))
1136
+ if (!this.isCardAllowed)
1121
1137
  return;
1122
1138
  this.writeCardSetVariantDivider();
1123
1139
  }
@@ -1127,7 +1143,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1127
1143
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.cardNode)
1128
1144
  return;
1129
1145
  // Ignore cards if not allowed
1130
- if (!this.isCardAllowed(route))
1146
+ if (!this.isCardAllowed)
1131
1147
  return;
1132
1148
  this.writeCardSetCardDivider();
1133
1149
  }
@@ -1137,7 +1153,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1137
1153
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.cardNode)
1138
1154
  return;
1139
1155
  // Ignore cards if not allowed
1140
- if (!this.isCardAllowed(route))
1156
+ if (!this.isCardAllowed)
1141
1157
  return;
1142
1158
  this.writeCardSetCardDivider();
1143
1159
  }
@@ -1157,7 +1173,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1157
1173
  if (parentKey !== NodeType_1.NodeType.table && parentKey !== NodeType_1.NodeType.captionDefinitionList)
1158
1174
  return;
1159
1175
  // Ignore cards if not allowed
1160
- if (!this.isCardAllowed(route))
1176
+ if (!this.isCardAllowed)
1161
1177
  return;
1162
1178
  this.writeCardSetSideDivider();
1163
1179
  }
@@ -1166,16 +1182,13 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1166
1182
  leaf_columnsValue(node, _route) {
1167
1183
  this.writeNL();
1168
1184
  this.writeOPHASH();
1169
- if (node.value)
1170
- this.writeBreakscapedTagString(node.value);
1185
+ this.writeTextOrValue(node.value, TextFormat_1.TextFormat.text, TextLocation_1.TextLocation.tag);
1171
1186
  this.writeCL();
1172
1187
  }
1173
1188
  enter_columnsValue(node, _route) {
1174
1189
  this.writeNL();
1175
1190
  this.writeOPHASH();
1176
- if (node.value) {
1177
- this.textGenerator.generateSync(node.value, TextFormat_1.TextFormat.bitmarkMinusMinus);
1178
- }
1191
+ this.writeTextOrValue(node.value, this.tagTextFormat, TextLocation_1.TextLocation.tag);
1179
1192
  this.writeCL();
1180
1193
  }
1181
1194
  // bitmarkAst -> bits -> bitsValue -> cardNode -> table -> data -> dataValue
@@ -1185,7 +1198,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1185
1198
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.table && (parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.pronunciationTable)
1186
1199
  return;
1187
1200
  // Ignore cards if not allowed
1188
- if (!this.isCardAllowed(route))
1201
+ if (!this.isCardAllowed)
1189
1202
  return;
1190
1203
  this.writeCardSetSideDivider();
1191
1204
  }
@@ -1195,16 +1208,14 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1195
1208
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.table)
1196
1209
  return;
1197
1210
  this.writeNL();
1198
- this.write(node.value);
1211
+ this.writeTextOrValue(node.value, this.textFormat, TextLocation_1.TextLocation.body);
1199
1212
  }
1200
1213
  // bitmarkAst -> bits -> bitsValue -> cardNode -> table -> data -> dataValue -> dataValueValue
1201
1214
  // bitmarkAst -> bits -> bitsValue -> cardNode -> pronunciationTable -> data -> dataValue -> dataValueValue
1202
1215
  enter_dataValueValue(node, route) {
1203
- var _a;
1204
1216
  const parent = this.getParentNode(route, 3);
1205
1217
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.table && (parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.pronunciationTable)
1206
1218
  return;
1207
- const textFormat = (_a = this.getTextFormat(route)) !== null && _a !== void 0 ? _a : TextFormat_1.TextFormat.bitmarkMinusMinus;
1208
1219
  if (node.value) {
1209
1220
  if ((parent === null || parent === void 0 ? void 0 : parent.key) === NodeType_1.NodeType.pronunciationTable) {
1210
1221
  // Pronunciation Table
@@ -1213,16 +1224,16 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1213
1224
  this.writeNL();
1214
1225
  this.writeOP();
1215
1226
  this.writeHash();
1216
- this.textGenerator.generateSync(cell.title, TextFormat_1.TextFormat.bitmarkMinusMinus);
1227
+ this.writeTextOrValue(cell.title, this.tagTextFormat, TextLocation_1.TextLocation.tag);
1217
1228
  this.writeCL();
1218
1229
  }
1219
1230
  if (cell.audio) {
1220
1231
  this.writeNL();
1221
- this.writeResource(ResourceTag_1.ResourceTag.audio, cell.audio.src);
1232
+ this.writeResource(ResourceTag_1.ResourceTag.audio, cell.audio.audio.src);
1222
1233
  }
1223
1234
  if (cell.body) {
1224
1235
  this.writeNL();
1225
- this.textGenerator.generateSync(cell.body, textFormat);
1236
+ this.writeTextOrValue(cell.body, this.textFormat, TextLocation_1.TextLocation.body);
1226
1237
  }
1227
1238
  // Stop traversal of this branch
1228
1239
  return false;
@@ -1230,10 +1241,9 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1230
1241
  else {
1231
1242
  // Table
1232
1243
  this.writeNL();
1233
- this.textGenerator.generateSync(node.value, textFormat);
1244
+ this.writeTextOrValue(node.value, this.textFormat, TextLocation_1.TextLocation.body);
1234
1245
  }
1235
1246
  }
1236
- // this.write(node.value);
1237
1247
  }
1238
1248
  // bitmarkAst -> bits -> bitsValue -> cardNode -> captionDefinitionList
1239
1249
  between_captionDefinitionList(_node, _left, _right, route) {
@@ -1249,7 +1259,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1249
1259
  return true;
1250
1260
  if (node.value) {
1251
1261
  this.writeNL();
1252
- this.write(node.value);
1262
+ this.writeTextOrValue(node.value, this.textFormat, TextLocation_1.TextLocation.body);
1253
1263
  }
1254
1264
  // Stop traversal of this branch
1255
1265
  return false;
@@ -1261,7 +1271,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1261
1271
  return true;
1262
1272
  if (node.value) {
1263
1273
  this.writeNL();
1264
- this.write(node.value);
1274
+ this.writeTextOrValue(node.value, this.textFormat, TextLocation_1.TextLocation.body);
1265
1275
  }
1266
1276
  // Stop traversal of this branch
1267
1277
  return false;
@@ -1281,7 +1291,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1281
1291
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.definitions)
1282
1292
  return;
1283
1293
  // Ignore cards if not allowed
1284
- if (!this.isCardAllowed(route))
1294
+ if (!this.isCardAllowed)
1285
1295
  return;
1286
1296
  if (right.key === NodeType_1.NodeType.definition) {
1287
1297
  this.writeCardSetSideDivider();
@@ -1310,7 +1320,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1310
1320
  if (ingredient.title != null) {
1311
1321
  this.writeNL();
1312
1322
  this.writeOPHASH();
1313
- this.writeBreakscapedTagString(ingredient.title);
1323
+ this.writeTextOrValue(ingredient.title, TextFormat_1.TextFormat.text, TextLocation_1.TextLocation.tag);
1314
1324
  this.writeCL();
1315
1325
  // this.writeNL();
1316
1326
  }
@@ -1326,7 +1336,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1326
1336
  // [!43]
1327
1337
  if (ingredient.quantity != null) {
1328
1338
  this.writeOPB();
1329
- this.writeBreakscapedTagString(`${ingredient.quantity}`);
1339
+ this.writeTextOrValue(`${ingredient.quantity}`, TextFormat_1.TextFormat.text, TextLocation_1.TextLocation.tag);
1330
1340
  this.writeCL();
1331
1341
  }
1332
1342
  // [@unit:kilograms]
@@ -1360,7 +1370,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1360
1370
  // item
1361
1371
  if (ingredient.item != null) {
1362
1372
  this.writeNL();
1363
- this.write(ingredient.item);
1373
+ this.writeTextOrValue(ingredient.item, this.textFormat, TextLocation_1.TextLocation.body);
1364
1374
  }
1365
1375
  // Stop traversal of this branch
1366
1376
  return false;
@@ -1386,7 +1396,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1386
1396
  return;
1387
1397
  this.writeNL();
1388
1398
  this.writeOPB();
1389
- this.writeBreakscapedTagString(node.value);
1399
+ this.writeTextOrValue(node.value, TextFormat_1.TextFormat.text, TextLocation_1.TextLocation.tag);
1390
1400
  this.writeCL();
1391
1401
  }
1392
1402
  // bitmarkAst -> bits -> bitsValue -> cardNode -> botResponses -> botResponsesValue -> reaction
@@ -1406,10 +1416,10 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1406
1416
  const parent = this.getParentNode(route);
1407
1417
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.botResponsesValue)
1408
1418
  return;
1409
- const feeback = node.value;
1410
- if (feeback) {
1419
+ const feedback = node.value;
1420
+ if (feedback) {
1411
1421
  this.writeNL();
1412
- this.write(feeback);
1422
+ this.writeTextOrValue(feedback, this.textFormat, TextLocation_1.TextLocation.body);
1413
1423
  }
1414
1424
  }
1415
1425
  // bitmarkAst -> bits -> bitsValue -> imagePlaceholder
@@ -1484,8 +1494,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1484
1494
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.bitsValue)
1485
1495
  return true;
1486
1496
  // Ensure this is a chapter bit
1487
- const bitType = this.getBitType(route);
1488
- if (!Config_1.Config.isOfBitType(bitType, [BitType_1.BitType.chapter]))
1497
+ if (!Config_1.Config.isOfBitType(this.bitType, [BitType_1.BitType.chapter]))
1489
1498
  return true;
1490
1499
  const level = node.value;
1491
1500
  const bit = parent === null || parent === void 0 ? void 0 : parent.value;
@@ -1516,7 +1525,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1516
1525
  this.writeOP();
1517
1526
  for (let i = 0; i < +level; i++)
1518
1527
  this.writeHash();
1519
- this.textGenerator.generateSync(title, TextFormat_1.TextFormat.bitmarkMinusMinus);
1528
+ this.writeTextOrValue(title, this.tagTextFormat, TextLocation_1.TextLocation.tag);
1520
1529
  this.writeCL();
1521
1530
  }
1522
1531
  // Stop traversal of this branch
@@ -1536,7 +1545,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1536
1545
  this.writeOP();
1537
1546
  for (let i = 0; i < level; i++)
1538
1547
  this.writeHash();
1539
- this.textGenerator.generateSync(subtitle, TextFormat_1.TextFormat.bitmarkMinusMinus);
1548
+ this.writeTextOrValue(subtitle, this.tagTextFormat, TextLocation_1.TextLocation.tag);
1540
1549
  this.writeCL();
1541
1550
  }
1542
1551
  // Stop traversal of this branch
@@ -1560,11 +1569,11 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1560
1569
  });
1561
1570
  if (book.reference) {
1562
1571
  this.writeOPRANGLE();
1563
- this.writeBreakscapedTagString(book.reference);
1572
+ this.writeTextOrValue(book.reference, TextFormat_1.TextFormat.text, TextLocation_1.TextLocation.tag);
1564
1573
  this.writeCL();
1565
1574
  if (book.referenceEnd) {
1566
1575
  this.writeOPRANGLE();
1567
- this.writeBreakscapedTagString(book.referenceEnd);
1576
+ this.writeTextOrValue(book.referenceEnd, TextFormat_1.TextFormat.text, TextLocation_1.TextLocation.tag);
1568
1577
  this.writeCL();
1569
1578
  }
1570
1579
  }
@@ -1585,11 +1594,11 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1585
1594
  });
1586
1595
  if (bit.reference) {
1587
1596
  this.writeOPRANGLE();
1588
- this.writeBreakscapedTagString(bit.reference);
1597
+ this.writeTextOrValue(bit.reference, TextFormat_1.TextFormat.text, TextLocation_1.TextLocation.tag);
1589
1598
  this.writeCL();
1590
1599
  if (bit.referenceEnd) {
1591
1600
  this.writeOPRANGLE();
1592
- this.writeBreakscapedTagString(bit.referenceEnd);
1601
+ this.writeTextOrValue(bit.referenceEnd, TextFormat_1.TextFormat.text, TextLocation_1.TextLocation.tag);
1593
1602
  this.writeCL();
1594
1603
  }
1595
1604
  }
@@ -1600,7 +1609,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1600
1609
  if (node.value) {
1601
1610
  this.writeNL();
1602
1611
  this.writeOPDANGLE();
1603
- this.writeBreakscapedTagString(node.value);
1612
+ this.writeTextOrValue(node.value, TextFormat_1.TextFormat.text, TextLocation_1.TextLocation.tag);
1604
1613
  this.writeCL();
1605
1614
  }
1606
1615
  }
@@ -1613,7 +1622,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1613
1622
  if (!bit.book) {
1614
1623
  this.writeNL();
1615
1624
  this.writeOPRANGLE();
1616
- this.writeBreakscapedTagString(node.value);
1625
+ this.writeTextOrValue(node.value, TextFormat_1.TextFormat.text, TextLocation_1.TextLocation.tag);
1617
1626
  this.writeCL();
1618
1627
  }
1619
1628
  }
@@ -1627,7 +1636,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1627
1636
  if (!this.isEmptyText(text)) {
1628
1637
  this.writeNL_IfNotChain(route);
1629
1638
  this.writeOPQ();
1630
- this.textGenerator.generateSync(text, TextFormat_1.TextFormat.bitmarkMinusMinus);
1639
+ this.writeTextOrValue(text, this.tagTextFormat, TextLocation_1.TextLocation.tag);
1631
1640
  this.writeCL();
1632
1641
  }
1633
1642
  // Stop traversal of this branch
@@ -1640,7 +1649,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1640
1649
  if (!this.isEmptyText(text)) {
1641
1650
  this.writeNL_IfNotChain(route);
1642
1651
  this.writeOPB();
1643
- this.textGenerator.generateSync(text, TextFormat_1.TextFormat.bitmarkMinusMinus);
1652
+ this.writeTextOrValue(text, this.tagTextFormat, TextLocation_1.TextLocation.tag);
1644
1653
  this.writeCL();
1645
1654
  }
1646
1655
  // Stop traversal of this branch
@@ -1728,18 +1737,18 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1728
1737
  this.writeString('example');
1729
1738
  this.writeColon();
1730
1739
  if (example === true) {
1731
- this.writeString('true');
1740
+ this.writeString(' true ');
1732
1741
  }
1733
1742
  else if (example === false) {
1734
- this.writeString('false');
1743
+ this.writeString(' false ');
1735
1744
  }
1736
1745
  else if (Array.isArray(example)) {
1737
1746
  // TextAst
1738
- this.textGenerator.generateSync(example, TextFormat_1.TextFormat.bitmarkMinusMinus);
1747
+ this.writeTextOrValue(example, this.tagTextFormat, TextLocation_1.TextLocation.tag);
1739
1748
  }
1740
1749
  else {
1741
1750
  // String
1742
- this.writeBreakscapedTagString(example);
1751
+ this.writeTextOrValue(example, TextFormat_1.TextFormat.text, TextLocation_1.TextLocation.tag);
1743
1752
  }
1744
1753
  this.writeCL();
1745
1754
  }
@@ -1754,7 +1763,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1754
1763
  leaf_elementsValue(node, _route) {
1755
1764
  if (node.value) {
1756
1765
  this.writeNL();
1757
- this.writeBreakscapedTagString(node.value);
1766
+ this.writeTextOrValue(node.value, this.textFormat, TextLocation_1.TextLocation.body);
1758
1767
  }
1759
1768
  }
1760
1769
  // bitmarkAst -> bits -> bitsValue -> body -> bodyValue -> gap -> solutions -> solution
@@ -1765,7 +1774,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1765
1774
  return;
1766
1775
  if (node.value != null) {
1767
1776
  this.writeOPU();
1768
- this.writeBreakscapedTagString(node.value);
1777
+ this.writeTextOrValue(node.value, TextFormat_1.TextFormat.text, TextLocation_1.TextLocation.tag);
1769
1778
  this.writeCL();
1770
1779
  }
1771
1780
  }
@@ -1774,7 +1783,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1774
1783
  leaf_prefix(node, _route) {
1775
1784
  if (node.value) {
1776
1785
  this.writeOPPRE();
1777
- this.writeBreakscapedTagString(node.value);
1786
+ this.writeTextOrValue(node.value, TextFormat_1.TextFormat.text, TextLocation_1.TextLocation.tag);
1778
1787
  this.writeCL();
1779
1788
  }
1780
1789
  }
@@ -1783,7 +1792,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1783
1792
  leaf_postfix(node, _route) {
1784
1793
  if (node.value) {
1785
1794
  this.writeOPPOST();
1786
- this.writeBreakscapedTagString(node.value);
1795
+ this.writeTextOrValue(node.value, TextFormat_1.TextFormat.text, TextLocation_1.TextLocation.tag);
1787
1796
  this.writeCL();
1788
1797
  }
1789
1798
  }
@@ -1801,21 +1810,21 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1801
1810
  leaf_forKeys(node, _route) {
1802
1811
  this.writeNL();
1803
1812
  this.writeOPHASH();
1804
- this.writeBreakscapedTagString(node.value);
1813
+ this.writeTextOrValue(node.value, TextFormat_1.TextFormat.text, TextLocation_1.TextLocation.tag);
1805
1814
  this.writeCL();
1806
1815
  }
1807
1816
  // bitmarkAst -> bits -> bitsValue -> heading -> forValues
1808
1817
  leaf_forValues(node, _route) {
1809
1818
  this.writeNL();
1810
1819
  this.writeOPHASH();
1811
- this.writeBreakscapedTagString(node.value);
1820
+ this.writeTextOrValue(node.value, TextFormat_1.TextFormat.text, TextLocation_1.TextLocation.tag);
1812
1821
  this.writeCL();
1813
1822
  }
1814
1823
  // bitmarkAst -> bits -> bitsValue -> heading -> forValuesValue
1815
1824
  leaf_forValuesValue(node, _route) {
1816
1825
  this.writeNL();
1817
1826
  this.writeOPHASH();
1818
- this.writeBreakscapedTagString(node.value);
1827
+ this.writeTextOrValue(node.value, TextFormat_1.TextFormat.text, TextLocation_1.TextLocation.tag);
1819
1828
  this.writeCL();
1820
1829
  }
1821
1830
  // bitmarkAst -> bits -> bitsValue -> pairs -> pairsValue -> key
@@ -1823,7 +1832,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1823
1832
  leaf_key(node, _route) {
1824
1833
  if (node.value) {
1825
1834
  this.writeNL();
1826
- this.writeBreakscapedTagString(node.value);
1835
+ this.writeTextOrValue(node.value, this.textFormat, TextLocation_1.TextLocation.body);
1827
1836
  }
1828
1837
  }
1829
1838
  // bitmarkAst -> bits -> bitsValue -> pairs -> pairsValue -> values -> valuesValue
@@ -1831,7 +1840,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1831
1840
  leaf_valuesValue(node, _route) {
1832
1841
  if (node.value) {
1833
1842
  this.writeNL();
1834
- this.writeBreakscapedTagString(node.value);
1843
+ this.writeTextOrValue(node.value, this.textFormat, TextLocation_1.TextLocation.body);
1835
1844
  }
1836
1845
  }
1837
1846
  // bitmarkAst -> bits -> bitsValue -> questions -> questionsValue -> question
@@ -1843,7 +1852,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1843
1852
  return;
1844
1853
  if (node.value) {
1845
1854
  this.writeNL();
1846
- this.writeBreakscapedTagString(node.value);
1855
+ this.writeTextOrValue(node.value, this.textFormat, TextLocation_1.TextLocation.body);
1847
1856
  }
1848
1857
  }
1849
1858
  // bitmarkAst -> bits -> bitsValue -> statements -> text
@@ -1900,9 +1909,8 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1900
1909
  ignoreEmpty: true,
1901
1910
  });
1902
1911
  }
1903
- leaf_zoomDisabled(node, route) {
1904
- const bitType = this.getBitType(route);
1905
- if (Config_1.Config.isOfBitType(bitType, [
1912
+ leaf_zoomDisabled(node, _route) {
1913
+ if (Config_1.Config.isOfBitType(this.bitType, [
1906
1914
  BitType_1.BitType.imageSeparator,
1907
1915
  BitType_1.BitType.pageBanner,
1908
1916
  BitType_1.BitType.imagesLogoGrave,
@@ -2167,8 +2175,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2167
2175
  return false;
2168
2176
  }
2169
2177
  else if (footer.footer && footer.footer.length > 0) {
2170
- const isBitmarkText = textFormat === TextFormat_1.TextFormat.bitmarkPlusPlus || textFormat === TextFormat_1.TextFormat.bitmarkMinusMinus;
2171
- if (isBitmarkText) {
2178
+ if (this.isBodyBitmarkText) {
2172
2179
  // handle bitmark text
2173
2180
  return true;
2174
2181
  }
@@ -2180,17 +2187,108 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2180
2187
  }
2181
2188
  return false;
2182
2189
  }
2190
+ /**
2191
+ * Calculate the number of spaces around values from the options.
2192
+ *
2193
+ * This function should only be called from the constructor.
2194
+ * Otherwise use this.spacesAroundValues.
2195
+ *
2196
+ * @returns
2197
+ */
2198
+ calcSpacesAroundValues() {
2199
+ const val = this.options.spacesAroundValues;
2200
+ let spaces = DEFAULT_SPACES_AROUND_VALUES;
2201
+ if (val != null) {
2202
+ if (val === true) {
2203
+ spaces = DEFAULT_SPACES_AROUND_VALUES;
2204
+ }
2205
+ else if (val === false) {
2206
+ spaces = 0;
2207
+ }
2208
+ else {
2209
+ spaces = val;
2210
+ }
2211
+ }
2212
+ spaces = Math.min(Math.max(spaces, 0), MAX_SPACES_AROUND_VALUES);
2213
+ return spaces;
2214
+ }
2183
2215
  // END UTILITY FUNCTIONS
2184
2216
  //
2185
2217
  // WRITE FUNCTIONS
2186
2218
  //
2187
- writeBreakscapedTagString(s) {
2219
+ /**
2220
+ * Helper function to write a tag key, breakscaping appropriately.
2221
+ * Use only to write a tag key.
2222
+ *
2223
+ * @param s
2224
+ */
2225
+ writeTagKey(s) {
2188
2226
  if (s != null) {
2189
2227
  this.write(Breakscape_1.Breakscape.breakscape(`${s}`, {
2190
- textFormat: TextFormat_1.TextFormat.tag,
2228
+ textFormat: TextFormat_1.TextFormat.text,
2229
+ textLocation: TextLocation_1.TextLocation.tag,
2191
2230
  }));
2192
2231
  }
2193
2232
  }
2233
+ /**
2234
+ * Write text or value, handling the format and location (i.e. conversion to text and breakscaping).
2235
+ *
2236
+ * @param text
2237
+ * @param format
2238
+ * @param location
2239
+ * @param options
2240
+ */
2241
+ writeTextOrValue(text, format, location, options) {
2242
+ const isTagValue = location === TextLocation_1.TextLocation.tag;
2243
+ const s = StringUtils_1.StringUtils.isString(text) ? text : undefined;
2244
+ const ast = Array.isArray(text) ? text : undefined;
2245
+ const isBitmarkText = format === TextFormat_1.TextFormat.bitmarkPlusPlus || format === TextFormat_1.TextFormat.bitmarkMinusMinus;
2246
+ const isPlainText = !isBitmarkText;
2247
+ const spacesAroundValues = isTagValue ? this.spacesAroundValuesStr : '';
2248
+ if (isPlainText) {
2249
+ // Plain text
2250
+ if (s != null) {
2251
+ this.write(`${spacesAroundValues}${Breakscape_1.Breakscape.breakscape(`${s}`, {
2252
+ textFormat: TextFormat_1.TextFormat.text,
2253
+ textLocation: location,
2254
+ })}${spacesAroundValues}`);
2255
+ }
2256
+ }
2257
+ else {
2258
+ // Bitmark text (but might not be AST as some values are just strings (and all v2 values are strings))
2259
+ if (s != null) {
2260
+ this.write(`${spacesAroundValues}${Breakscape_1.Breakscape.breakscape(`${s}`, {
2261
+ textFormat: format,
2262
+ textLocation: location,
2263
+ })}${spacesAroundValues}`);
2264
+ }
2265
+ else if (ast != null) {
2266
+ // When writing a tag value, we don't know if it is empty until we write it, so we need to
2267
+ // write it using the part writer, and then check if it is empty before writing to the main writer.
2268
+ // Body values can be written directly to the main writer.
2269
+ if (isTagValue) {
2270
+ // Change the writer to the part writer
2271
+ this.writer = this.partWriter;
2272
+ this.partWriter.openSync();
2273
+ // Write the text
2274
+ this.textGenerator.generateSync(ast, format, location, options);
2275
+ // Get the written text
2276
+ this.partWriter.closeSync();
2277
+ const text = this.partWriter.getString();
2278
+ // Restore the main writer
2279
+ this.writer = this.mainWriter;
2280
+ // Write the text to the main writer, adding spaces around it where required
2281
+ if (text) {
2282
+ this.write(`${spacesAroundValues}${text.trim()}${spacesAroundValues}`);
2283
+ }
2284
+ }
2285
+ else {
2286
+ // Write the text directly to the main writer
2287
+ this.textGenerator.generateSync(ast, format, location, options);
2288
+ }
2289
+ }
2290
+ }
2291
+ }
2194
2292
  writeString(s) {
2195
2293
  if (s != null)
2196
2294
  this.write(`${s}`);
@@ -2259,8 +2357,14 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2259
2357
  this.write('[');
2260
2358
  }
2261
2359
  writeCL() {
2262
- // HACK to fix breakscaping when string ends with a ^ (must add a space)
2263
- this.writer.getLastWrite().endsWith('^') ? this.write(' ]') : this.write(']');
2360
+ // HACK to fix breakscaping when string ends with a ^ (must add a space) if
2361
+ // options.spacesAroundValues is 0
2362
+ if (this.spacesAroundValues === 0) {
2363
+ this.writer.getLastWrite().endsWith('^') ? this.write(' ]') : this.write(']');
2364
+ }
2365
+ else {
2366
+ this.write(']');
2367
+ }
2264
2368
  }
2265
2369
  writeAmpersand() {
2266
2370
  this.write('&');
@@ -2274,6 +2378,9 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2274
2378
  writeHash() {
2275
2379
  this.write('#');
2276
2380
  }
2381
+ writeSpacesAroundValues() {
2382
+ this.write(this.spacesAroundValuesStr);
2383
+ }
2277
2384
  writePlainTextDivider() {
2278
2385
  this.writeNL();
2279
2386
  this.write('==== text ====');
@@ -2343,9 +2450,9 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2343
2450
  const resourceData = resource[resourceTag];
2344
2451
  const src = resourceData ? resourceData.src || resourceData.url || resourceData.body || '' : '';
2345
2452
  this.writeOPA();
2346
- this.writeBreakscapedTagString(key);
2453
+ this.writeTagKey(key);
2347
2454
  this.writeColon();
2348
- this.writeBreakscapedTagString(src);
2455
+ this.writeTextOrValue(src, TextFormat_1.TextFormat.text, TextLocation_1.TextLocation.tag);
2349
2456
  if (resource.type === ResourceTag_1.ResourceTag.article) {
2350
2457
  // this.writeNL();
2351
2458
  }
@@ -2357,9 +2464,9 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2357
2464
  if (type) {
2358
2465
  // Standard case
2359
2466
  this.writeOPAMP();
2360
- this.writeBreakscapedTagString(type);
2467
+ this.writeTagKey(type);
2361
2468
  this.writeColon();
2362
- this.writeBreakscapedTagString(value);
2469
+ this.writeTextOrValue(value, TextFormat_1.TextFormat.text, TextLocation_1.TextLocation.tag);
2363
2470
  if (type === ResourceTag_1.ResourceTag.article) {
2364
2471
  // this.writeNL();
2365
2472
  }
@@ -2376,9 +2483,9 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2376
2483
  if (options.ignoreEmpty && isBitmarkText && this.isEmptyText(values))
2377
2484
  return;
2378
2485
  this.writeOPA();
2379
- this.writeBreakscapedTagString(name);
2486
+ this.writeTagKey(name);
2380
2487
  this.writeColon();
2381
- this.textGenerator.generateSync(values, (_a = TextFormat_1.TextFormat.fromValue(options.format)) !== null && _a !== void 0 ? _a : TextFormat_1.TextFormat.bitmarkMinusMinus);
2488
+ this.writeTextOrValue(values, (_a = TextFormat_1.TextFormat.fromValue(options.format)) !== null && _a !== void 0 ? _a : TextFormat_1.TextFormat.bitmarkMinusMinus, TextLocation_1.TextLocation.tag);
2382
2489
  this.writeCL();
2383
2490
  }
2384
2491
  else {
@@ -2401,9 +2508,9 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2401
2508
  if (options.ignoreEmpty && val === '')
2402
2509
  continue;
2403
2510
  this.writeOPA();
2404
- this.writeBreakscapedTagString(name);
2511
+ this.writeTagKey(name);
2405
2512
  this.writeColon();
2406
- this.writeBreakscapedTagString(`${val}`);
2513
+ this.writeTextOrValue(`${val}`, TextFormat_1.TextFormat.text, TextLocation_1.TextLocation.tag);
2407
2514
  this.writeCL();
2408
2515
  // propertyIndex++;
2409
2516
  }
@@ -2440,35 +2547,14 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2440
2547
  const writeFormat = !isDefault || this.options.explicitTextFormat;
2441
2548
  return !!writeFormat;
2442
2549
  }
2443
- getTextFormat(route) {
2444
- for (const node of route) {
2445
- if (node.key === NodeType_1.NodeType.bitsValue) {
2446
- const n = node.value;
2447
- return n === null || n === void 0 ? void 0 : n.textFormat;
2448
- }
2449
- }
2450
- return undefined;
2451
- }
2452
- isCardAllowed(route) {
2453
- const textFormat = this.getTextFormat(route);
2454
- const isBitmarkText = textFormat === TextFormat_1.TextFormat.bitmarkMinusMinus || textFormat === TextFormat_1.TextFormat.bitmarkPlusPlus;
2455
- return isBitmarkText && !this.isOfBitType1(route);
2550
+ calculateIsCardAllowed() {
2551
+ return this.isBodyBitmarkText && !this.isOfBitType1();
2456
2552
  }
2457
- isOfBitType1(route) {
2458
- return this.isOfBitType(route, [BitType_1.BitType.trueFalse1, BitType_1.BitType.multipleChoice1, BitType_1.BitType.multipleResponse1]);
2553
+ isOfBitType1() {
2554
+ return this.isOfBitType([BitType_1.BitType.trueFalse1, BitType_1.BitType.multipleChoice1, BitType_1.BitType.multipleResponse1]);
2459
2555
  }
2460
- isOfBitType(route, baseBitType) {
2461
- const bt = this.getBitType(route);
2462
- return Config_1.Config.isOfBitType(bt, baseBitType);
2463
- }
2464
- getBitType(route) {
2465
- for (const node of route) {
2466
- if (node.key === NodeType_1.NodeType.bitsValue) {
2467
- const n = node.value;
2468
- return n === null || n === void 0 ? void 0 : n.bitType;
2469
- }
2470
- }
2471
- return undefined;
2556
+ isOfBitType(baseBitType) {
2557
+ return Config_1.Config.isOfBitType(this.bitType, baseBitType);
2472
2558
  }
2473
2559
  //
2474
2560
  // Writer interface