@gmb/bitmark-parser-generator 3.11.0 → 3.13.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 (140) 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 +17 -7
  4. package/dist/cjs/BitmarkParserGenerator.js.map +1 -1
  5. package/dist/cjs/ast/BaseBuilder.js +5 -0
  6. package/dist/cjs/ast/BaseBuilder.js.map +1 -1
  7. package/dist/cjs/ast/Builder.js +147 -6
  8. package/dist/cjs/ast/Builder.js.map +1 -1
  9. package/dist/cjs/ast/ResourceBuilder.js +1 -0
  10. package/dist/cjs/ast/ResourceBuilder.js.map +1 -1
  11. package/dist/cjs/ast/writer/FileWriter.js +17 -7
  12. package/dist/cjs/ast/writer/FileWriter.js.map +1 -1
  13. package/dist/cjs/config/raw/bits.js +54 -0
  14. package/dist/cjs/config/raw/bits.js.map +1 -1
  15. package/dist/cjs/config/raw/cardSets.js +46 -0
  16. package/dist/cjs/config/raw/cardSets.js.map +1 -1
  17. package/dist/cjs/config/raw/groups.js +19 -0
  18. package/dist/cjs/config/raw/groups.js.map +1 -1
  19. package/dist/cjs/config/raw/properties.js +10 -0
  20. package/dist/cjs/config/raw/properties.js.map +1 -1
  21. package/dist/cjs/generated/build-info.js +1 -1
  22. package/dist/cjs/generated/parser/bitmark/bitmark-peggy-parser.js +1 -1
  23. package/dist/cjs/generated/parser/text/text-peggy-parser.js +1258 -710
  24. package/dist/cjs/generated/parser/text/text-peggy-parser.js.map +1 -1
  25. package/dist/cjs/generator/bitmark/BitmarkGenerator.js +265 -399
  26. package/dist/cjs/generator/bitmark/BitmarkGenerator.js.map +1 -1
  27. package/dist/cjs/generator/json/JsonGenerator.js +5 -0
  28. package/dist/cjs/generator/json/JsonGenerator.js.map +1 -1
  29. package/dist/cjs/generator/text/TextGenerator.js +32 -13
  30. package/dist/cjs/generator/text/TextGenerator.js.map +1 -1
  31. package/dist/cjs/model/ast/NodeType.js +7 -0
  32. package/dist/cjs/model/ast/NodeType.js.map +1 -1
  33. package/dist/cjs/model/config/enum/CardSetConfigKey.js +1 -0
  34. package/dist/cjs/model/config/enum/CardSetConfigKey.js.map +1 -1
  35. package/dist/cjs/model/config/enum/GroupConfigKey.js +1 -0
  36. package/dist/cjs/model/config/enum/GroupConfigKey.js.map +1 -1
  37. package/dist/cjs/model/config/enum/PropertyConfigKey.js +2 -0
  38. package/dist/cjs/model/config/enum/PropertyConfigKey.js.map +1 -1
  39. package/dist/cjs/model/enum/BitType.js +14 -0
  40. package/dist/cjs/model/enum/BitType.js.map +1 -1
  41. package/dist/cjs/model/enum/ResourceTag.js +1 -0
  42. package/dist/cjs/model/enum/ResourceTag.js.map +1 -1
  43. package/dist/cjs/parser/bitmark/peg/BitmarkPegParserTypes.js.map +1 -1
  44. package/dist/cjs/parser/bitmark/peg/BitmarkPegParserValidator.js +1 -1
  45. package/dist/cjs/parser/bitmark/peg/BitmarkPegParserValidator.js.map +1 -1
  46. package/dist/cjs/parser/bitmark/peg/contentProcessors/CardContentProcessor.js +79 -16
  47. package/dist/cjs/parser/bitmark/peg/contentProcessors/CardContentProcessor.js.map +1 -1
  48. package/dist/cjs/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.js +5 -0
  49. package/dist/cjs/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.js.map +1 -1
  50. package/dist/cjs/parser/bitmark/peg/contentProcessors/TrueFalseChainContentProcessor.js +6 -1
  51. package/dist/cjs/parser/bitmark/peg/contentProcessors/TrueFalseChainContentProcessor.js.map +1 -1
  52. package/dist/cjs/utils/FileUtils.js +17 -7
  53. package/dist/cjs/utils/FileUtils.js.map +1 -1
  54. package/dist/esm/ast/BaseBuilder.js +5 -0
  55. package/dist/esm/ast/BaseBuilder.js.map +1 -1
  56. package/dist/esm/ast/Builder.js +147 -6
  57. package/dist/esm/ast/Builder.js.map +1 -1
  58. package/dist/esm/ast/ResourceBuilder.js +1 -0
  59. package/dist/esm/ast/ResourceBuilder.js.map +1 -1
  60. package/dist/esm/config/raw/bits.js +54 -0
  61. package/dist/esm/config/raw/bits.js.map +1 -1
  62. package/dist/esm/config/raw/cardSets.js +46 -0
  63. package/dist/esm/config/raw/cardSets.js.map +1 -1
  64. package/dist/esm/config/raw/groups.js +19 -0
  65. package/dist/esm/config/raw/groups.js.map +1 -1
  66. package/dist/esm/config/raw/properties.js +10 -0
  67. package/dist/esm/config/raw/properties.js.map +1 -1
  68. package/dist/esm/generated/build-info.js +1 -1
  69. package/dist/esm/generated/parser/bitmark/bitmark-peggy-parser.js +1 -1
  70. package/dist/esm/generated/parser/text/text-peggy-parser.js +1258 -710
  71. package/dist/esm/generated/parser/text/text-peggy-parser.js.map +1 -1
  72. package/dist/esm/generator/bitmark/BitmarkGenerator.js +265 -399
  73. package/dist/esm/generator/bitmark/BitmarkGenerator.js.map +1 -1
  74. package/dist/esm/generator/json/JsonGenerator.js +5 -0
  75. package/dist/esm/generator/json/JsonGenerator.js.map +1 -1
  76. package/dist/esm/generator/text/TextGenerator.js +32 -13
  77. package/dist/esm/generator/text/TextGenerator.js.map +1 -1
  78. package/dist/esm/model/ast/NodeType.js +7 -0
  79. package/dist/esm/model/ast/NodeType.js.map +1 -1
  80. package/dist/esm/model/config/enum/CardSetConfigKey.js +1 -0
  81. package/dist/esm/model/config/enum/CardSetConfigKey.js.map +1 -1
  82. package/dist/esm/model/config/enum/GroupConfigKey.js +1 -0
  83. package/dist/esm/model/config/enum/GroupConfigKey.js.map +1 -1
  84. package/dist/esm/model/config/enum/PropertyConfigKey.js +2 -0
  85. package/dist/esm/model/config/enum/PropertyConfigKey.js.map +1 -1
  86. package/dist/esm/model/enum/BitType.js +14 -0
  87. package/dist/esm/model/enum/BitType.js.map +1 -1
  88. package/dist/esm/model/enum/ResourceTag.js +1 -0
  89. package/dist/esm/model/enum/ResourceTag.js.map +1 -1
  90. package/dist/esm/parser/bitmark/peg/BitmarkPegParserTypes.js.map +1 -1
  91. package/dist/esm/parser/bitmark/peg/BitmarkPegParserValidator.js +1 -1
  92. package/dist/esm/parser/bitmark/peg/BitmarkPegParserValidator.js.map +1 -1
  93. package/dist/esm/parser/bitmark/peg/contentProcessors/CardContentProcessor.js +79 -16
  94. package/dist/esm/parser/bitmark/peg/contentProcessors/CardContentProcessor.js.map +1 -1
  95. package/dist/esm/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.js +6 -1
  96. package/dist/esm/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.js.map +1 -1
  97. package/dist/esm/parser/bitmark/peg/contentProcessors/TrueFalseChainContentProcessor.js +6 -1
  98. package/dist/esm/parser/bitmark/peg/contentProcessors/TrueFalseChainContentProcessor.js.map +1 -1
  99. package/dist/types/ast/BaseBuilder.d.ts +3 -0
  100. package/dist/types/ast/BaseBuilder.d.ts.map +1 -1
  101. package/dist/types/ast/Builder.d.ts +40 -2
  102. package/dist/types/ast/Builder.d.ts.map +1 -1
  103. package/dist/types/ast/ResourceBuilder.d.ts.map +1 -1
  104. package/dist/types/config/raw/bits.d.ts.map +1 -1
  105. package/dist/types/config/raw/cardSets.d.ts.map +1 -1
  106. package/dist/types/config/raw/groups.d.ts.map +1 -1
  107. package/dist/types/config/raw/properties.d.ts.map +1 -1
  108. package/dist/types/generated/parser/text/text-peggy-parser.d.ts.map +1 -1
  109. package/dist/types/generator/bitmark/BitmarkGenerator.d.ts +26 -43
  110. package/dist/types/generator/bitmark/BitmarkGenerator.d.ts.map +1 -1
  111. package/dist/types/generator/json/JsonGenerator.d.ts +1 -0
  112. package/dist/types/generator/json/JsonGenerator.d.ts.map +1 -1
  113. package/dist/types/generator/text/TextGenerator.d.ts +5 -1
  114. package/dist/types/generator/text/TextGenerator.d.ts.map +1 -1
  115. package/dist/types/model/ast/NodeType.d.ts +14 -0
  116. package/dist/types/model/ast/NodeType.d.ts.map +1 -1
  117. package/dist/types/model/ast/Nodes.d.ts +4 -1
  118. package/dist/types/model/ast/Nodes.d.ts.map +1 -1
  119. package/dist/types/model/config/enum/CardSetConfigKey.d.ts +2 -0
  120. package/dist/types/model/config/enum/CardSetConfigKey.d.ts.map +1 -1
  121. package/dist/types/model/config/enum/ConfigKey.d.ts +6 -0
  122. package/dist/types/model/config/enum/ConfigKey.d.ts.map +1 -1
  123. package/dist/types/model/config/enum/GroupConfigKey.d.ts +3 -0
  124. package/dist/types/model/config/enum/GroupConfigKey.d.ts.map +1 -1
  125. package/dist/types/model/config/enum/PropertyConfigKey.d.ts +6 -0
  126. package/dist/types/model/config/enum/PropertyConfigKey.d.ts.map +1 -1
  127. package/dist/types/model/enum/BitType.d.ts +28 -0
  128. package/dist/types/model/enum/BitType.d.ts.map +1 -1
  129. package/dist/types/model/enum/PropertyTag.d.ts +4 -0
  130. package/dist/types/model/enum/PropertyTag.d.ts.map +1 -1
  131. package/dist/types/model/enum/ResourceTag.d.ts +2 -0
  132. package/dist/types/model/enum/ResourceTag.d.ts.map +1 -1
  133. package/dist/types/model/json/BitJson.d.ts +45 -6
  134. package/dist/types/model/json/BitJson.d.ts.map +1 -1
  135. package/dist/types/parser/bitmark/peg/BitmarkPegParserTypes.d.ts +5 -2
  136. package/dist/types/parser/bitmark/peg/BitmarkPegParserTypes.d.ts.map +1 -1
  137. package/dist/types/parser/bitmark/peg/contentProcessors/CardContentProcessor.d.ts.map +1 -1
  138. package/dist/types/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.d.ts.map +1 -1
  139. package/dist/types/parser/bitmark/peg/contentProcessors/TrueFalseChainContentProcessor.d.ts.map +1 -1
  140. package/package.json +40 -40
@@ -32,6 +32,9 @@ const DEFAULT_OPTIONS = {
32
32
  };
33
33
  /**
34
34
  * Generate bitmark markup from a bitmark AST
35
+ *
36
+ * NOTE: Newlines - a newline is written BEFORE each content that requries a newline
37
+ *
35
38
  */
36
39
  class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
37
40
  /**
@@ -54,10 +57,9 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
54
57
  super();
55
58
  this.ast = new Ast_1.Ast();
56
59
  // State
60
+ this.firstBit = true;
57
61
  this.hasCardSet = false;
58
62
  this.hasFooter = false;
59
- this.skipNLBetweenBitsValue = false;
60
- this.wroteSomething = false;
61
63
  this.inTag = true;
62
64
  // Keep TS happy
63
65
  this.inTag;
@@ -130,10 +132,9 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
130
132
  this.writer.closeSync();
131
133
  }
132
134
  resetState() {
135
+ this.firstBit = true;
133
136
  this.hasCardSet = false;
134
137
  this.hasFooter = false;
135
- this.skipNLBetweenBitsValue = false;
136
- this.wroteSomething = false;
137
138
  this.inTag = true;
138
139
  this.printed = false;
139
140
  }
@@ -150,12 +151,6 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
150
151
  // Non-Terminal nodes (branches)
151
152
  //
152
153
  // bitmark
153
- // bitmarkAst -> bits
154
- between_bits(_node, _left, _right, _route) {
155
- this.writeNL();
156
- this.writeNL();
157
- this.writeNL();
158
- }
159
154
  // bitmarkAst -> bits -> bitsValue
160
155
  enter_bitsValue(node, _route) {
161
156
  const bit = node.value;
@@ -163,6 +158,12 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
163
158
  const bitResourcesConfig = Config_1.Config.getBitResourcesConfig(bit.bitType, bit.resourceType);
164
159
  this.hasCardSet = this.haveValidCardSet(bit);
165
160
  this.hasFooter = this.haveValidFooter(bit);
161
+ // Separate the bits with 3 newlines
162
+ if (!this.firstBit) {
163
+ this.writeNL();
164
+ this.writeNL();
165
+ this.writeNL();
166
+ }
166
167
  // Write the bit tag opening
167
168
  this.writeOPD(bit.bitLevel);
168
169
  if (bit.isCommented)
@@ -198,22 +199,12 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
198
199
  this.writeBreakscapedTagString(resourceType);
199
200
  }
200
201
  this.writeCL();
201
- this.writeNL();
202
+ // this.writeNL();
202
203
  // Continue traversal
203
204
  return true;
204
205
  }
205
- between_bitsValue(node, left, right, route) {
206
- // The following keys are combined with other keys so don't need newlines
207
- const noNlKeys = [
208
- NodeType_1.NodeType.bitType,
209
- NodeType_1.NodeType.textFormat,
210
- NodeType_1.NodeType.level,
211
- NodeType_1.NodeType.progress,
212
- NodeType_1.NodeType.toc,
213
- NodeType_1.NodeType.referenceEnd,
214
- NodeType_1.NodeType.labelFalse,
215
- ];
216
- this.writeNlBetween(node, left, right, route, noNlKeys);
206
+ exit_bitsValue(_node, _route) {
207
+ this.firstBit = false;
217
208
  }
218
209
  // bitmarkAst -> bits -> bitsValue -> internalComment
219
210
  enter_internalComment(node, route) {
@@ -224,14 +215,12 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
224
215
  return true;
225
216
  for (let i = 0; i < internalComment.length; i++) {
226
217
  const comment = internalComment[i];
227
- const last = i === internalComment.length - 1;
218
+ this.writeNL();
228
219
  this.writeProperty('internalComment', comment, {
229
220
  format: PropertyFormat_1.PropertyFormat.trimmedString,
230
221
  single: false,
231
222
  ignoreEmpty: true,
232
223
  });
233
- if (!last)
234
- this.writeNL();
235
224
  }
236
225
  // Stop traversal of this branch
237
226
  return false;
@@ -245,13 +234,18 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
245
234
  return true;
246
235
  const bit = parent === null || parent === void 0 ? void 0 : parent.value;
247
236
  if (bit) {
248
- if (value != '')
237
+ const haveTrue = value != '';
238
+ const haveFalse = bit.labelFalse && bit.labelFalse[0] != '';
239
+ if (haveTrue || haveFalse) {
240
+ this.writeNL();
241
+ }
242
+ if (haveTrue)
249
243
  this.writeProperty(PropertyTag_1.PropertyTag.labelTrue, value, {
250
244
  format: PropertyFormat_1.PropertyFormat.trimmedString,
251
245
  single: true,
252
246
  ignoreEmpty: true,
253
247
  });
254
- if (bit.labelFalse && bit.labelFalse[0] != '')
248
+ if (haveFalse)
255
249
  this.writeProperty(PropertyTag_1.PropertyTag.labelFalse, bit.labelFalse, {
256
250
  format: PropertyFormat_1.PropertyFormat.trimmedString,
257
251
  single: true,
@@ -261,6 +255,10 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
261
255
  // Stop traversal of this branch
262
256
  return false;
263
257
  }
258
+ enter_labelFalse(_node, _route) {
259
+ // Handled above in enter_labelTrue(), but this function needed to block automatic property handling
260
+ return true;
261
+ }
264
262
  // bitmarkAst -> bits -> bitsValue -> imageSource
265
263
  enter_imageSource(node, route) {
266
264
  const imageSource = node.value;
@@ -269,6 +267,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
269
267
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.bitsValue)
270
268
  return true;
271
269
  const { url, mockupId, size, format, trim } = imageSource;
270
+ this.writeNL();
272
271
  this.writeProperty('imageSource', url, {
273
272
  format: PropertyFormat_1.PropertyFormat.trimmedString,
274
273
  single: true,
@@ -311,6 +310,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
311
310
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.bitsValue)
312
311
  return true;
313
312
  const { technicalTerm, lang } = nodeValue;
313
+ this.writeNL();
314
314
  this.writeProperty('technicalTerm', technicalTerm, {
315
315
  format: PropertyFormat_1.PropertyFormat.trimmedString,
316
316
  single: true,
@@ -334,6 +334,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
334
334
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.bitsValue)
335
335
  return true;
336
336
  const { servings, unit, unitAbbr, decimalPlaces, disableCalculation, hint } = nodeValue;
337
+ this.writeNL();
337
338
  this.writeProperty('servings', servings, {
338
339
  format: PropertyFormat_1.PropertyFormat.trimmedString,
339
340
  single: true,
@@ -387,6 +388,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
387
388
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.bitsValue)
388
389
  return true;
389
390
  const { name, title, avatarImage } = person;
391
+ this.writeNL();
390
392
  this.writeProperty('person', name, {
391
393
  format: PropertyFormat_1.PropertyFormat.trimmedString,
392
394
  single: true,
@@ -405,6 +407,89 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
405
407
  // Stop traversal of this branch
406
408
  return false;
407
409
  }
410
+ // bitmarkAst -> bits -> bitsValue -> cardNode -> definitions -> definitionsValue -> term -> text
411
+ // bitmarkAst -> bits -> bitsValue -> cardNode -> definitions -> definitionsValue -> definition -> text
412
+ // bitmarkAst -> bits -> bitsValue -> cardNode -> definitions -> definitionsValue -> alternativeDefinitions
413
+ // -> alternativeDefinitionsValue -> text
414
+ // bitmarkAst -> bits -> bitsValue -> cardNode -> flashcards -> flashcardsValue -> question -> text
415
+ // bitmarkAst -> bits -> bitsValue -> cardNode -> flashcards -> flashcardsValue -> answer -> text
416
+ // bitmarkAst -> bits -> bitsValue -> cardNode -> flashcards -> flashcardsValue -> alternativeAnswers ->
417
+ // -> alternativeAnswersValue -> text
418
+ enter_text(node, route) {
419
+ const parent = this.getParentNode(route);
420
+ if (!parent ||
421
+ (parent.key !== NodeType_1.NodeType.term &&
422
+ parent.key !== NodeType_1.NodeType.definition &&
423
+ parent.key !== NodeType_1.NodeType.alternativeDefinitionsValue &&
424
+ parent.key !== NodeType_1.NodeType.question &&
425
+ parent.key !== NodeType_1.NodeType.answer &&
426
+ parent.key !== NodeType_1.NodeType.alternativeAnswersValue)) {
427
+ return true;
428
+ }
429
+ if (node.value) {
430
+ this.writeNL();
431
+ this.textGenerator.generateSync(node.value, TextFormat_1.TextFormat.bitmarkMinusMinus);
432
+ }
433
+ // Stop traversal of this branch
434
+ return false;
435
+ }
436
+ leaf_text(node, route) {
437
+ const parent = this.getParentNode(route);
438
+ if (!parent ||
439
+ (parent.key !== NodeType_1.NodeType.term &&
440
+ parent.key !== NodeType_1.NodeType.definition &&
441
+ parent.key !== NodeType_1.NodeType.alternativeDefinitionsValue &&
442
+ parent.key !== NodeType_1.NodeType.question &&
443
+ parent.key !== NodeType_1.NodeType.answer &&
444
+ parent.key !== NodeType_1.NodeType.alternativeAnswersValue &&
445
+ parent.key !== NodeType_1.NodeType.reason)) {
446
+ return true;
447
+ }
448
+ if (StringUtils_1.StringUtils.isString(node.value)) {
449
+ const str = node.value;
450
+ this.writeNL();
451
+ this.write(Breakscape_1.Breakscape.breakscape(str, {
452
+ textFormat: TextFormat_1.TextFormat.text,
453
+ }));
454
+ }
455
+ // Stop traversal of this branch
456
+ return false;
457
+ }
458
+ // bitmarkAst -> bits -> bitsValue -> * -> term -> icon
459
+ // bitmarkAst -> bits -> bitsValue -> * -> definition -> icon
460
+ // bitmarkAst -> bits -> bitsValue -> * -> alternativeDefinitionsValue -> icon
461
+ enter_icon(node, route) {
462
+ const resource = node.value;
463
+ const parent = this.getParentNode(route);
464
+ if (!parent)
465
+ return true;
466
+ if (parent.key !== NodeType_1.NodeType.term &&
467
+ parent.key !== NodeType_1.NodeType.definition &&
468
+ parent.key !== NodeType_1.NodeType.alternativeDefinitionsValue &&
469
+ parent.key !== NodeType_1.NodeType.question &&
470
+ parent.key !== NodeType_1.NodeType.answer &&
471
+ parent.key !== NodeType_1.NodeType.alternativeAnswersValue) {
472
+ // Continue traversal of this branch
473
+ return true;
474
+ }
475
+ // This is a resource, so handle it with the common code
476
+ this.writeNL();
477
+ this.writeResource(ResourceTag_1.ResourceTag.icon, resource.src);
478
+ // this.writePropertyStyleResource(ResourceTag.icon, resource as ResourceJson);
479
+ // Continue traversal of this branch (for the chained properties)
480
+ return true;
481
+ }
482
+ leaf_iconValue(node, _route) {
483
+ // Handle as a standard icon property
484
+ this.writeNL();
485
+ this.writeProperty('icon', node.value, {
486
+ format: PropertyFormat_1.PropertyFormat.trimmedString,
487
+ single: true,
488
+ ignoreEmpty: true,
489
+ });
490
+ // Stop traversal of this branch
491
+ return false;
492
+ }
408
493
  // bitmarkAst -> bits -> bitsValue -> ratingLevelStart
409
494
  enter_ratingLevelStart(node, route) {
410
495
  this.enterRatingLevelStartEndCommon(node, route);
@@ -426,6 +511,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
426
511
  return true;
427
512
  const { level, label } = n;
428
513
  const levelKey = node.key === NodeType_1.NodeType.ratingLevelStart ? PropertyTag_1.PropertyTag.ratingLevelStart : PropertyTag_1.PropertyTag.ratingLevelEnd;
514
+ this.writeNL();
429
515
  this.writeProperty(levelKey, level, {
430
516
  format: PropertyFormat_1.PropertyFormat.trimmedString,
431
517
  single: true,
@@ -455,6 +541,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
455
541
  return true;
456
542
  const { mark, color, emphasis } = markConfig;
457
543
  if (mark) {
544
+ this.writeNL();
458
545
  this.writeProperty('mark', mark, {
459
546
  format: PropertyFormat_1.PropertyFormat.trimmedString,
460
547
  single: true,
@@ -474,74 +561,79 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
474
561
  ignoreEmpty: true,
475
562
  });
476
563
  }
477
- this.writeNL();
478
564
  }
479
565
  // Stop traversal of this branch
480
566
  return false;
481
567
  }
482
568
  // bitmarkAst -> bits -> bitsValue -> partialAnswer
483
569
  enter_partialAnswer(node, _route) {
484
- this.writeProperty('partialAnswer', node.value, {
485
- format: PropertyFormat_1.PropertyFormat.trimmedString,
486
- single: true,
487
- ignoreEmpty: true,
488
- });
570
+ if (node.value) {
571
+ this.writeNL();
572
+ this.writeProperty('partialAnswer', node.value, {
573
+ format: PropertyFormat_1.PropertyFormat.trimmedString,
574
+ single: true,
575
+ ignoreEmpty: true,
576
+ });
577
+ }
489
578
  // Stop traversal of this branch
490
579
  return false;
491
580
  }
492
581
  // bitmarkAst -> bits -> bitsValue -> questions -> questionsValue -> partialAnswer
493
582
  leaf_partialAnswer(node, _route) {
494
- this.writeProperty('partialAnswer', node.value, {
495
- format: PropertyFormat_1.PropertyFormat.trimmedString,
496
- single: true,
497
- ignoreEmpty: true,
498
- });
583
+ if (node.value) {
584
+ this.writeNL();
585
+ this.writeProperty('partialAnswer', node.value, {
586
+ format: PropertyFormat_1.PropertyFormat.trimmedString,
587
+ single: true,
588
+ ignoreEmpty: true,
589
+ });
590
+ }
499
591
  // Stop traversal of this branch
500
592
  return false;
501
593
  }
502
594
  // bitmarkAst -> bits -> bitsValue -> sampleSolution
503
595
  // bitmarkAst -> bits -> bitsValue -> questions -> questionsValue -> sampleSolution
504
596
  enter_sampleSolution(node, _route) {
505
- this.writeProperty('sampleSolution', node.value, {
506
- format: PropertyFormat_1.PropertyFormat.trimmedString,
507
- single: true,
508
- ignoreEmpty: true,
509
- });
597
+ if (node.value) {
598
+ this.writeNL();
599
+ this.writeProperty('sampleSolution', node.value, {
600
+ format: PropertyFormat_1.PropertyFormat.trimmedString,
601
+ single: true,
602
+ ignoreEmpty: true,
603
+ });
604
+ }
510
605
  // Stop traversal of this branch
511
606
  return false;
512
607
  }
513
608
  leaf_sampleSolution(node, _route) {
514
- this.writeProperty('sampleSolution', node.value, {
515
- format: PropertyFormat_1.PropertyFormat.trimmedString,
516
- single: true,
517
- ignoreEmpty: true,
518
- });
609
+ if (node.value) {
610
+ this.writeNL();
611
+ this.writeProperty('sampleSolution', node.value, {
612
+ format: PropertyFormat_1.PropertyFormat.trimmedString,
613
+ single: true,
614
+ ignoreEmpty: true,
615
+ });
616
+ }
519
617
  // Stop traversal of this branch
520
618
  return false;
521
619
  }
522
620
  // bitmarkAst -> bits -> bitsValue -> reasonableNumOfChars
523
621
  // bitmarkAst -> bits -> bitsValue -> questions -> questionsValue -> reasonableNumOfChars
524
622
  leaf_reasonableNumOfChars(node, _route) {
623
+ this.writeNL();
525
624
  this.writeProperty('reasonableNumOfChars', node.value, {
526
625
  format: PropertyFormat_1.PropertyFormat.trimmedString,
527
626
  single: true,
528
627
  ignoreEmpty: true,
529
628
  });
530
629
  }
531
- // bitmarkAst -> bits -> bitsValue -> questions -> questionsValue -> additionalSolutions
532
- between_additionalSolutions(_node, _left, _right, route) {
533
- // Ignore values that are not at the bit level as they might be handled elsewhere
534
- const parent = this.getParentNode(route);
535
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.questionsValue)
536
- return;
537
- this.writeNL();
538
- }
539
630
  // bitmarkAst -> bits -> bitsValue -> questions -> questionsValue -> additionalSolutions -> additionalSolutionsValue
540
631
  leaf_additionalSolutionsValue(node, route) {
541
632
  // Ignore values that are not at the bit level as they might be handled elsewhere
542
633
  const parent = this.getParentNode(route, 2);
543
634
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.questionsValue)
544
635
  return;
636
+ this.writeNL();
545
637
  this.writeProperty('additionalSolutions', node.value, {
546
638
  format: PropertyFormat_1.PropertyFormat.trimmedString,
547
639
  single: false,
@@ -560,6 +652,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
560
652
  return true; // Will be handled by pageNumber
561
653
  if (!this.isEmptyText((_c = parent === null || parent === void 0 ? void 0 : parent.value) === null || _c === void 0 ? void 0 : _c.marginNumber))
562
654
  return true; // Will be handled by marginNumber
655
+ this.writeNL_IfNotChain(route);
563
656
  this.writeOPC();
564
657
  this.textGenerator.generateSync(item, TextFormat_1.TextFormat.bitmarkMinusMinus);
565
658
  this.writeCL();
@@ -576,6 +669,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
576
669
  return true; // Will be handled by pageNumber
577
670
  if (!this.isEmptyText((_b = parent === null || parent === void 0 ? void 0 : parent.value) === null || _b === void 0 ? void 0 : _b.marginNumber))
578
671
  return true; // Will be handled by marginNumber
672
+ this.writeNL_IfNotChain(route);
579
673
  this.writeOPC();
580
674
  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);
581
675
  this.writeCL();
@@ -593,6 +687,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
593
687
  return false; // Ignore empty
594
688
  if (!this.isEmptyText((_a = parent === null || parent === void 0 ? void 0 : parent.value) === null || _a === void 0 ? void 0 : _a.marginNumber))
595
689
  return true; // Will be handled by marginNumber
690
+ this.writeNL_IfNotChain(route);
596
691
  this.writeOPC();
597
692
  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);
598
693
  this.writeCL();
@@ -611,6 +706,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
611
706
  const parent = this.getParentNode(route);
612
707
  if (this.isEmptyText(marginNumber))
613
708
  return false; // Ignore empty
709
+ this.writeNL_IfNotChain(route);
614
710
  this.writeOPC();
615
711
  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);
616
712
  this.writeCL();
@@ -633,7 +729,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
633
729
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.bitsValue && (parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.cardBitsValue)
634
730
  return true;
635
731
  this.inTag = false;
636
- // always write a NL before the body content if there is any?
732
+ // Always write a NL before the body content if there is any (see Handle body)
637
733
  const body = node.value;
638
734
  const textFormat = this.getTextFormat(route);
639
735
  const isBitmarkText = textFormat === TextFormat_1.TextFormat.bitmarkPlusPlus || textFormat === TextFormat_1.TextFormat.bitmarkMinusMinus;
@@ -643,7 +739,6 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
643
739
  if (Array.isArray(json) || ObjectUtils_1.ObjectUtils.isObject(json)) {
644
740
  const text = JSON.stringify(json, null, this.prettifySpace);
645
741
  if (text) {
646
- this.writeNL();
647
742
  this.writePlainTextDivider();
648
743
  this.writeNL();
649
744
  this.write(Breakscape_1.Breakscape.breakscape(text, {
@@ -664,27 +759,15 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
664
759
  }
665
760
  else {
666
761
  // handle plain text
667
- this.writeNL();
668
762
  this.writePlainTextDivider();
669
763
  this.writeNL();
670
764
  const s = (StringUtils_1.StringUtils.isString(body.body) ? body.body : '');
671
765
  this.write(Breakscape_1.Breakscape.breakscape(`${s}`, {
672
766
  textFormat: TextFormat_1.TextFormat.text,
673
767
  }));
674
- this.writeNL();
675
768
  }
676
769
  // Stop traversal of this branch
677
770
  return false;
678
- // if ((body.body && body.body.length > 0) || body.bodyJson) {
679
- // this.writeNL();
680
- // // Write the plain text divider if not bitmark++/-- format
681
- // const textFormat = this.getTextFormat(route);
682
- // const isBitmarkText = textFormat === TextFormat.bitmarkPlusPlus || textFormat === TextFormat.bitmarkMinusMinus;
683
- // if (!isBitmarkText) {
684
- // this.writePlainTextDivider();
685
- // this.writeNL();
686
- // }
687
- // }
688
771
  }
689
772
  exit_body(_node, _route) {
690
773
  this.inTag = true;
@@ -750,6 +833,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
750
833
  const isBitmarkText = textFormat === TextFormat_1.TextFormat.bitmarkPlusPlus || textFormat === TextFormat_1.TextFormat.bitmarkMinusMinus;
751
834
  if (isBitmarkText) {
752
835
  // handle bitmark text
836
+ this.writeNL();
753
837
  this.write('==== footer ====');
754
838
  this.writeNL();
755
839
  // The text generator will write to the writer
@@ -844,7 +928,6 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
844
928
  if (!this.isCardAllowed(route))
845
929
  return true;
846
930
  this.writeCardSetStart();
847
- this.writeNL();
848
931
  // Continue traversal
849
932
  return true;
850
933
  }
@@ -852,41 +935,27 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
852
935
  // Ignore cards if not allowed
853
936
  if (!this.isCardAllowed(route))
854
937
  return;
855
- this.writeNL();
856
938
  this.writeCardSetCardDivider();
857
- this.writeNL();
858
939
  }
859
940
  exit_cardNode(_node, route) {
860
941
  // Ignore cards if not allowed
861
942
  if (!this.isCardAllowed(route))
862
943
  return;
863
- this.writeNL();
864
944
  this.writeCardSetEnd();
865
945
  if (this.options.cardSetVersion === CardSetVersion_1.CardSetVersion.v1) {
866
- this.writeNL();
946
+ // this.writeNL();
867
947
  }
868
948
  }
869
- // bitmarkAst -> bits -> bitsValue -> cardNode -> cardBitsValue
870
- between_cardBitsValue(_node, _left, _right, _route) {
871
- this.writeNL();
872
- }
873
949
  // bitmarkAst -> bits -> bitsValue -> cardNode -> elements
874
950
  enter_elements(_node, _route) {
875
951
  //
876
952
  }
877
953
  between_elements(_node, _left, _right, _route) {
878
- this.writeNL();
879
954
  this.writeCardSetVariantDivider();
880
- this.writeNL();
881
- }
882
- exit_elements(_node, _route) {
883
- //
884
955
  }
885
956
  // bitmarkAst -> bits -> bitsValue -> cardNode -> flashcards
886
957
  between_flashcards(_node, _left, _right, _route) {
887
- this.writeNL();
888
958
  this.writeCardSetCardDivider();
889
- this.writeNL();
890
959
  }
891
960
  // bitmarkAst -> bits -> bitsValue -> cardNode -> flashcards -> flashcardsValue
892
961
  between_flashcardsValue(_node, _left, right, route) {
@@ -895,67 +964,19 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
895
964
  if (!this.isCardAllowed(route))
896
965
  return;
897
966
  if (right.key === NodeType_1.NodeType.answer) {
898
- this.writeNL();
899
967
  this.writeCardSetSideDivider();
900
- this.writeNL();
901
968
  }
902
969
  else if (right.key === NodeType_1.NodeType.alternativeAnswers && ((_a = right.value) === null || _a === void 0 ? void 0 : _a.length) !== 0) {
903
- this.writeNL();
904
970
  this.writeCardSetVariantDivider();
905
- this.writeNL();
906
971
  }
907
972
  }
908
- // bitmarkAst -> bits -> bitsValue -> cardNode -> flashcards -> flashcardsValue -> answer
909
- enter_answer(node, route) {
910
- // Ignore responses that are not at the flashcardsValue level as they are handled elsewhere
911
- const parent = this.getParentNode(route);
912
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.flashcardsValue)
913
- return true;
914
- if (node.value) {
915
- this.textGenerator.generateSync(node.value, TextFormat_1.TextFormat.bitmarkMinusMinus);
916
- }
917
- // Stop traversal of this branch
918
- return false;
919
- }
920
973
  // bitmarkAst -> bits -> bitsValue -> cardNode -> flashcards -> flashcardsValue -> alternativeAnswers
921
974
  between_alternativeAnswers(_node, _route) {
922
- this.writeNL();
923
975
  this.writeCardSetVariantDivider();
924
- this.writeNL();
925
- }
926
- // bitmarkAst -> bits -> bitsValue -> cardNode -> flashcards -> flashcardsValue -> alternativeAnswers -> alternativeAnswersValue
927
- enter_alternativeAnswersValue(node, route) {
928
- // Ignore responses that are not at the alternativeAnswers level as they are handled elsewhere
929
- const parent = this.getParentNode(route);
930
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.alternativeAnswers)
931
- return true;
932
- if (node.value) {
933
- // this.writeBreakscapedTagString(node.value);
934
- this.textGenerator.generateSync(node.value, TextFormat_1.TextFormat.bitmarkMinusMinus);
935
- }
936
- // Stop traversal of this branch
937
- return false;
938
976
  }
939
977
  // bitmarkAst -> bits -> bitsValue -> cardNode -> definitions -> definitionsValue -> alternativeDefintions
940
978
  between_alternativeDefinitions(_node, _route) {
941
- this.writeNL();
942
979
  this.writeCardSetVariantDivider();
943
- this.writeNL();
944
- }
945
- // bitmarkAst -> bits -> bitsValue -> cardNode -> definitions -> definitionsValue -> alternativeDefinitions -> alternativeDefinitionsValue
946
- enter_alternativeDefinitionsValue(node, route) {
947
- // Ignore responses that are not at the alternativeAnswers level as they are handled elsewhere
948
- const parent = this.getParentNode(route);
949
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.alternativeDefinitions)
950
- return true;
951
- if (node.value) {
952
- // this.writeNL();
953
- // this.writeCardSetVariantDivider();
954
- // this.writeNL();
955
- this.textGenerator.generateSync(node.value, TextFormat_1.TextFormat.bitmarkMinusMinus);
956
- }
957
- // Stop traversal of this branch
958
- return false;
959
980
  }
960
981
  // bitmarkAst -> bits -> bitsValue -> cardNode -> statements
961
982
  enter_statements(_node, _route) {
@@ -964,17 +985,13 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
964
985
  between_statements(_node, _left, _right, route) {
965
986
  const isTrueFalse1 = this.isOfBitType(route, BitType_1.BitType.trueFalse1);
966
987
  if (!isTrueFalse1) {
967
- this.writeNL();
968
988
  this.writeCardSetCardDivider();
969
989
  }
970
- this.writeNL();
971
- }
972
- exit_statements(_node, _route) {
973
- //
974
990
  }
975
991
  // bitmarkAst -> bits -> bitsValue -> cardNode -> statements -> statementsValue
976
992
  enter_statementsValue(node, _route) {
977
993
  const statement = node.value;
994
+ this.writeNL();
978
995
  if (statement.isCorrect) {
979
996
  this.writeOPP();
980
997
  }
@@ -986,19 +1003,13 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
986
1003
  // Continue traversal
987
1004
  return true;
988
1005
  }
989
- // bitmarkAst -> bits -> bitsValue -> choices
990
- // bitmarkAst -> bits -> bitsValue -> cardNode -> quizzes -> quizzesValue -> choices
991
- between_choices(_node, _left, _right, _route) {
992
- this.writeNL();
993
- }
994
- exit_choices(_node, _route) {
995
- this.writeNL();
996
- }
997
1006
  // bitmarkAst -> bits -> bitsValue -> choices -> choicesValue
998
1007
  // bitmarkAst -> bits -> bitsValue -> cardNode -> quizzes -> quizzesValue -> choices -> choicesValue
1008
+ // bitmarkAst -> bits -> bitsValue -> cardNode -> feedbacks -> feedbacksValue -> choices -> choicesValue
999
1009
  enter_choicesValue(node, _route) {
1000
1010
  const choice = node.value;
1001
- if (choice.isCorrect) {
1011
+ this.writeNL();
1012
+ if (choice.isCorrect || choice.requireReason) {
1002
1013
  this.writeOPP();
1003
1014
  }
1004
1015
  else {
@@ -1009,18 +1020,11 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1009
1020
  // Continue traversal
1010
1021
  return true;
1011
1022
  }
1012
- // bitmarkAst -> bits -> bitsValue -> responses
1013
- // bitmarkAst -> bits -> bitsValue -> cardNode -> quizzes -> quizzesValue -> responses
1014
- between_responses(_node, _left, _right, _route) {
1015
- this.writeNL();
1016
- }
1017
- exit_responses(_node, _route) {
1018
- this.writeNL();
1019
- }
1020
1023
  // bitmarkAst -> bits -> bitsValue -> responses -> responsesValue
1021
1024
  // bitmarkAst -> bits -> bitsValue -> cardNode -> quizzes -> quizzesValue -> responses -> responsesValue
1022
1025
  enter_responsesValue(node, _route) {
1023
1026
  const response = node.value;
1027
+ this.writeNL();
1024
1028
  if (response.isCorrect) {
1025
1029
  this.writeOPP();
1026
1030
  }
@@ -1032,23 +1036,22 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1032
1036
  // Continue traversal
1033
1037
  return true;
1034
1038
  }
1039
+ // bitmarkAst -> bits -> bitsValue -> cardNode -> feedbacks
1040
+ between_feedbacks(_node, _left, _right, _route) {
1041
+ this.writeCardSetCardDivider();
1042
+ }
1043
+ // bitmarkAst -> bits -> bitsValue -> cardNode -> feedbacks -> feedbacksValue -> reason
1044
+ enter_reason(_node, _route) {
1045
+ this.writeCardSetSideDivider();
1046
+ // Continue traversal
1047
+ return true;
1048
+ }
1035
1049
  // bitmarkAst -> bits -> bitsValue -> cardNode -> quizzes
1036
1050
  enter_quizzes(_node, _route) {
1037
1051
  //
1038
1052
  }
1039
1053
  between_quizzes(_node, _left, _right, _route) {
1040
- // this.writeNL();
1041
1054
  this.writeCardSetCardDivider();
1042
- this.writeNL();
1043
- }
1044
- exit_quizzes(_node, _route) {
1045
- //
1046
- }
1047
- // bitmarkAst -> bits -> bitsValue -> cardNode -> quizzes -> quizzesValue
1048
- between_quizzesValue(_node, _left, right, _route) {
1049
- if (right.key === NodeType_1.NodeType.choices || right.key === NodeType_1.NodeType.responses) {
1050
- this.writeNL();
1051
- }
1052
1055
  }
1053
1056
  // bitmarkAst -> bits -> bitsValue -> cardNode -> heading
1054
1057
  enter_heading(_node, _route) {
@@ -1058,12 +1061,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1058
1061
  // Ignore cards if not allowed
1059
1062
  if (!this.isCardAllowed(route))
1060
1063
  return;
1061
- this.writeNL();
1062
1064
  this.writeCardSetSideDivider();
1063
- this.writeNL();
1064
- }
1065
- exit_heading(_node, _route) {
1066
- //
1067
1065
  }
1068
1066
  // bitmarkAst -> bits -> bitsValue -> cardNode -> heading -> forValues
1069
1067
  enter_forValues(_node, _route) {
@@ -1073,33 +1071,20 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1073
1071
  // Ignore cards if not allowed
1074
1072
  if (!this.isCardAllowed(route))
1075
1073
  return;
1076
- this.writeNL();
1077
1074
  this.writeCardSetSideDivider();
1078
- this.writeNL();
1079
- }
1080
- exit_forValues(_node, _route) {
1081
- //
1082
1075
  }
1083
1076
  // bitmarkAst -> bits -> bitsValue -> cardNode -> pairs
1084
1077
  enter_pairs(_node, _route) {
1085
1078
  //
1086
1079
  }
1087
1080
  between_pairs(_node, _left, _right, _route) {
1088
- this.writeNL();
1089
1081
  this.writeCardSetCardDivider();
1090
- this.writeNL();
1091
- }
1092
- exit_pairs(_node, _route) {
1093
- //
1094
- }
1095
- // bitmarkAst -> bits -> bitsValue -> cardNode -> pairs -> pairsValue
1096
- between_pairsValue(_node, _left, _right, _route) {
1097
- //
1098
1082
  }
1099
1083
  // bitmarkAst -> bits -> bitsValue -> cardNode -> pairs -> pairsValue -> keyAudio
1100
1084
  enter_keyAudio(node, _route) {
1101
1085
  const resource = node.value;
1102
1086
  // This is a resource, so handle it with the common code
1087
+ this.writeNL();
1103
1088
  this.writeResource(ResourceTag_1.ResourceTag.audio, resource.src);
1104
1089
  // Stop traversal of this branch
1105
1090
  return false;
@@ -1108,6 +1093,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1108
1093
  enter_keyImage(node, _route) {
1109
1094
  const resource = node.value;
1110
1095
  // This is a resource, so handle it with the common code
1096
+ this.writeNL();
1111
1097
  this.writeResource(ResourceTag_1.ResourceTag.image, resource.src);
1112
1098
  // Stop traversal of this branch
1113
1099
  return false;
@@ -1117,16 +1103,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1117
1103
  //
1118
1104
  }
1119
1105
  between_matrix(_node, _left, _right, _route) {
1120
- this.writeNL();
1121
1106
  this.writeCardSetCardDivider();
1122
- this.writeNL();
1123
- }
1124
- exit_matrix(_node, _route) {
1125
- //
1126
- }
1127
- // bitmarkAst -> bits -> bitsValue -> cardNode -> matrix -> matrixValue
1128
- between_matrixValue(_node, _left, _right, _route) {
1129
- //
1130
1107
  }
1131
1108
  // bitmarkAst -> bits -> bitsValue -> cardNode -> pairs -> pairsValue -> values
1132
1109
  // bitmarkAst -> bits -> bitsValue -> cardNode -> matrix -> matrixValue -> cells -> cellsValue -> values
@@ -1134,17 +1111,13 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1134
1111
  // Ignore cards if not allowed
1135
1112
  if (!this.isCardAllowed(route))
1136
1113
  return;
1137
- this.writeNL();
1138
1114
  this.writeCardSetSideDivider();
1139
- this.writeNL();
1140
1115
  }
1141
1116
  between_values(_node, _left, _right, route) {
1142
1117
  // Ignore cards if not allowed
1143
1118
  if (!this.isCardAllowed(route))
1144
1119
  return;
1145
- this.writeNL();
1146
1120
  this.writeCardSetVariantDivider();
1147
- this.writeNL();
1148
1121
  }
1149
1122
  // bitmarkAst -> bits -> bitsValue -> cardNode -> pronunciationTable
1150
1123
  between_pronunciationTable(_node, _left, _right, route) {
@@ -1154,9 +1127,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1154
1127
  // Ignore cards if not allowed
1155
1128
  if (!this.isCardAllowed(route))
1156
1129
  return;
1157
- this.writeNL();
1158
1130
  this.writeCardSetCardDivider();
1159
- this.writeNL();
1160
1131
  }
1161
1132
  // bitmarkAst -> bits -> bitsValue -> cardNode -> table
1162
1133
  between_table(_node, _left, _right, route) {
@@ -1166,9 +1137,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1166
1137
  // Ignore cards if not allowed
1167
1138
  if (!this.isCardAllowed(route))
1168
1139
  return;
1169
- this.writeNL();
1170
1140
  this.writeCardSetCardDivider();
1171
- this.writeNL();
1172
1141
  }
1173
1142
  // bitmarkAst -> bits -> bitsValue -> cardNode -> table -> data
1174
1143
  // bitmarkAst -> bits -> bitsValue -> cardNode -> pronunciationTable -> data
@@ -1176,9 +1145,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1176
1145
  const parent = this.getParentNode(route);
1177
1146
  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)
1178
1147
  return;
1179
- this.writeNL();
1180
1148
  this.writeCardSetCardDivider();
1181
- this.writeNL();
1182
1149
  }
1183
1150
  // bitmarkAst -> bits -> bitsValue -> cardNode -> table -> columns
1184
1151
  // bitmarkAst -> bits -> bitsValue -> cardNode -> captionDefinitionList -> columns
@@ -1190,19 +1157,19 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1190
1157
  // Ignore cards if not allowed
1191
1158
  if (!this.isCardAllowed(route))
1192
1159
  return;
1193
- this.writeNL();
1194
1160
  this.writeCardSetSideDivider();
1195
- this.writeNL();
1196
1161
  }
1197
1162
  // bitmarkAst -> bits -> bitsValue -> cardNode -> table -> columns -> columnsValue
1198
1163
  // bitmarkAst -> bits -> bitsValue -> cardNode -> captionDefinitionList -> columns -> columnsValue
1199
1164
  leaf_columnsValue(node, _route) {
1165
+ this.writeNL();
1200
1166
  this.writeOPHASH();
1201
1167
  if (node.value)
1202
1168
  this.writeBreakscapedTagString(node.value);
1203
1169
  this.writeCL();
1204
1170
  }
1205
1171
  enter_columnsValue(node, _route) {
1172
+ this.writeNL();
1206
1173
  this.writeOPHASH();
1207
1174
  if (node.value) {
1208
1175
  this.textGenerator.generateSync(node.value, TextFormat_1.TextFormat.bitmarkMinusMinus);
@@ -1218,15 +1185,14 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1218
1185
  // Ignore cards if not allowed
1219
1186
  if (!this.isCardAllowed(route))
1220
1187
  return;
1221
- this.writeNL();
1222
1188
  this.writeCardSetSideDivider();
1223
- this.writeNL();
1224
1189
  }
1225
1190
  // bitmarkAst -> bits -> bitsValue -> cardNode -> table -> data -> dataValue -> dataValueValue
1226
1191
  leaf_dataValueValue(node, route) {
1227
1192
  const parent = this.getParentNode(route, 3);
1228
1193
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.table)
1229
1194
  return;
1195
+ this.writeNL();
1230
1196
  this.write(node.value);
1231
1197
  }
1232
1198
  // bitmarkAst -> bits -> bitsValue -> cardNode -> table -> data -> dataValue -> dataValueValue
@@ -1242,17 +1208,18 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1242
1208
  // Pronunciation Table
1243
1209
  const cell = node.value;
1244
1210
  if (cell.title) {
1211
+ this.writeNL();
1245
1212
  this.writeOP();
1246
1213
  this.writeHash();
1247
1214
  this.textGenerator.generateSync(cell.title, TextFormat_1.TextFormat.bitmarkMinusMinus);
1248
1215
  this.writeCL();
1249
- this.writeNL();
1250
1216
  }
1251
1217
  if (cell.audio) {
1252
- this.writeResource(ResourceTag_1.ResourceTag.audio, cell.audio.src);
1253
1218
  this.writeNL();
1219
+ this.writeResource(ResourceTag_1.ResourceTag.audio, cell.audio.src);
1254
1220
  }
1255
1221
  if (cell.body) {
1222
+ this.writeNL();
1256
1223
  this.textGenerator.generateSync(cell.body, textFormat);
1257
1224
  }
1258
1225
  // Stop traversal of this branch
@@ -1260,6 +1227,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1260
1227
  }
1261
1228
  else {
1262
1229
  // Table
1230
+ this.writeNL();
1263
1231
  this.textGenerator.generateSync(node.value, textFormat);
1264
1232
  }
1265
1233
  }
@@ -1270,38 +1238,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1270
1238
  const parent = this.getParentNode(route);
1271
1239
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.cardNode)
1272
1240
  return;
1273
- this.writeNL();
1274
1241
  this.writeCardSetCardDivider();
1275
- this.writeNL();
1276
- }
1277
- // // bitmarkAst -> bits -> bitsValue -> cardNode -> captionDefinitionList -> definitions
1278
- // protected between_definitions(_node: NodeInfo, _left: NodeInfo, _right: NodeInfo, route: NodeInfo[]): void {
1279
- // const parent = this.getParentNode(route);
1280
- // if (parent?.key !== NodeType.captionDefinitionList) return;
1281
- // this.writeNL();
1282
- // this.writeCardSetCardDivider();
1283
- // this.writeNL();
1284
- // }
1285
- // // bitmarkAst -> bits -> bitsValue -> cardNode -> captionDefinitionList -> definitions -> definitionsValue
1286
- // protected between_definitionsValue(_node: NodeInfo, _left: NodeInfo, _right: NodeInfo, route: NodeInfo[]): void {
1287
- // const parent = this.getParentNode(route);
1288
- // if (parent?.key !== NodeType.definitions) return;
1289
- // // Ignore cards if not allowed
1290
- // if (!this.isCardAllowed(route)) return;
1291
- // this.writeNL();
1292
- // this.writeCardSetSideDivider();
1293
- // this.writeNL();
1294
- // }
1295
- // bitmarkAst -> bits -> bitsValue -> cardNode -> definitions -> definitionsValue -> term
1296
- enter_term(node, route) {
1297
- const parent = this.getParentNode(route);
1298
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.definitionsValue)
1299
- return true;
1300
- if (node.value) {
1301
- this.textGenerator.generateSync(node.value, TextFormat_1.TextFormat.bitmarkMinusMinus);
1302
- }
1303
- // Stop traversal of this branch
1304
- return false;
1305
1242
  }
1306
1243
  // bitmarkAst -> bits -> bitsValue -> cardNode -> captionDefinitionList -> definitions -> definitionsValue -> term
1307
1244
  leaf_term(node, route) {
@@ -1309,28 +1246,19 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1309
1246
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.definitionsValue)
1310
1247
  return true;
1311
1248
  if (node.value) {
1249
+ this.writeNL();
1312
1250
  this.write(node.value);
1313
1251
  }
1314
1252
  // Stop traversal of this branch
1315
1253
  return false;
1316
1254
  }
1317
- // bitmarkAst -> bits -> bitsValue -> cardNode -> definitions -> definitionsValue -> definition
1318
- enter_definition(node, route) {
1319
- const parent = this.getParentNode(route);
1320
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.definitionsValue)
1321
- return true;
1322
- if (node.value) {
1323
- this.textGenerator.generateSync(node.value, TextFormat_1.TextFormat.bitmarkMinusMinus);
1324
- }
1325
- // Stop traversal of this branch
1326
- return false;
1327
- }
1328
1255
  // bitmarkAst -> bits -> bitsValue -> cardNode -> captionDefinitionList -> definitions -> definitionsValue -> definition
1329
1256
  leaf_definition(node, route) {
1330
1257
  const parent = this.getParentNode(route);
1331
1258
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.definitionsValue)
1332
1259
  return true;
1333
1260
  if (node.value) {
1261
+ this.writeNL();
1334
1262
  this.write(node.value);
1335
1263
  }
1336
1264
  // Stop traversal of this branch
@@ -1342,9 +1270,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1342
1270
  const parent = this.getParentNode(route);
1343
1271
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.cardNode && (parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.captionDefinitionList)
1344
1272
  return;
1345
- this.writeNL();
1346
1273
  this.writeCardSetCardDivider();
1347
- this.writeNL();
1348
1274
  }
1349
1275
  // bitmarkAst -> bits -> bitsValue -> cardNode -> definitions -> definitionsValue
1350
1276
  between_definitionsValue(_node, _left, right, route) {
@@ -1356,75 +1282,37 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1356
1282
  if (!this.isCardAllowed(route))
1357
1283
  return;
1358
1284
  if (right.key === NodeType_1.NodeType.definition) {
1359
- this.writeNL();
1360
1285
  this.writeCardSetSideDivider();
1361
- this.writeNL();
1362
1286
  }
1363
1287
  else if (right.key === NodeType_1.NodeType.alternativeDefinitions && ((_a = right.value) === null || _a === void 0 ? void 0 : _a.length) > 0) {
1364
- this.writeNL();
1365
1288
  this.writeCardSetVariantDivider();
1366
- this.writeNL();
1367
1289
  }
1368
1290
  }
1369
- // bitmarkAst -> bits -> bitsValue -> cardNode -> captionDefinitionList -> definitions -> definitionsValue
1370
- // protected between_definitionsValue(_node: NodeInfo, _left: NodeInfo, right: NodeInfo, route: NodeInfo[]): void {
1371
- // const parent = this.getParentNode(route);
1372
- // if (parent?.key !== NodeType.definitions) return;
1373
- // // Ignore cards if not allowed
1374
- // if (!this.isCardAllowed(route)) return;
1375
- // if (right.key === NodeType.definition) {
1376
- // this.writeNL();
1377
- // this.writeCardSetSideDivider();
1378
- // this.writeNL();
1379
- // } else if (right.key === NodeType.alternativeDefinitions && right.value?.length > 0) {
1380
- // this.writeNL();
1381
- // this.writeCardSetVariantDivider();
1382
- // this.writeNL();
1383
- // }
1384
- // }
1385
1291
  // bitmarkAst -> bits -> bitsValue -> cardNode -> questions
1386
1292
  enter_questions(_node, _route) {
1387
1293
  //
1388
1294
  }
1389
1295
  between_questions(_node, _left, _right, _route) {
1390
1296
  this.writeCardSetCardDivider();
1391
- this.writeNL();
1392
- }
1393
- exit_questions(_node, _route) {
1394
- //
1395
- }
1396
- // bitmarkAst -> bits -> bitsValue -> cardNode -> questions -> questionsValue
1397
- between_questionsValue(node, left, right, route) {
1398
- // The following keys are combined with other keys so don't need newlines
1399
- const noNlKeys = [
1400
- //
1401
- ];
1402
- this.writeNlBetween(node, left, right, route, noNlKeys);
1403
- }
1404
- exit_questionsValue(_node, _route) {
1405
- this.writeNL();
1406
1297
  }
1407
1298
  // bitmarkAst -> bits -> bitsValue -> cardNode -> ingredients
1408
1299
  enter_ingredients(_node, _route) {
1409
1300
  //
1410
1301
  }
1411
1302
  between_ingredients(_node, _left, _right, _route) {
1412
- this.writeNL();
1413
1303
  this.writeCardSetCardDivider();
1414
- this.writeNL();
1415
- }
1416
- exit_ingredients(_node, _route) {
1417
- //
1418
1304
  }
1419
1305
  // bitmarkAst -> bits -> bitsValue -> cardNode -> ingredients -> ingredientsValue
1420
1306
  enter_ingredientsValue(node, _route) {
1421
1307
  const ingredient = node.value;
1422
1308
  if (ingredient.title != null) {
1309
+ this.writeNL();
1423
1310
  this.writeOPHASH();
1424
1311
  this.writeBreakscapedTagString(ingredient.title);
1425
1312
  this.writeCL();
1426
- this.writeNL();
1313
+ // this.writeNL();
1427
1314
  }
1315
+ this.writeNL();
1428
1316
  // [+] / [-]
1429
1317
  if (ingredient.checked) {
1430
1318
  this.writeOPP();
@@ -1468,8 +1356,10 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1468
1356
  ignoreEmpty: true,
1469
1357
  });
1470
1358
  // item
1471
- if (ingredient.item != null)
1359
+ if (ingredient.item != null) {
1360
+ this.writeNL();
1472
1361
  this.write(ingredient.item);
1362
+ }
1473
1363
  // Stop traversal of this branch
1474
1364
  return false;
1475
1365
  }
@@ -1479,35 +1369,20 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1479
1369
  }
1480
1370
  between_botResponses(_node, _left, _right, _route) {
1481
1371
  this.writeCardSetCardDivider();
1482
- this.writeNL();
1483
- }
1484
- exit_botResponses(_node, _route) {
1485
- //
1486
- }
1487
- // bitmarkAst -> bits -> bitsValue -> cardNode -> botResponses -> botResponsesValue
1488
- between_botResponsesValue(_node, _left, _right, _route) {
1489
- this.writeNL();
1490
- }
1491
- exit_botResponsesValue(_node, _route) {
1492
- this.writeNL();
1493
1372
  }
1494
1373
  // bitmarkAst -> bits -> bitsValue -> cardNode -> cardBits
1495
1374
  enter_cardBits(_node, _route) {
1496
1375
  //
1497
1376
  }
1498
1377
  between_cardBits(_node, _left, _right, _route) {
1499
- this.writeNL();
1500
1378
  this.writeCardSetCardDivider();
1501
- this.writeNL();
1502
- }
1503
- exit_cardBits(_node, _route) {
1504
- //
1505
1379
  }
1506
1380
  // bitmarkAst -> bits -> bitsValue -> cardNode -> botResponses -> botResponsesValue -> response
1507
1381
  leaf_response(node, route) {
1508
1382
  const parent = this.getParentNode(route);
1509
1383
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.botResponsesValue)
1510
1384
  return;
1385
+ this.writeNL();
1511
1386
  this.writeOPB();
1512
1387
  this.writeBreakscapedTagString(node.value);
1513
1388
  this.writeCL();
@@ -1517,6 +1392,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1517
1392
  const parent = this.getParentNode(route);
1518
1393
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.botResponsesValue)
1519
1394
  return;
1395
+ this.writeNL();
1520
1396
  this.writeProperty('reaction', node.value, {
1521
1397
  format: PropertyFormat_1.PropertyFormat.trimmedString,
1522
1398
  single: true,
@@ -1530,6 +1406,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1530
1406
  return;
1531
1407
  const feeback = node.value;
1532
1408
  if (feeback) {
1409
+ this.writeNL();
1533
1410
  this.write(feeback);
1534
1411
  }
1535
1412
  }
@@ -1537,12 +1414,13 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1537
1414
  enter_imagePlaceholder(node, _route) {
1538
1415
  const resource = node.value;
1539
1416
  // This is a resource, so handle it with the common code
1417
+ this.writeNL();
1540
1418
  this.writePropertyStyleResource(node.key, resource);
1541
1419
  // Continue traversal
1542
1420
  return true;
1543
1421
  }
1544
1422
  exit_imagePlaceholder(_node, _route) {
1545
- this.writeNL();
1423
+ // this.writeNL();
1546
1424
  }
1547
1425
  // bitmarkAst -> bits -> bitsValue -> posterImage
1548
1426
  // bitmarkAst -> bits -> bitsValue -> resource -> * -> posterImage
@@ -1641,9 +1519,6 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1641
1519
  enter_book(_node, _route) {
1642
1520
  // Block standard property handling
1643
1521
  }
1644
- between_book(_node, _route) {
1645
- this.writeNL();
1646
- }
1647
1522
  enter_bookValue(node, _route) {
1648
1523
  const book = node.value;
1649
1524
  // const parent = this.getParentNode(route);
@@ -1714,10 +1589,11 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1714
1589
  // * -> itemLead --> item
1715
1590
  // * -> itemLead --> lead
1716
1591
  // * -> hint
1717
- enter_hint(node, _route) {
1592
+ enter_hint(node, route) {
1718
1593
  const value = node.value;
1719
1594
  const text = value;
1720
1595
  if (!this.isEmptyText(text)) {
1596
+ this.writeNL_IfNotChain(route);
1721
1597
  this.writeOPQ();
1722
1598
  this.textGenerator.generateSync(text, TextFormat_1.TextFormat.bitmarkMinusMinus);
1723
1599
  this.writeCL();
@@ -1726,10 +1602,11 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1726
1602
  return false;
1727
1603
  }
1728
1604
  // bitmarkAst -> bits -> bitsValue -> * -> instruction
1729
- enter_instruction(node, _route) {
1605
+ enter_instruction(node, route) {
1730
1606
  const value = node.value;
1731
1607
  const text = value;
1732
1608
  if (!this.isEmptyText(text)) {
1609
+ this.writeNL_IfNotChain(route);
1733
1610
  this.writeOPB();
1734
1611
  this.textGenerator.generateSync(text, TextFormat_1.TextFormat.bitmarkMinusMinus);
1735
1612
  this.writeCL();
@@ -1739,6 +1616,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1739
1616
  }
1740
1617
  // bitmarkAst -> bits -> bitsValue -> * -> lang
1741
1618
  enter_lang(node, _route) {
1619
+ this.writeNL();
1742
1620
  this.writeProperty('lang', node.value, {
1743
1621
  format: PropertyFormat_1.PropertyFormat.boolean,
1744
1622
  single: true,
@@ -1747,6 +1625,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1747
1625
  }
1748
1626
  // bitmarkAst -> bits -> bitsValue -> * -> refAuthor
1749
1627
  enter_refAuthor(node, _route) {
1628
+ this.writeNL();
1750
1629
  this.writeProperty('refAuthor', node.value, {
1751
1630
  format: PropertyFormat_1.PropertyFormat.trimmedString,
1752
1631
  single: false,
@@ -1755,6 +1634,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1755
1634
  }
1756
1635
  // bitmarkAst -> bits -> bitsValue -> * -> refBookTitle
1757
1636
  enter_refBookTitle(node, _route) {
1637
+ this.writeNL();
1758
1638
  this.writeProperty('refBookTitle', node.value, {
1759
1639
  format: PropertyFormat_1.PropertyFormat.trimmedString,
1760
1640
  single: true,
@@ -1763,6 +1643,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1763
1643
  }
1764
1644
  // bitmarkAst -> bits -> bitsValue -> * -> refPublisher
1765
1645
  enter_refPublisher(node, _route) {
1646
+ this.writeNL();
1766
1647
  this.writeProperty('refPublisher', node.value, {
1767
1648
  format: PropertyFormat_1.PropertyFormat.trimmedString,
1768
1649
  single: false,
@@ -1779,6 +1660,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1779
1660
  }
1780
1661
  // bitmarkAst -> bits -> bitsValue -> * -> citationStyle
1781
1662
  enter_citationStyle(node, _route) {
1663
+ this.writeNL();
1782
1664
  this.writeProperty('citationStyle', node.value, {
1783
1665
  format: PropertyFormat_1.PropertyFormat.trimmedString,
1784
1666
  single: true,
@@ -1795,6 +1677,8 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1795
1677
  const example = (_a = parent === null || parent === void 0 ? void 0 : parent.value.example) !== null && _a !== void 0 ? _a : null;
1796
1678
  // const __isDefaultExample = parent?.value.__isDefaultExample ?? false;
1797
1679
  if (example != null && example !== '') {
1680
+ // Write a newline if not in a chain
1681
+ this.writeNL_IfNotChain(route);
1798
1682
  this.writeOPA();
1799
1683
  this.writeString('example');
1800
1684
  this.writeColon();
@@ -1824,6 +1708,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1824
1708
  // bitmarkAst -> bits -> bitsValue -> elements -> elementsValue
1825
1709
  leaf_elementsValue(node, _route) {
1826
1710
  if (node.value) {
1711
+ this.writeNL();
1827
1712
  this.writeBreakscapedTagString(node.value);
1828
1713
  }
1829
1714
  }
@@ -1869,18 +1754,21 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1869
1754
  // bitmarkAst -> bits -> bitsValue -> * -> isCorrect
1870
1755
  // bitmarkAst -> bits -> bitsValue -> heading -> forKeys
1871
1756
  leaf_forKeys(node, _route) {
1757
+ this.writeNL();
1872
1758
  this.writeOPHASH();
1873
1759
  this.writeBreakscapedTagString(node.value);
1874
1760
  this.writeCL();
1875
1761
  }
1876
1762
  // bitmarkAst -> bits -> bitsValue -> heading -> forValues
1877
1763
  leaf_forValues(node, _route) {
1764
+ this.writeNL();
1878
1765
  this.writeOPHASH();
1879
1766
  this.writeBreakscapedTagString(node.value);
1880
1767
  this.writeCL();
1881
1768
  }
1882
1769
  // bitmarkAst -> bits -> bitsValue -> heading -> forValuesValue
1883
1770
  leaf_forValuesValue(node, _route) {
1771
+ this.writeNL();
1884
1772
  this.writeOPHASH();
1885
1773
  this.writeBreakscapedTagString(node.value);
1886
1774
  this.writeCL();
@@ -1889,6 +1777,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1889
1777
  // bitmarkAst -> bits -> bitsValue -> matrix -> matrixValue -> key
1890
1778
  leaf_key(node, _route) {
1891
1779
  if (node.value) {
1780
+ this.writeNL();
1892
1781
  this.writeBreakscapedTagString(node.value);
1893
1782
  }
1894
1783
  }
@@ -1896,6 +1785,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1896
1785
  // bitmarkAst -> bits -> bitsValue -> matrix -> matrixValue -> cells -> cellsValue -> values -> valuesValue
1897
1786
  leaf_valuesValue(node, _route) {
1898
1787
  if (node.value) {
1788
+ this.writeNL();
1899
1789
  this.writeBreakscapedTagString(node.value);
1900
1790
  }
1901
1791
  }
@@ -1907,23 +1797,10 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1907
1797
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.questionsValue && (parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.flashcardsValue)
1908
1798
  return;
1909
1799
  if (node.value) {
1800
+ this.writeNL();
1910
1801
  this.writeBreakscapedTagString(node.value);
1911
- // this.writeNL();
1912
1802
  }
1913
1803
  }
1914
- enter_question(node, route) {
1915
- // Ignore responses that are not at the questionsValue level as they are handled elsewhere
1916
- const parent = this.getParentNode(route);
1917
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.questionsValue && (parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.flashcardsValue)
1918
- return true;
1919
- if (node.value) {
1920
- this.textGenerator.generateSync(node.value, TextFormat_1.TextFormat.bitmarkMinusMinus);
1921
- // this.writeString(node.value);
1922
- // this.writeNL();
1923
- }
1924
- // Stop traversal of this branch
1925
- return false;
1926
- }
1927
1804
  // bitmarkAst -> bits -> bitsValue -> statements -> text
1928
1805
  // bitmarkAst -> bits -> bitsValue -> resource -> ...
1929
1806
  // bitmarkAst -> bits -> bitsValue -> resource -> posterImage -> ...
@@ -2028,8 +1905,9 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2028
1905
  ignoreFalse: true,
2029
1906
  });
2030
1907
  }
2031
- enter_caption(node, _route) {
1908
+ enter_caption(node, route) {
2032
1909
  const value = node.value;
1910
+ this.writeNL_IfNotChain(route);
2033
1911
  this.writeProperty('caption', value, {
2034
1912
  format: PropertyFormat_1.PropertyFormat.bitmarkMinusMinus,
2035
1913
  single: true, // ??
@@ -2092,17 +1970,6 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2092
1970
  //
2093
1971
  // Resources
2094
1972
  //
2095
- // bitmarkAst -> bits -> bitsValue -> resources
2096
- between_resources(_node, _left, _right, _route) {
2097
- this.writeNL();
2098
- }
2099
- exit_resources(_node, _left, _right, _route) {
2100
- this.writeNL();
2101
- }
2102
- // bitmarkAst -> bits -> bitsValue -> resourcesValue
2103
- between_resourcesValue(_node, _left, _right, _route) {
2104
- this.writeNL();
2105
- }
2106
1973
  //
2107
1974
  // Generated Node Handlers
2108
1975
  //
@@ -2137,6 +2004,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2137
2004
  // url / src / href / app
2138
2005
  const url = resource.url || resource.src || resource.body || '';
2139
2006
  // Write the resource
2007
+ this.writeNL();
2140
2008
  this.writeResource(type, url);
2141
2009
  // Continue traversal
2142
2010
  return true;
@@ -2149,14 +2017,6 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2149
2017
  /**
2150
2018
  * Generate the handlers for properties, as they are mostly the same, but not quite
2151
2019
  */
2152
- // protected enter_labelTrue(node: NodeInfo, _route: NodeInfo[],
2153
- // ): void {
2154
- // const bit = parent?.value as Bit;
2155
- // if (bit) {
2156
- // this.writeProperty('labelTrue', node.value ?? '', true);
2157
- // this.writeProperty('labelFalse', bit.labelFalse ?? '', true);
2158
- // }
2159
- // }
2160
2020
  generatePropertyHandlers() {
2161
2021
  var _a;
2162
2022
  const propertiesConfig = Config_1.Config.getRawPropertiesConfig();
@@ -2183,6 +2043,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2183
2043
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.bitsValue)
2184
2044
  return;
2185
2045
  // Write the property
2046
+ this.writeNL(); // Only if NOT in chain (how do we know this?)
2186
2047
  this.writeProperty(propertyConfig.tag, node.value, {
2187
2048
  format: (_a = propertyConfig.format) !== null && _a !== void 0 ? _a : PropertyFormat_1.PropertyFormat.trimmedString,
2188
2049
  single: (_b = propertyConfig.single) !== null && _b !== void 0 ? _b : false,
@@ -2195,35 +2056,44 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2195
2056
  this[enterFuncName] = this[enterFuncName].bind(this);
2196
2057
  }
2197
2058
  }
2198
- writeNlBetween(node, left, _right, _route,
2199
- // The following keys are combined with other keys so don't need newlines
2200
- noNlKeys) {
2201
- const bit = node.value;
2202
- if (bit.book) {
2203
- // If the book node exists, remove the newline caused by reference as it will be bound to book
2204
- noNlKeys.push(NodeType_1.NodeType.reference);
2205
- }
2206
- // Check if a no newline key is to the left in this 'between' callback
2207
- const noNl = (() => {
2208
- if (!this.wroteSomething || this.skipNLBetweenBitsValue) {
2209
- return true;
2210
- }
2211
- for (const keyType of noNlKeys) {
2212
- if (left.key === keyType /*|| right.key === keyType*/)
2213
- return true;
2214
- }
2215
- return false;
2216
- })();
2217
- if (!noNl) {
2218
- this.writeNL();
2219
- }
2220
- this.skipNLBetweenBitsValue = false;
2221
- this.wroteSomething = false;
2222
- }
2223
2059
  // END NODE HANDLERS
2224
2060
  //
2225
2061
  // UTILITY FUNCTIONS
2226
2062
  //
2063
+ /**
2064
+ * Check if in a chain.
2065
+ *
2066
+ * Return false if at the root of the bit or a card bit, otherwise true.
2067
+ * This is useful to determine if a newline should be written before certain properties.
2068
+ *
2069
+ * @param route
2070
+ * @returns
2071
+ */
2072
+ isChain(route) {
2073
+ const parent = this.getParentNode(route);
2074
+ // Root of bit
2075
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) === NodeType_1.NodeType.bitsValue)
2076
+ return false;
2077
+ // Root of card bits
2078
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) === NodeType_1.NodeType.cardBitsValue)
2079
+ return false;
2080
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) === NodeType_1.NodeType.feedbacksValue)
2081
+ return false;
2082
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) === NodeType_1.NodeType.quizzesValue)
2083
+ return false;
2084
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) === NodeType_1.NodeType.pairsValue)
2085
+ return false;
2086
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) === NodeType_1.NodeType.matrixValue)
2087
+ return false;
2088
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) === NodeType_1.NodeType.definitionsValue)
2089
+ return false;
2090
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) === NodeType_1.NodeType.questionsValue)
2091
+ return false;
2092
+ // Root of sub-card bits
2093
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) === NodeType_1.NodeType.reason)
2094
+ return false;
2095
+ return true;
2096
+ }
2227
2097
  haveValidCardSet(bit) {
2228
2098
  const bitConfig = Config_1.Config.getBitConfig(bit.bitType);
2229
2099
  if (!bitConfig)
@@ -2355,17 +2225,20 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2355
2225
  this.write('#');
2356
2226
  }
2357
2227
  writePlainTextDivider() {
2228
+ this.writeNL();
2358
2229
  this.write('==== text ====');
2359
2230
  }
2360
2231
  writeCardSetStart() {
2232
+ this.writeNL();
2361
2233
  if (this.options.cardSetVersion === CardSetVersion_1.CardSetVersion.v1) {
2362
- this.write('\n===');
2234
+ this.write('===');
2363
2235
  }
2364
2236
  else {
2365
- this.write('\n====');
2237
+ this.write('====');
2366
2238
  }
2367
2239
  }
2368
2240
  writeCardSetEnd() {
2241
+ this.writeNL();
2369
2242
  if (this.options.cardSetVersion === CardSetVersion_1.CardSetVersion.v1) {
2370
2243
  this.write('===');
2371
2244
  }
@@ -2374,6 +2247,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2374
2247
  }
2375
2248
  }
2376
2249
  writeCardSetCardDivider() {
2250
+ this.writeNL();
2377
2251
  if (this.options.cardSetVersion === CardSetVersion_1.CardSetVersion.v1) {
2378
2252
  this.write('===');
2379
2253
  }
@@ -2382,6 +2256,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2382
2256
  }
2383
2257
  }
2384
2258
  writeCardSetSideDivider() {
2259
+ this.writeNL();
2385
2260
  if (this.options.cardSetVersion === CardSetVersion_1.CardSetVersion.v1) {
2386
2261
  this.write('==');
2387
2262
  }
@@ -2390,6 +2265,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2390
2265
  }
2391
2266
  }
2392
2267
  writeCardSetVariantDivider() {
2268
+ this.writeNL();
2393
2269
  if (this.options.cardSetVersion === CardSetVersion_1.CardSetVersion.v1) {
2394
2270
  this.write('--');
2395
2271
  }
@@ -2397,6 +2273,11 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2397
2273
  this.write('++');
2398
2274
  }
2399
2275
  }
2276
+ writeNL_IfNotChain(route) {
2277
+ if (!this.isChain(route)) {
2278
+ this.writeNL();
2279
+ }
2280
+ }
2400
2281
  writeNL() {
2401
2282
  if (this.options.debugGenerationInline) {
2402
2283
  this.write('\\n');
@@ -2416,7 +2297,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2416
2297
  this.writeColon();
2417
2298
  this.writeBreakscapedTagString(src);
2418
2299
  if (resource.type === ResourceTag_1.ResourceTag.article) {
2419
- this.writeNL();
2300
+ // this.writeNL();
2420
2301
  }
2421
2302
  this.writeCL();
2422
2303
  }
@@ -2430,7 +2311,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2430
2311
  this.writeColon();
2431
2312
  this.writeBreakscapedTagString(value);
2432
2313
  if (type === ResourceTag_1.ResourceTag.article) {
2433
- this.writeNL();
2314
+ // this.writeNL();
2434
2315
  }
2435
2316
  this.writeCL();
2436
2317
  }
@@ -2438,7 +2319,6 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2438
2319
  writeProperty(name, values, options) {
2439
2320
  var _a;
2440
2321
  let valuesArray;
2441
- let wroteSomething = false;
2442
2322
  if (values !== undefined) {
2443
2323
  const isBitmarkText = options.format === PropertyFormat_1.PropertyFormat.bitmarkMinusMinus || options.format === PropertyFormat_1.PropertyFormat.bitmarkPlusPlus;
2444
2324
  if (isBitmarkText) {
@@ -2450,7 +2330,6 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2450
2330
  this.writeColon();
2451
2331
  this.textGenerator.generateSync(values, (_a = TextFormat_1.TextFormat.fromValue(options.format)) !== null && _a !== void 0 ? _a : TextFormat_1.TextFormat.bitmarkMinusMinus);
2452
2332
  this.writeCL();
2453
- wroteSomething = true;
2454
2333
  }
2455
2334
  else {
2456
2335
  // Write any other property type
@@ -2463,7 +2342,6 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2463
2342
  if (valuesArray.length > 0) {
2464
2343
  if (options.single)
2465
2344
  valuesArray = valuesArray.slice(valuesArray.length - 1);
2466
- let propertyIndex = 0;
2467
2345
  for (const val of valuesArray) {
2468
2346
  if (val !== undefined) {
2469
2347
  if (options.ignoreFalse && val === false)
@@ -2472,23 +2350,17 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2472
2350
  continue;
2473
2351
  if (options.ignoreEmpty && val === '')
2474
2352
  continue;
2475
- if (propertyIndex > 0)
2476
- this.writeNL();
2477
2353
  this.writeOPA();
2478
2354
  this.writeBreakscapedTagString(name);
2479
2355
  this.writeColon();
2480
2356
  this.writeBreakscapedTagString(`${val}`);
2481
2357
  this.writeCL();
2482
- wroteSomething = true;
2483
- propertyIndex++;
2358
+ // propertyIndex++;
2484
2359
  }
2485
2360
  }
2486
2361
  }
2487
2362
  } // isBitmarkText
2488
2363
  }
2489
- if (!wroteSomething) {
2490
- this.skipNLBetweenBitsValue = true;
2491
- }
2492
2364
  }
2493
2365
  writeInlineDebug(key, state) {
2494
2366
  let tag = key;
@@ -2556,8 +2428,6 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2556
2428
  * @param value - The string value to be written.
2557
2429
  */
2558
2430
  write(value) {
2559
- if (value)
2560
- this.wroteSomething = true;
2561
2431
  this.writer.write(value);
2562
2432
  return this;
2563
2433
  }
@@ -2566,8 +2436,6 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2566
2436
  * @param value - The line to write. When omitted, only the endOfLineString is written.
2567
2437
  */
2568
2438
  writeLine(value) {
2569
- if (value)
2570
- this.wroteSomething = true;
2571
2439
  this.writer.writeLine(value);
2572
2440
  return this;
2573
2441
  }
@@ -2577,8 +2445,6 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2577
2445
  * @param delimiter - An optional delimiter to be written at the end of each line, except for the last one.
2578
2446
  */
2579
2447
  writeLines(values, delimiter) {
2580
- if (values.length > 0 && values.reduce((acc, v) => (v ? true : acc), false))
2581
- this.wroteSomething = true;
2582
2448
  this.writer.writeLines(values, delimiter);
2583
2449
  return this;
2584
2450
  }