@gmb/bitmark-parser-generator 3.23.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 (197) 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 +11 -7
  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 +11 -0
  12. package/dist/cjs/config/raw/bits.js.map +1 -1
  13. package/dist/cjs/config/raw/groups.js +5 -0
  14. package/dist/cjs/config/raw/groups.js.map +1 -1
  15. package/dist/cjs/config/raw/properties.js +4 -0
  16. package/dist/cjs/config/raw/properties.js.map +1 -1
  17. package/dist/cjs/generated/build-info.js +1 -1
  18. package/dist/cjs/generated/parser/text/text-peggy-parser.js +317 -296
  19. package/dist/cjs/generated/parser/text/text-peggy-parser.js.map +1 -1
  20. package/dist/cjs/generator/bitmark/BitmarkGenerator.js +276 -166
  21. package/dist/cjs/generator/bitmark/BitmarkGenerator.js.map +1 -1
  22. package/dist/cjs/generator/json/JsonGenerator.js +10 -7
  23. package/dist/cjs/generator/json/JsonGenerator.js.map +1 -1
  24. package/dist/cjs/generator/text/TextGenerator.js +42 -12
  25. package/dist/cjs/generator/text/TextGenerator.js.map +1 -1
  26. package/dist/cjs/model/ast/NodeType.js +2 -0
  27. package/dist/cjs/model/ast/NodeType.js.map +1 -1
  28. package/dist/cjs/model/config/enum/PropertyConfigKey.js +1 -0
  29. package/dist/cjs/model/config/enum/PropertyConfigKey.js.map +1 -1
  30. package/dist/cjs/model/enum/BitType.js +2 -0
  31. package/dist/cjs/model/enum/BitType.js.map +1 -1
  32. package/dist/cjs/model/enum/TextFormat.js +16 -7
  33. package/dist/cjs/model/enum/TextFormat.js.map +1 -1
  34. package/dist/cjs/model/enum/TextLocation.js +15 -0
  35. package/dist/cjs/model/enum/TextLocation.js.map +1 -0
  36. package/dist/cjs/parser/bitmark/peg/BitmarkPegParserHelper.js +5 -2
  37. package/dist/cjs/parser/bitmark/peg/BitmarkPegParserHelper.js.map +1 -1
  38. package/dist/cjs/parser/bitmark/peg/BitmarkPegParserProcessor.js +5 -2
  39. package/dist/cjs/parser/bitmark/peg/BitmarkPegParserProcessor.js.map +1 -1
  40. package/dist/cjs/parser/bitmark/peg/contentProcessors/BodyContentProcessor.js +4 -0
  41. package/dist/cjs/parser/bitmark/peg/contentProcessors/BodyContentProcessor.js.map +1 -1
  42. package/dist/cjs/parser/bitmark/peg/contentProcessors/BookChainContentProcessor.js +3 -1
  43. package/dist/cjs/parser/bitmark/peg/contentProcessors/BookChainContentProcessor.js.map +1 -1
  44. package/dist/cjs/parser/bitmark/peg/contentProcessors/CardContentProcessor.js +1 -2
  45. package/dist/cjs/parser/bitmark/peg/contentProcessors/CardContentProcessor.js.map +1 -1
  46. package/dist/cjs/parser/bitmark/peg/contentProcessors/ClozeTagContentProcessor.js +3 -1
  47. package/dist/cjs/parser/bitmark/peg/contentProcessors/ClozeTagContentProcessor.js.map +1 -1
  48. package/dist/cjs/parser/bitmark/peg/contentProcessors/DefaultTagContentProcessor.js +17 -5
  49. package/dist/cjs/parser/bitmark/peg/contentProcessors/DefaultTagContentProcessor.js.map +1 -1
  50. package/dist/cjs/parser/bitmark/peg/contentProcessors/ExampleTagContentProcessor.js +8 -1
  51. package/dist/cjs/parser/bitmark/peg/contentProcessors/ExampleTagContentProcessor.js.map +1 -1
  52. package/dist/cjs/parser/bitmark/peg/contentProcessors/FooterContentProcessor.js +3 -0
  53. package/dist/cjs/parser/bitmark/peg/contentProcessors/FooterContentProcessor.js.map +1 -1
  54. package/dist/cjs/parser/bitmark/peg/contentProcessors/ImageSourceChainContentProcessor.js +3 -1
  55. package/dist/cjs/parser/bitmark/peg/contentProcessors/ImageSourceChainContentProcessor.js.map +1 -1
  56. package/dist/cjs/parser/bitmark/peg/contentProcessors/MarkConfigChainContentProcessor.js +3 -1
  57. package/dist/cjs/parser/bitmark/peg/contentProcessors/MarkConfigChainContentProcessor.js.map +1 -1
  58. package/dist/cjs/parser/bitmark/peg/contentProcessors/MarkTagContentProcessor.js +1 -1
  59. package/dist/cjs/parser/bitmark/peg/contentProcessors/MarkTagContentProcessor.js.map +1 -1
  60. package/dist/cjs/parser/bitmark/peg/contentProcessors/PersonChainContentProcessor.js +4 -2
  61. package/dist/cjs/parser/bitmark/peg/contentProcessors/PersonChainContentProcessor.js.map +1 -1
  62. package/dist/cjs/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.js +11 -5
  63. package/dist/cjs/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.js.map +1 -1
  64. package/dist/cjs/parser/bitmark/peg/contentProcessors/ReferenceTagContentProcessor.js +5 -2
  65. package/dist/cjs/parser/bitmark/peg/contentProcessors/ReferenceTagContentProcessor.js.map +1 -1
  66. package/dist/cjs/parser/bitmark/peg/contentProcessors/ResourceContentProcessor.js +7 -2
  67. package/dist/cjs/parser/bitmark/peg/contentProcessors/ResourceContentProcessor.js.map +1 -1
  68. package/dist/cjs/parser/bitmark/peg/contentProcessors/TechnicalTermChainContentProcessor.js +3 -1
  69. package/dist/cjs/parser/bitmark/peg/contentProcessors/TechnicalTermChainContentProcessor.js.map +1 -1
  70. package/dist/cjs/parser/bitmark/peg/contentProcessors/TrueFalseTagContentProcessor.js +3 -1
  71. package/dist/cjs/parser/bitmark/peg/contentProcessors/TrueFalseTagContentProcessor.js.map +1 -1
  72. package/dist/cjs/parser/text/TextParser.js +0 -15
  73. package/dist/cjs/parser/text/TextParser.js.map +1 -1
  74. package/dist/esm/BitmarkParserGenerator.js +10 -2
  75. package/dist/esm/BitmarkParserGenerator.js.map +1 -1
  76. package/dist/esm/ast/BaseBuilder.js +4 -0
  77. package/dist/esm/ast/BaseBuilder.js.map +1 -1
  78. package/dist/esm/ast/Builder.js +11 -7
  79. package/dist/esm/ast/Builder.js.map +1 -1
  80. package/dist/esm/breakscaping/Breakscape.js +185 -128
  81. package/dist/esm/breakscaping/Breakscape.js.map +1 -1
  82. package/dist/esm/config/raw/bits.js +11 -0
  83. package/dist/esm/config/raw/bits.js.map +1 -1
  84. package/dist/esm/config/raw/groups.js +5 -0
  85. package/dist/esm/config/raw/groups.js.map +1 -1
  86. package/dist/esm/config/raw/properties.js +4 -0
  87. package/dist/esm/config/raw/properties.js.map +1 -1
  88. package/dist/esm/generated/build-info.js +1 -1
  89. package/dist/esm/generated/parser/text/text-peggy-parser.js +317 -296
  90. package/dist/esm/generated/parser/text/text-peggy-parser.js.map +1 -1
  91. package/dist/esm/generator/bitmark/BitmarkGenerator.js +276 -166
  92. package/dist/esm/generator/bitmark/BitmarkGenerator.js.map +1 -1
  93. package/dist/esm/generator/json/JsonGenerator.js +10 -7
  94. package/dist/esm/generator/json/JsonGenerator.js.map +1 -1
  95. package/dist/esm/generator/text/TextGenerator.js +42 -12
  96. package/dist/esm/generator/text/TextGenerator.js.map +1 -1
  97. package/dist/esm/model/ast/NodeType.js +2 -0
  98. package/dist/esm/model/ast/NodeType.js.map +1 -1
  99. package/dist/esm/model/config/enum/PropertyConfigKey.js +1 -0
  100. package/dist/esm/model/config/enum/PropertyConfigKey.js.map +1 -1
  101. package/dist/esm/model/enum/BitType.js +2 -0
  102. package/dist/esm/model/enum/BitType.js.map +1 -1
  103. package/dist/esm/model/enum/TextFormat.js +16 -7
  104. package/dist/esm/model/enum/TextFormat.js.map +1 -1
  105. package/dist/esm/model/enum/TextLocation.js +12 -0
  106. package/dist/esm/model/enum/TextLocation.js.map +1 -0
  107. package/dist/esm/parser/bitmark/peg/BitmarkPegParserHelper.js +5 -2
  108. package/dist/esm/parser/bitmark/peg/BitmarkPegParserHelper.js.map +1 -1
  109. package/dist/esm/parser/bitmark/peg/BitmarkPegParserProcessor.js +5 -2
  110. package/dist/esm/parser/bitmark/peg/BitmarkPegParserProcessor.js.map +1 -1
  111. package/dist/esm/parser/bitmark/peg/contentProcessors/BodyContentProcessor.js +4 -0
  112. package/dist/esm/parser/bitmark/peg/contentProcessors/BodyContentProcessor.js.map +1 -1
  113. package/dist/esm/parser/bitmark/peg/contentProcessors/BookChainContentProcessor.js +3 -1
  114. package/dist/esm/parser/bitmark/peg/contentProcessors/BookChainContentProcessor.js.map +1 -1
  115. package/dist/esm/parser/bitmark/peg/contentProcessors/CardContentProcessor.js +1 -2
  116. package/dist/esm/parser/bitmark/peg/contentProcessors/CardContentProcessor.js.map +1 -1
  117. package/dist/esm/parser/bitmark/peg/contentProcessors/ClozeTagContentProcessor.js +3 -1
  118. package/dist/esm/parser/bitmark/peg/contentProcessors/ClozeTagContentProcessor.js.map +1 -1
  119. package/dist/esm/parser/bitmark/peg/contentProcessors/DefaultTagContentProcessor.js +17 -5
  120. package/dist/esm/parser/bitmark/peg/contentProcessors/DefaultTagContentProcessor.js.map +1 -1
  121. package/dist/esm/parser/bitmark/peg/contentProcessors/ExampleTagContentProcessor.js +8 -1
  122. package/dist/esm/parser/bitmark/peg/contentProcessors/ExampleTagContentProcessor.js.map +1 -1
  123. package/dist/esm/parser/bitmark/peg/contentProcessors/FooterContentProcessor.js +3 -0
  124. package/dist/esm/parser/bitmark/peg/contentProcessors/FooterContentProcessor.js.map +1 -1
  125. package/dist/esm/parser/bitmark/peg/contentProcessors/ImageSourceChainContentProcessor.js +3 -1
  126. package/dist/esm/parser/bitmark/peg/contentProcessors/ImageSourceChainContentProcessor.js.map +1 -1
  127. package/dist/esm/parser/bitmark/peg/contentProcessors/MarkConfigChainContentProcessor.js +3 -1
  128. package/dist/esm/parser/bitmark/peg/contentProcessors/MarkConfigChainContentProcessor.js.map +1 -1
  129. package/dist/esm/parser/bitmark/peg/contentProcessors/MarkTagContentProcessor.js +1 -1
  130. package/dist/esm/parser/bitmark/peg/contentProcessors/MarkTagContentProcessor.js.map +1 -1
  131. package/dist/esm/parser/bitmark/peg/contentProcessors/PersonChainContentProcessor.js +4 -2
  132. package/dist/esm/parser/bitmark/peg/contentProcessors/PersonChainContentProcessor.js.map +1 -1
  133. package/dist/esm/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.js +11 -5
  134. package/dist/esm/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.js.map +1 -1
  135. package/dist/esm/parser/bitmark/peg/contentProcessors/ReferenceTagContentProcessor.js +5 -2
  136. package/dist/esm/parser/bitmark/peg/contentProcessors/ReferenceTagContentProcessor.js.map +1 -1
  137. package/dist/esm/parser/bitmark/peg/contentProcessors/ResourceContentProcessor.js +7 -2
  138. package/dist/esm/parser/bitmark/peg/contentProcessors/ResourceContentProcessor.js.map +1 -1
  139. package/dist/esm/parser/bitmark/peg/contentProcessors/TechnicalTermChainContentProcessor.js +3 -1
  140. package/dist/esm/parser/bitmark/peg/contentProcessors/TechnicalTermChainContentProcessor.js.map +1 -1
  141. package/dist/esm/parser/bitmark/peg/contentProcessors/TrueFalseTagContentProcessor.js +3 -1
  142. package/dist/esm/parser/bitmark/peg/contentProcessors/TrueFalseTagContentProcessor.js.map +1 -1
  143. package/dist/esm/parser/text/TextParser.js +0 -15
  144. package/dist/esm/parser/text/TextParser.js.map +1 -1
  145. package/dist/types/BitmarkParserGenerator.d.ts +13 -0
  146. package/dist/types/BitmarkParserGenerator.d.ts.map +1 -1
  147. package/dist/types/ast/BaseBuilder.d.ts.map +1 -1
  148. package/dist/types/ast/Builder.d.ts +1 -0
  149. package/dist/types/ast/Builder.d.ts.map +1 -1
  150. package/dist/types/breakscaping/Breakscape.d.ts +23 -1
  151. package/dist/types/breakscaping/Breakscape.d.ts.map +1 -1
  152. package/dist/types/config/raw/bits.d.ts.map +1 -1
  153. package/dist/types/config/raw/groups.d.ts.map +1 -1
  154. package/dist/types/config/raw/properties.d.ts.map +1 -1
  155. package/dist/types/generated/parser/text/text-peggy-parser.d.ts.map +1 -1
  156. package/dist/types/generator/bitmark/BitmarkGenerator.d.ts +61 -18
  157. package/dist/types/generator/bitmark/BitmarkGenerator.d.ts.map +1 -1
  158. package/dist/types/generator/json/JsonGenerator.d.ts.map +1 -1
  159. package/dist/types/generator/text/TextGenerator.d.ts +9 -2
  160. package/dist/types/generator/text/TextGenerator.d.ts.map +1 -1
  161. package/dist/types/model/ast/NodeType.d.ts +4 -0
  162. package/dist/types/model/ast/NodeType.d.ts.map +1 -1
  163. package/dist/types/model/ast/Nodes.d.ts +1 -0
  164. package/dist/types/model/ast/Nodes.d.ts.map +1 -1
  165. package/dist/types/model/config/enum/ConfigKey.d.ts +2 -0
  166. package/dist/types/model/config/enum/ConfigKey.d.ts.map +1 -1
  167. package/dist/types/model/config/enum/PropertyConfigKey.d.ts +3 -0
  168. package/dist/types/model/config/enum/PropertyConfigKey.d.ts.map +1 -1
  169. package/dist/types/model/enum/BitType.d.ts +4 -0
  170. package/dist/types/model/enum/BitType.d.ts.map +1 -1
  171. package/dist/types/model/enum/PropertyTag.d.ts +2 -0
  172. package/dist/types/model/enum/PropertyTag.d.ts.map +1 -1
  173. package/dist/types/model/enum/TextFormat.d.ts +0 -2
  174. package/dist/types/model/enum/TextFormat.d.ts.map +1 -1
  175. package/dist/types/model/enum/TextLocation.d.ts +16 -0
  176. package/dist/types/model/enum/TextLocation.d.ts.map +1 -0
  177. package/dist/types/model/json/BitJson.d.ts +4 -3
  178. package/dist/types/model/json/BitJson.d.ts.map +1 -1
  179. package/dist/types/parser/bitmark/peg/BitmarkPegParserHelper.d.ts.map +1 -1
  180. package/dist/types/parser/bitmark/peg/BitmarkPegParserProcessor.d.ts.map +1 -1
  181. package/dist/types/parser/bitmark/peg/contentProcessors/BodyContentProcessor.d.ts.map +1 -1
  182. package/dist/types/parser/bitmark/peg/contentProcessors/BookChainContentProcessor.d.ts.map +1 -1
  183. package/dist/types/parser/bitmark/peg/contentProcessors/CardContentProcessor.d.ts.map +1 -1
  184. package/dist/types/parser/bitmark/peg/contentProcessors/ClozeTagContentProcessor.d.ts.map +1 -1
  185. package/dist/types/parser/bitmark/peg/contentProcessors/DefaultTagContentProcessor.d.ts.map +1 -1
  186. package/dist/types/parser/bitmark/peg/contentProcessors/ExampleTagContentProcessor.d.ts.map +1 -1
  187. package/dist/types/parser/bitmark/peg/contentProcessors/FooterContentProcessor.d.ts.map +1 -1
  188. package/dist/types/parser/bitmark/peg/contentProcessors/ImageSourceChainContentProcessor.d.ts.map +1 -1
  189. package/dist/types/parser/bitmark/peg/contentProcessors/MarkConfigChainContentProcessor.d.ts.map +1 -1
  190. package/dist/types/parser/bitmark/peg/contentProcessors/PersonChainContentProcessor.d.ts.map +1 -1
  191. package/dist/types/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.d.ts.map +1 -1
  192. package/dist/types/parser/bitmark/peg/contentProcessors/ReferenceTagContentProcessor.d.ts.map +1 -1
  193. package/dist/types/parser/bitmark/peg/contentProcessors/ResourceContentProcessor.d.ts.map +1 -1
  194. package/dist/types/parser/bitmark/peg/contentProcessors/TechnicalTermChainContentProcessor.d.ts.map +1 -1
  195. package/dist/types/parser/bitmark/peg/contentProcessors/TrueFalseTagContentProcessor.d.ts.map +1 -1
  196. package/dist/types/parser/text/TextParser.d.ts.map +1 -1
  197. 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.writer = writer;
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.writeBreakscapedTagString(bit.bitType);
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.writeBreakscapedTagString(bit.textFormat);
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.writeBreakscapedTagString(resourceType);
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.writeBreakscapedTagString(hint);
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.textGenerator.generateSync(node.value, textFormat);
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.write(Breakscape.breakscape(str, {
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.textGenerator.generateSync(item, TextFormat.bitmarkMinusMinus);
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.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.bitmarkMinusMinus);
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.textGenerator.generateSync(lead, TextFormat.bitmarkMinusMinus);
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.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.bitmarkMinusMinus);
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.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.bitmarkMinusMinus);
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.textGenerator.generateSync(pageNumber !== null && pageNumber !== void 0 ? pageNumber : '', TextFormat.bitmarkMinusMinus);
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.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.bitmarkMinusMinus);
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.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.bitmarkMinusMinus);
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.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.bitmarkMinusMinus);
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.textGenerator.generateSync(marginNumber, TextFormat.bitmarkMinusMinus);
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.write(Breakscape.breakscape(text, {
744
- textFormat: TextFormat.text,
745
- }));
765
+ this.writeTextOrValue(text, TextFormat.text, TextLocation.body);
746
766
  }
747
767
  }
748
768
  }
749
- else if (isBitmarkText) {
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.textGenerator.generateSync(b, textFormat, {
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.write(Breakscape.breakscape(`${s}`, {
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.writeBreakscapedTagString(solution);
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.writeBreakscapedTagString(mark.solution);
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
- const isBitmarkText = textFormat === TextFormat.bitmarkPlusPlus || textFormat === TextFormat.bitmarkMinusMinus;
833
- if (isBitmarkText) {
849
+ if (this.isBodyBitmarkText) {
834
850
  // handle bitmark text
835
851
  this.writeNL();
836
- this.write('==== footer ====');
852
+ this.writeTextOrValue('==== footer ====', TextFormat.text, TextLocation.body);
837
853
  this.writeNL();
838
854
  // The text generator will write to the writer
839
- this.textGenerator.generateSync(footer.footer, textFormat, {
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.writeBreakscapedTagString(solution);
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.write(selectOption.text);
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.write(highlightText.text);
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, route) {
941
+ enter_cardNode(_node, _route) {
926
942
  // Ignore cards if not allowed
927
- if (!this.isCardAllowed(route))
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, route) {
949
+ between_cardNode(_node, _left, _right, _route) {
934
950
  // Ignore cards if not allowed
935
- if (!this.isCardAllowed(route))
951
+ if (!this.isCardAllowed)
936
952
  return;
937
953
  this.writeCardSetCardDivider();
938
954
  }
939
- exit_cardNode(_node, route) {
955
+ exit_cardNode(_node, _route) {
940
956
  // Ignore cards if not allowed
941
- if (!this.isCardAllowed(route))
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, route) {
976
+ between_flashcardsValue(_node, _left, right, _route) {
961
977
  var _a;
962
978
  // Ignore cards if not allowed
963
- if (!this.isCardAllowed(route))
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, route) {
985
- const isTrueFalse1 = this.isOfBitType(route, BitType.trueFalse1);
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.write(statement.statement);
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.write(choice.choice);
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.write(response.response);
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, route) {
1075
+ between_heading(_node, _left, _right, _route) {
1060
1076
  // Ignore cards if not allowed
1061
- if (!this.isCardAllowed(route))
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, route) {
1085
+ between_forValues(_node, _left, _right, _route) {
1070
1086
  // Ignore cards if not allowed
1071
- if (!this.isCardAllowed(route))
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, route) {
1125
+ enter_values(_node, _route) {
1110
1126
  // Ignore cards if not allowed
1111
- if (!this.isCardAllowed(route))
1127
+ if (!this.isCardAllowed)
1112
1128
  return;
1113
1129
  this.writeCardSetSideDivider();
1114
1130
  }
1115
- between_values(_node, _left, _right, route) {
1131
+ between_values(_node, _left, _right, _route) {
1116
1132
  // Ignore cards if not allowed
1117
- if (!this.isCardAllowed(route))
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(route))
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(route))
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(route))
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
- if (node.value)
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
- if (node.value) {
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(route))
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.write(node.value);
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.textGenerator.generateSync(cell.title, TextFormat.bitmarkMinusMinus);
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.textGenerator.generateSync(cell.body, textFormat);
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.textGenerator.generateSync(node.value, textFormat);
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.write(node.value);
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.write(node.value);
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(route))
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.writeBreakscapedTagString(ingredient.title);
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.writeBreakscapedTagString(`${ingredient.quantity}`);
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.write(ingredient.item);
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.writeBreakscapedTagString(node.value);
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 feeback = node.value;
1407
- if (feeback) {
1416
+ const feedback = node.value;
1417
+ if (feedback) {
1408
1418
  this.writeNL();
1409
- this.write(feeback);
1419
+ this.writeTextOrValue(feedback, this.textFormat, TextLocation.body);
1410
1420
  }
1411
1421
  }
1412
1422
  // bitmarkAst -> bits -> bitsValue -> imagePlaceholder
@@ -1474,6 +1484,29 @@ class BitmarkGenerator extends AstWalkerGenerator {
1474
1484
  }
1475
1485
  // bitmarkAst -> bits -> bitsValue -> bitType
1476
1486
  // bitmarkAst -> bits -> bitsValue -> textFormat
1487
+ // bitmarkAst -> bits -> level
1488
+ leaf_level(node, route) {
1489
+ // Ensure this is at the bit level
1490
+ const parent = this.getParentNode(route);
1491
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.bitsValue)
1492
+ return true;
1493
+ // Ensure this is a chapter bit
1494
+ if (!Config.isOfBitType(this.bitType, [BitType.chapter]))
1495
+ return true;
1496
+ const level = node.value;
1497
+ const bit = parent === null || parent === void 0 ? void 0 : parent.value;
1498
+ if (level > 0 && bit.title == null) {
1499
+ // If the level is set, but there is no title, this is a [.chapter] bit with an empty title.
1500
+ // We need to write an empty title tag at the correct level.
1501
+ this.writeNL();
1502
+ this.writeOP();
1503
+ for (let i = 0; i < +level; i++)
1504
+ this.writeHash();
1505
+ this.writeCL();
1506
+ }
1507
+ // Stop traversal of this branch
1508
+ return false;
1509
+ }
1477
1510
  // bitmarkAst -> bits -> title
1478
1511
  enter_title(node, route) {
1479
1512
  // Ensure this is at the bit level
@@ -1489,7 +1522,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
1489
1522
  this.writeOP();
1490
1523
  for (let i = 0; i < +level; i++)
1491
1524
  this.writeHash();
1492
- this.textGenerator.generateSync(title, TextFormat.bitmarkMinusMinus);
1525
+ this.writeTextOrValue(title, this.tagTextFormat, TextLocation.tag);
1493
1526
  this.writeCL();
1494
1527
  }
1495
1528
  // Stop traversal of this branch
@@ -1509,7 +1542,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
1509
1542
  this.writeOP();
1510
1543
  for (let i = 0; i < level; i++)
1511
1544
  this.writeHash();
1512
- this.textGenerator.generateSync(subtitle, TextFormat.bitmarkMinusMinus);
1545
+ this.writeTextOrValue(subtitle, this.tagTextFormat, TextLocation.tag);
1513
1546
  this.writeCL();
1514
1547
  }
1515
1548
  // Stop traversal of this branch
@@ -1533,11 +1566,11 @@ class BitmarkGenerator extends AstWalkerGenerator {
1533
1566
  });
1534
1567
  if (book.reference) {
1535
1568
  this.writeOPRANGLE();
1536
- this.writeBreakscapedTagString(book.reference);
1569
+ this.writeTextOrValue(book.reference, TextFormat.text, TextLocation.tag);
1537
1570
  this.writeCL();
1538
1571
  if (book.referenceEnd) {
1539
1572
  this.writeOPRANGLE();
1540
- this.writeBreakscapedTagString(book.referenceEnd);
1573
+ this.writeTextOrValue(book.referenceEnd, TextFormat.text, TextLocation.tag);
1541
1574
  this.writeCL();
1542
1575
  }
1543
1576
  }
@@ -1558,11 +1591,11 @@ class BitmarkGenerator extends AstWalkerGenerator {
1558
1591
  });
1559
1592
  if (bit.reference) {
1560
1593
  this.writeOPRANGLE();
1561
- this.writeBreakscapedTagString(bit.reference);
1594
+ this.writeTextOrValue(bit.reference, TextFormat.text, TextLocation.tag);
1562
1595
  this.writeCL();
1563
1596
  if (bit.referenceEnd) {
1564
1597
  this.writeOPRANGLE();
1565
- this.writeBreakscapedTagString(bit.referenceEnd);
1598
+ this.writeTextOrValue(bit.referenceEnd, TextFormat.text, TextLocation.tag);
1566
1599
  this.writeCL();
1567
1600
  }
1568
1601
  }
@@ -1573,7 +1606,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
1573
1606
  if (node.value) {
1574
1607
  this.writeNL();
1575
1608
  this.writeOPDANGLE();
1576
- this.writeBreakscapedTagString(node.value);
1609
+ this.writeTextOrValue(node.value, TextFormat.text, TextLocation.tag);
1577
1610
  this.writeCL();
1578
1611
  }
1579
1612
  }
@@ -1586,7 +1619,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
1586
1619
  if (!bit.book) {
1587
1620
  this.writeNL();
1588
1621
  this.writeOPRANGLE();
1589
- this.writeBreakscapedTagString(node.value);
1622
+ this.writeTextOrValue(node.value, TextFormat.text, TextLocation.tag);
1590
1623
  this.writeCL();
1591
1624
  }
1592
1625
  }
@@ -1600,7 +1633,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
1600
1633
  if (!this.isEmptyText(text)) {
1601
1634
  this.writeNL_IfNotChain(route);
1602
1635
  this.writeOPQ();
1603
- this.textGenerator.generateSync(text, TextFormat.bitmarkMinusMinus);
1636
+ this.writeTextOrValue(text, this.tagTextFormat, TextLocation.tag);
1604
1637
  this.writeCL();
1605
1638
  }
1606
1639
  // Stop traversal of this branch
@@ -1613,7 +1646,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
1613
1646
  if (!this.isEmptyText(text)) {
1614
1647
  this.writeNL_IfNotChain(route);
1615
1648
  this.writeOPB();
1616
- this.textGenerator.generateSync(text, TextFormat.bitmarkMinusMinus);
1649
+ this.writeTextOrValue(text, this.tagTextFormat, TextLocation.tag);
1617
1650
  this.writeCL();
1618
1651
  }
1619
1652
  // Stop traversal of this branch
@@ -1701,18 +1734,18 @@ class BitmarkGenerator extends AstWalkerGenerator {
1701
1734
  this.writeString('example');
1702
1735
  this.writeColon();
1703
1736
  if (example === true) {
1704
- this.writeString('true');
1737
+ this.writeString(' true ');
1705
1738
  }
1706
1739
  else if (example === false) {
1707
- this.writeString('false');
1740
+ this.writeString(' false ');
1708
1741
  }
1709
1742
  else if (Array.isArray(example)) {
1710
1743
  // TextAst
1711
- this.textGenerator.generateSync(example, TextFormat.bitmarkMinusMinus);
1744
+ this.writeTextOrValue(example, this.tagTextFormat, TextLocation.tag);
1712
1745
  }
1713
1746
  else {
1714
1747
  // String
1715
- this.writeBreakscapedTagString(example);
1748
+ this.writeTextOrValue(example, TextFormat.text, TextLocation.tag);
1716
1749
  }
1717
1750
  this.writeCL();
1718
1751
  }
@@ -1727,7 +1760,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
1727
1760
  leaf_elementsValue(node, _route) {
1728
1761
  if (node.value) {
1729
1762
  this.writeNL();
1730
- this.writeBreakscapedTagString(node.value);
1763
+ this.writeTextOrValue(node.value, this.textFormat, TextLocation.body);
1731
1764
  }
1732
1765
  }
1733
1766
  // bitmarkAst -> bits -> bitsValue -> body -> bodyValue -> gap -> solutions -> solution
@@ -1738,7 +1771,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
1738
1771
  return;
1739
1772
  if (node.value != null) {
1740
1773
  this.writeOPU();
1741
- this.writeBreakscapedTagString(node.value);
1774
+ this.writeTextOrValue(node.value, TextFormat.text, TextLocation.tag);
1742
1775
  this.writeCL();
1743
1776
  }
1744
1777
  }
@@ -1747,7 +1780,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
1747
1780
  leaf_prefix(node, _route) {
1748
1781
  if (node.value) {
1749
1782
  this.writeOPPRE();
1750
- this.writeBreakscapedTagString(node.value);
1783
+ this.writeTextOrValue(node.value, TextFormat.text, TextLocation.tag);
1751
1784
  this.writeCL();
1752
1785
  }
1753
1786
  }
@@ -1756,7 +1789,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
1756
1789
  leaf_postfix(node, _route) {
1757
1790
  if (node.value) {
1758
1791
  this.writeOPPOST();
1759
- this.writeBreakscapedTagString(node.value);
1792
+ this.writeTextOrValue(node.value, TextFormat.text, TextLocation.tag);
1760
1793
  this.writeCL();
1761
1794
  }
1762
1795
  }
@@ -1774,21 +1807,21 @@ class BitmarkGenerator extends AstWalkerGenerator {
1774
1807
  leaf_forKeys(node, _route) {
1775
1808
  this.writeNL();
1776
1809
  this.writeOPHASH();
1777
- this.writeBreakscapedTagString(node.value);
1810
+ this.writeTextOrValue(node.value, TextFormat.text, TextLocation.tag);
1778
1811
  this.writeCL();
1779
1812
  }
1780
1813
  // bitmarkAst -> bits -> bitsValue -> heading -> forValues
1781
1814
  leaf_forValues(node, _route) {
1782
1815
  this.writeNL();
1783
1816
  this.writeOPHASH();
1784
- this.writeBreakscapedTagString(node.value);
1817
+ this.writeTextOrValue(node.value, TextFormat.text, TextLocation.tag);
1785
1818
  this.writeCL();
1786
1819
  }
1787
1820
  // bitmarkAst -> bits -> bitsValue -> heading -> forValuesValue
1788
1821
  leaf_forValuesValue(node, _route) {
1789
1822
  this.writeNL();
1790
1823
  this.writeOPHASH();
1791
- this.writeBreakscapedTagString(node.value);
1824
+ this.writeTextOrValue(node.value, TextFormat.text, TextLocation.tag);
1792
1825
  this.writeCL();
1793
1826
  }
1794
1827
  // bitmarkAst -> bits -> bitsValue -> pairs -> pairsValue -> key
@@ -1796,7 +1829,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
1796
1829
  leaf_key(node, _route) {
1797
1830
  if (node.value) {
1798
1831
  this.writeNL();
1799
- this.writeBreakscapedTagString(node.value);
1832
+ this.writeTextOrValue(node.value, this.textFormat, TextLocation.body);
1800
1833
  }
1801
1834
  }
1802
1835
  // bitmarkAst -> bits -> bitsValue -> pairs -> pairsValue -> values -> valuesValue
@@ -1804,7 +1837,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
1804
1837
  leaf_valuesValue(node, _route) {
1805
1838
  if (node.value) {
1806
1839
  this.writeNL();
1807
- this.writeBreakscapedTagString(node.value);
1840
+ this.writeTextOrValue(node.value, this.textFormat, TextLocation.body);
1808
1841
  }
1809
1842
  }
1810
1843
  // bitmarkAst -> bits -> bitsValue -> questions -> questionsValue -> question
@@ -1816,7 +1849,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
1816
1849
  return;
1817
1850
  if (node.value) {
1818
1851
  this.writeNL();
1819
- this.writeBreakscapedTagString(node.value);
1852
+ this.writeTextOrValue(node.value, this.textFormat, TextLocation.body);
1820
1853
  }
1821
1854
  }
1822
1855
  // bitmarkAst -> bits -> bitsValue -> statements -> text
@@ -1873,9 +1906,8 @@ class BitmarkGenerator extends AstWalkerGenerator {
1873
1906
  ignoreEmpty: true,
1874
1907
  });
1875
1908
  }
1876
- leaf_zoomDisabled(node, route) {
1877
- const bitType = this.getBitType(route);
1878
- if (Config.isOfBitType(bitType, [
1909
+ leaf_zoomDisabled(node, _route) {
1910
+ if (Config.isOfBitType(this.bitType, [
1879
1911
  BitType.imageSeparator,
1880
1912
  BitType.pageBanner,
1881
1913
  BitType.imagesLogoGrave,
@@ -2140,8 +2172,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
2140
2172
  return false;
2141
2173
  }
2142
2174
  else if (footer.footer && footer.footer.length > 0) {
2143
- const isBitmarkText = textFormat === TextFormat.bitmarkPlusPlus || textFormat === TextFormat.bitmarkMinusMinus;
2144
- if (isBitmarkText) {
2175
+ if (this.isBodyBitmarkText) {
2145
2176
  // handle bitmark text
2146
2177
  return true;
2147
2178
  }
@@ -2153,17 +2184,108 @@ class BitmarkGenerator extends AstWalkerGenerator {
2153
2184
  }
2154
2185
  return false;
2155
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
+ }
2156
2212
  // END UTILITY FUNCTIONS
2157
2213
  //
2158
2214
  // WRITE FUNCTIONS
2159
2215
  //
2160
- writeBreakscapedTagString(s) {
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) {
2161
2223
  if (s != null) {
2162
2224
  this.write(Breakscape.breakscape(`${s}`, {
2163
- textFormat: TextFormat.tag,
2225
+ textFormat: TextFormat.text,
2226
+ textLocation: TextLocation.tag,
2164
2227
  }));
2165
2228
  }
2166
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
+ }
2167
2289
  writeString(s) {
2168
2290
  if (s != null)
2169
2291
  this.write(`${s}`);
@@ -2232,8 +2354,14 @@ class BitmarkGenerator extends AstWalkerGenerator {
2232
2354
  this.write('[');
2233
2355
  }
2234
2356
  writeCL() {
2235
- // HACK to fix breakscaping when string ends with a ^ (must add a space)
2236
- this.writer.getLastWrite().endsWith('^') ? this.write(' ]') : this.write(']');
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
+ }
2237
2365
  }
2238
2366
  writeAmpersand() {
2239
2367
  this.write('&');
@@ -2247,6 +2375,9 @@ class BitmarkGenerator extends AstWalkerGenerator {
2247
2375
  writeHash() {
2248
2376
  this.write('#');
2249
2377
  }
2378
+ writeSpacesAroundValues() {
2379
+ this.write(this.spacesAroundValuesStr);
2380
+ }
2250
2381
  writePlainTextDivider() {
2251
2382
  this.writeNL();
2252
2383
  this.write('==== text ====');
@@ -2316,9 +2447,9 @@ class BitmarkGenerator extends AstWalkerGenerator {
2316
2447
  const resourceData = resource[resourceTag];
2317
2448
  const src = resourceData ? resourceData.src || resourceData.url || resourceData.body || '' : '';
2318
2449
  this.writeOPA();
2319
- this.writeBreakscapedTagString(key);
2450
+ this.writeTagKey(key);
2320
2451
  this.writeColon();
2321
- this.writeBreakscapedTagString(src);
2452
+ this.writeTextOrValue(src, TextFormat.text, TextLocation.tag);
2322
2453
  if (resource.type === ResourceTag.article) {
2323
2454
  // this.writeNL();
2324
2455
  }
@@ -2330,9 +2461,9 @@ class BitmarkGenerator extends AstWalkerGenerator {
2330
2461
  if (type) {
2331
2462
  // Standard case
2332
2463
  this.writeOPAMP();
2333
- this.writeBreakscapedTagString(type);
2464
+ this.writeTagKey(type);
2334
2465
  this.writeColon();
2335
- this.writeBreakscapedTagString(value);
2466
+ this.writeTextOrValue(value, TextFormat.text, TextLocation.tag);
2336
2467
  if (type === ResourceTag.article) {
2337
2468
  // this.writeNL();
2338
2469
  }
@@ -2349,9 +2480,9 @@ class BitmarkGenerator extends AstWalkerGenerator {
2349
2480
  if (options.ignoreEmpty && isBitmarkText && this.isEmptyText(values))
2350
2481
  return;
2351
2482
  this.writeOPA();
2352
- this.writeBreakscapedTagString(name);
2483
+ this.writeTagKey(name);
2353
2484
  this.writeColon();
2354
- this.textGenerator.generateSync(values, (_a = TextFormat.fromValue(options.format)) !== null && _a !== void 0 ? _a : TextFormat.bitmarkMinusMinus);
2485
+ this.writeTextOrValue(values, (_a = TextFormat.fromValue(options.format)) !== null && _a !== void 0 ? _a : TextFormat.bitmarkMinusMinus, TextLocation.tag);
2355
2486
  this.writeCL();
2356
2487
  }
2357
2488
  else {
@@ -2374,9 +2505,9 @@ class BitmarkGenerator extends AstWalkerGenerator {
2374
2505
  if (options.ignoreEmpty && val === '')
2375
2506
  continue;
2376
2507
  this.writeOPA();
2377
- this.writeBreakscapedTagString(name);
2508
+ this.writeTagKey(name);
2378
2509
  this.writeColon();
2379
- this.writeBreakscapedTagString(`${val}`);
2510
+ this.writeTextOrValue(`${val}`, TextFormat.text, TextLocation.tag);
2380
2511
  this.writeCL();
2381
2512
  // propertyIndex++;
2382
2513
  }
@@ -2413,35 +2544,14 @@ class BitmarkGenerator extends AstWalkerGenerator {
2413
2544
  const writeFormat = !isDefault || this.options.explicitTextFormat;
2414
2545
  return !!writeFormat;
2415
2546
  }
2416
- getTextFormat(route) {
2417
- for (const node of route) {
2418
- if (node.key === NodeType.bitsValue) {
2419
- const n = node.value;
2420
- return n === null || n === void 0 ? void 0 : n.textFormat;
2421
- }
2422
- }
2423
- return undefined;
2424
- }
2425
- isCardAllowed(route) {
2426
- const textFormat = this.getTextFormat(route);
2427
- const isBitmarkText = textFormat === TextFormat.bitmarkMinusMinus || textFormat === TextFormat.bitmarkPlusPlus;
2428
- return isBitmarkText && !this.isOfBitType1(route);
2429
- }
2430
- isOfBitType1(route) {
2431
- return this.isOfBitType(route, [BitType.trueFalse1, BitType.multipleChoice1, BitType.multipleResponse1]);
2547
+ calculateIsCardAllowed() {
2548
+ return this.isBodyBitmarkText && !this.isOfBitType1();
2432
2549
  }
2433
- isOfBitType(route, baseBitType) {
2434
- const bt = this.getBitType(route);
2435
- return Config.isOfBitType(bt, baseBitType);
2550
+ isOfBitType1() {
2551
+ return this.isOfBitType([BitType.trueFalse1, BitType.multipleChoice1, BitType.multipleResponse1]);
2436
2552
  }
2437
- getBitType(route) {
2438
- for (const node of route) {
2439
- if (node.key === NodeType.bitsValue) {
2440
- const n = node.value;
2441
- return n === null || n === void 0 ? void 0 : n.bitType;
2442
- }
2443
- }
2444
- return undefined;
2553
+ isOfBitType(baseBitType) {
2554
+ return Config.isOfBitType(this.bitType, baseBitType);
2445
2555
  }
2446
2556
  //
2447
2557
  // Writer interface