@gmb/bitmark-parser-generator 3.11.0 → 3.12.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 (100) 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/ast/BaseBuilder.js +2 -0
  4. package/dist/cjs/ast/BaseBuilder.js.map +1 -1
  5. package/dist/cjs/ast/Builder.js +32 -3
  6. package/dist/cjs/ast/Builder.js.map +1 -1
  7. package/dist/cjs/ast/ResourceBuilder.js +1 -0
  8. package/dist/cjs/ast/ResourceBuilder.js.map +1 -1
  9. package/dist/cjs/config/raw/bits.js +30 -0
  10. package/dist/cjs/config/raw/bits.js.map +1 -1
  11. package/dist/cjs/config/raw/cardSets.js +4 -0
  12. package/dist/cjs/config/raw/cardSets.js.map +1 -1
  13. package/dist/cjs/config/raw/groups.js +15 -0
  14. package/dist/cjs/config/raw/groups.js.map +1 -1
  15. package/dist/cjs/config/raw/properties.js +5 -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/generator/bitmark/BitmarkGenerator.js +238 -398
  19. package/dist/cjs/generator/bitmark/BitmarkGenerator.js.map +1 -1
  20. package/dist/cjs/model/ast/NodeType.js +2 -0
  21. package/dist/cjs/model/ast/NodeType.js.map +1 -1
  22. package/dist/cjs/model/config/enum/GroupConfigKey.js +1 -0
  23. package/dist/cjs/model/config/enum/GroupConfigKey.js.map +1 -1
  24. package/dist/cjs/model/config/enum/PropertyConfigKey.js +1 -0
  25. package/dist/cjs/model/config/enum/PropertyConfigKey.js.map +1 -1
  26. package/dist/cjs/model/enum/BitType.js +10 -0
  27. package/dist/cjs/model/enum/BitType.js.map +1 -1
  28. package/dist/cjs/model/enum/ResourceTag.js +1 -0
  29. package/dist/cjs/model/enum/ResourceTag.js.map +1 -1
  30. package/dist/cjs/parser/bitmark/peg/BitmarkPegParserTypes.js.map +1 -1
  31. package/dist/cjs/parser/bitmark/peg/contentProcessors/CardContentProcessor.js +26 -16
  32. package/dist/cjs/parser/bitmark/peg/contentProcessors/CardContentProcessor.js.map +1 -1
  33. package/dist/cjs/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.js +5 -0
  34. package/dist/cjs/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.js.map +1 -1
  35. package/dist/esm/ast/BaseBuilder.js +2 -0
  36. package/dist/esm/ast/BaseBuilder.js.map +1 -1
  37. package/dist/esm/ast/Builder.js +32 -3
  38. package/dist/esm/ast/Builder.js.map +1 -1
  39. package/dist/esm/ast/ResourceBuilder.js +1 -0
  40. package/dist/esm/ast/ResourceBuilder.js.map +1 -1
  41. package/dist/esm/config/raw/bits.js +30 -0
  42. package/dist/esm/config/raw/bits.js.map +1 -1
  43. package/dist/esm/config/raw/cardSets.js +4 -0
  44. package/dist/esm/config/raw/cardSets.js.map +1 -1
  45. package/dist/esm/config/raw/groups.js +15 -0
  46. package/dist/esm/config/raw/groups.js.map +1 -1
  47. package/dist/esm/config/raw/properties.js +5 -0
  48. package/dist/esm/config/raw/properties.js.map +1 -1
  49. package/dist/esm/generated/build-info.js +1 -1
  50. package/dist/esm/generator/bitmark/BitmarkGenerator.js +238 -398
  51. package/dist/esm/generator/bitmark/BitmarkGenerator.js.map +1 -1
  52. package/dist/esm/model/ast/NodeType.js +2 -0
  53. package/dist/esm/model/ast/NodeType.js.map +1 -1
  54. package/dist/esm/model/config/enum/GroupConfigKey.js +1 -0
  55. package/dist/esm/model/config/enum/GroupConfigKey.js.map +1 -1
  56. package/dist/esm/model/config/enum/PropertyConfigKey.js +1 -0
  57. package/dist/esm/model/config/enum/PropertyConfigKey.js.map +1 -1
  58. package/dist/esm/model/enum/BitType.js +10 -0
  59. package/dist/esm/model/enum/BitType.js.map +1 -1
  60. package/dist/esm/model/enum/ResourceTag.js +1 -0
  61. package/dist/esm/model/enum/ResourceTag.js.map +1 -1
  62. package/dist/esm/parser/bitmark/peg/BitmarkPegParserTypes.js.map +1 -1
  63. package/dist/esm/parser/bitmark/peg/contentProcessors/CardContentProcessor.js +26 -16
  64. package/dist/esm/parser/bitmark/peg/contentProcessors/CardContentProcessor.js.map +1 -1
  65. package/dist/esm/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.js +6 -1
  66. package/dist/esm/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.js.map +1 -1
  67. package/dist/types/ast/BaseBuilder.d.ts +2 -0
  68. package/dist/types/ast/BaseBuilder.d.ts.map +1 -1
  69. package/dist/types/ast/Builder.d.ts +3 -1
  70. package/dist/types/ast/Builder.d.ts.map +1 -1
  71. package/dist/types/ast/ResourceBuilder.d.ts.map +1 -1
  72. package/dist/types/config/raw/bits.d.ts.map +1 -1
  73. package/dist/types/config/raw/cardSets.d.ts.map +1 -1
  74. package/dist/types/config/raw/groups.d.ts.map +1 -1
  75. package/dist/types/config/raw/properties.d.ts.map +1 -1
  76. package/dist/types/generator/bitmark/BitmarkGenerator.d.ts +15 -43
  77. package/dist/types/generator/bitmark/BitmarkGenerator.d.ts.map +1 -1
  78. package/dist/types/model/ast/NodeType.d.ts +4 -0
  79. package/dist/types/model/ast/NodeType.d.ts.map +1 -1
  80. package/dist/types/model/ast/Nodes.d.ts +1 -0
  81. package/dist/types/model/ast/Nodes.d.ts.map +1 -1
  82. package/dist/types/model/config/enum/ConfigKey.d.ts +4 -0
  83. package/dist/types/model/config/enum/ConfigKey.d.ts.map +1 -1
  84. package/dist/types/model/config/enum/GroupConfigKey.d.ts +3 -0
  85. package/dist/types/model/config/enum/GroupConfigKey.d.ts.map +1 -1
  86. package/dist/types/model/config/enum/PropertyConfigKey.d.ts +3 -0
  87. package/dist/types/model/config/enum/PropertyConfigKey.d.ts.map +1 -1
  88. package/dist/types/model/enum/BitType.d.ts +20 -0
  89. package/dist/types/model/enum/BitType.d.ts.map +1 -1
  90. package/dist/types/model/enum/PropertyTag.d.ts +2 -0
  91. package/dist/types/model/enum/PropertyTag.d.ts.map +1 -1
  92. package/dist/types/model/enum/ResourceTag.d.ts +2 -0
  93. package/dist/types/model/enum/ResourceTag.d.ts.map +1 -1
  94. package/dist/types/model/json/BitJson.d.ts +11 -6
  95. package/dist/types/model/json/BitJson.d.ts.map +1 -1
  96. package/dist/types/parser/bitmark/peg/BitmarkPegParserTypes.d.ts +2 -1
  97. package/dist/types/parser/bitmark/peg/BitmarkPegParserTypes.d.ts.map +1 -1
  98. package/dist/types/parser/bitmark/peg/contentProcessors/CardContentProcessor.d.ts.map +1 -1
  99. package/dist/types/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.d.ts.map +1 -1
  100. package/package.json +1 -1
@@ -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,88 @@ 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
+ return true;
446
+ }
447
+ if (StringUtils_1.StringUtils.isString(node.value)) {
448
+ const str = node.value;
449
+ this.writeNL();
450
+ this.write(Breakscape_1.Breakscape.breakscape(str, {
451
+ textFormat: TextFormat_1.TextFormat.text,
452
+ }));
453
+ }
454
+ // Stop traversal of this branch
455
+ return false;
456
+ }
457
+ // bitmarkAst -> bits -> bitsValue -> * -> term -> icon
458
+ // bitmarkAst -> bits -> bitsValue -> * -> definition -> icon
459
+ // bitmarkAst -> bits -> bitsValue -> * -> alternativeDefinitionsValue -> icon
460
+ enter_icon(node, route) {
461
+ const resource = node.value;
462
+ const parent = this.getParentNode(route);
463
+ if (!parent)
464
+ return true;
465
+ if (parent.key !== NodeType_1.NodeType.term &&
466
+ parent.key !== NodeType_1.NodeType.definition &&
467
+ parent.key !== NodeType_1.NodeType.alternativeDefinitionsValue &&
468
+ parent.key !== NodeType_1.NodeType.question &&
469
+ parent.key !== NodeType_1.NodeType.answer &&
470
+ parent.key !== NodeType_1.NodeType.alternativeAnswersValue) {
471
+ // Continue traversal of this branch
472
+ return true;
473
+ }
474
+ // This is a resource, so handle it with the common code
475
+ this.writeNL();
476
+ this.writeResource(ResourceTag_1.ResourceTag.icon, resource.src);
477
+ // this.writePropertyStyleResource(ResourceTag.icon, resource as ResourceJson);
478
+ // Continue traversal of this branch (for the chained properties)
479
+ return true;
480
+ }
481
+ leaf_iconValue(node, _route) {
482
+ // Handle as a standard icon property
483
+ this.writeNL();
484
+ this.writeProperty('icon', node.value, {
485
+ format: PropertyFormat_1.PropertyFormat.trimmedString,
486
+ single: true,
487
+ ignoreEmpty: true,
488
+ });
489
+ // Stop traversal of this branch
490
+ return false;
491
+ }
408
492
  // bitmarkAst -> bits -> bitsValue -> ratingLevelStart
409
493
  enter_ratingLevelStart(node, route) {
410
494
  this.enterRatingLevelStartEndCommon(node, route);
@@ -426,6 +510,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
426
510
  return true;
427
511
  const { level, label } = n;
428
512
  const levelKey = node.key === NodeType_1.NodeType.ratingLevelStart ? PropertyTag_1.PropertyTag.ratingLevelStart : PropertyTag_1.PropertyTag.ratingLevelEnd;
513
+ this.writeNL();
429
514
  this.writeProperty(levelKey, level, {
430
515
  format: PropertyFormat_1.PropertyFormat.trimmedString,
431
516
  single: true,
@@ -455,6 +540,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
455
540
  return true;
456
541
  const { mark, color, emphasis } = markConfig;
457
542
  if (mark) {
543
+ this.writeNL();
458
544
  this.writeProperty('mark', mark, {
459
545
  format: PropertyFormat_1.PropertyFormat.trimmedString,
460
546
  single: true,
@@ -474,74 +560,79 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
474
560
  ignoreEmpty: true,
475
561
  });
476
562
  }
477
- this.writeNL();
478
563
  }
479
564
  // Stop traversal of this branch
480
565
  return false;
481
566
  }
482
567
  // bitmarkAst -> bits -> bitsValue -> partialAnswer
483
568
  enter_partialAnswer(node, _route) {
484
- this.writeProperty('partialAnswer', node.value, {
485
- format: PropertyFormat_1.PropertyFormat.trimmedString,
486
- single: true,
487
- ignoreEmpty: true,
488
- });
569
+ if (node.value) {
570
+ this.writeNL();
571
+ this.writeProperty('partialAnswer', node.value, {
572
+ format: PropertyFormat_1.PropertyFormat.trimmedString,
573
+ single: true,
574
+ ignoreEmpty: true,
575
+ });
576
+ }
489
577
  // Stop traversal of this branch
490
578
  return false;
491
579
  }
492
580
  // bitmarkAst -> bits -> bitsValue -> questions -> questionsValue -> partialAnswer
493
581
  leaf_partialAnswer(node, _route) {
494
- this.writeProperty('partialAnswer', node.value, {
495
- format: PropertyFormat_1.PropertyFormat.trimmedString,
496
- single: true,
497
- ignoreEmpty: true,
498
- });
582
+ if (node.value) {
583
+ this.writeNL();
584
+ this.writeProperty('partialAnswer', node.value, {
585
+ format: PropertyFormat_1.PropertyFormat.trimmedString,
586
+ single: true,
587
+ ignoreEmpty: true,
588
+ });
589
+ }
499
590
  // Stop traversal of this branch
500
591
  return false;
501
592
  }
502
593
  // bitmarkAst -> bits -> bitsValue -> sampleSolution
503
594
  // bitmarkAst -> bits -> bitsValue -> questions -> questionsValue -> sampleSolution
504
595
  enter_sampleSolution(node, _route) {
505
- this.writeProperty('sampleSolution', node.value, {
506
- format: PropertyFormat_1.PropertyFormat.trimmedString,
507
- single: true,
508
- ignoreEmpty: true,
509
- });
596
+ if (node.value) {
597
+ this.writeNL();
598
+ this.writeProperty('sampleSolution', node.value, {
599
+ format: PropertyFormat_1.PropertyFormat.trimmedString,
600
+ single: true,
601
+ ignoreEmpty: true,
602
+ });
603
+ }
510
604
  // Stop traversal of this branch
511
605
  return false;
512
606
  }
513
607
  leaf_sampleSolution(node, _route) {
514
- this.writeProperty('sampleSolution', node.value, {
515
- format: PropertyFormat_1.PropertyFormat.trimmedString,
516
- single: true,
517
- ignoreEmpty: true,
518
- });
608
+ if (node.value) {
609
+ this.writeNL();
610
+ this.writeProperty('sampleSolution', node.value, {
611
+ format: PropertyFormat_1.PropertyFormat.trimmedString,
612
+ single: true,
613
+ ignoreEmpty: true,
614
+ });
615
+ }
519
616
  // Stop traversal of this branch
520
617
  return false;
521
618
  }
522
619
  // bitmarkAst -> bits -> bitsValue -> reasonableNumOfChars
523
620
  // bitmarkAst -> bits -> bitsValue -> questions -> questionsValue -> reasonableNumOfChars
524
621
  leaf_reasonableNumOfChars(node, _route) {
622
+ this.writeNL();
525
623
  this.writeProperty('reasonableNumOfChars', node.value, {
526
624
  format: PropertyFormat_1.PropertyFormat.trimmedString,
527
625
  single: true,
528
626
  ignoreEmpty: true,
529
627
  });
530
628
  }
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
629
  // bitmarkAst -> bits -> bitsValue -> questions -> questionsValue -> additionalSolutions -> additionalSolutionsValue
540
630
  leaf_additionalSolutionsValue(node, route) {
541
631
  // Ignore values that are not at the bit level as they might be handled elsewhere
542
632
  const parent = this.getParentNode(route, 2);
543
633
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.questionsValue)
544
634
  return;
635
+ this.writeNL();
545
636
  this.writeProperty('additionalSolutions', node.value, {
546
637
  format: PropertyFormat_1.PropertyFormat.trimmedString,
547
638
  single: false,
@@ -560,6 +651,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
560
651
  return true; // Will be handled by pageNumber
561
652
  if (!this.isEmptyText((_c = parent === null || parent === void 0 ? void 0 : parent.value) === null || _c === void 0 ? void 0 : _c.marginNumber))
562
653
  return true; // Will be handled by marginNumber
654
+ this.writeNL_IfNotChain(route);
563
655
  this.writeOPC();
564
656
  this.textGenerator.generateSync(item, TextFormat_1.TextFormat.bitmarkMinusMinus);
565
657
  this.writeCL();
@@ -576,6 +668,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
576
668
  return true; // Will be handled by pageNumber
577
669
  if (!this.isEmptyText((_b = parent === null || parent === void 0 ? void 0 : parent.value) === null || _b === void 0 ? void 0 : _b.marginNumber))
578
670
  return true; // Will be handled by marginNumber
671
+ this.writeNL_IfNotChain(route);
579
672
  this.writeOPC();
580
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_1.TextFormat.bitmarkMinusMinus);
581
674
  this.writeCL();
@@ -593,6 +686,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
593
686
  return false; // Ignore empty
594
687
  if (!this.isEmptyText((_a = parent === null || parent === void 0 ? void 0 : parent.value) === null || _a === void 0 ? void 0 : _a.marginNumber))
595
688
  return true; // Will be handled by marginNumber
689
+ this.writeNL_IfNotChain(route);
596
690
  this.writeOPC();
597
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_1.TextFormat.bitmarkMinusMinus);
598
692
  this.writeCL();
@@ -611,6 +705,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
611
705
  const parent = this.getParentNode(route);
612
706
  if (this.isEmptyText(marginNumber))
613
707
  return false; // Ignore empty
708
+ this.writeNL_IfNotChain(route);
614
709
  this.writeOPC();
615
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_1.TextFormat.bitmarkMinusMinus);
616
711
  this.writeCL();
@@ -633,7 +728,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
633
728
  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
729
  return true;
635
730
  this.inTag = false;
636
- // always write a NL before the body content if there is any?
731
+ // Always write a NL before the body content if there is any (see Handle body)
637
732
  const body = node.value;
638
733
  const textFormat = this.getTextFormat(route);
639
734
  const isBitmarkText = textFormat === TextFormat_1.TextFormat.bitmarkPlusPlus || textFormat === TextFormat_1.TextFormat.bitmarkMinusMinus;
@@ -643,7 +738,6 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
643
738
  if (Array.isArray(json) || ObjectUtils_1.ObjectUtils.isObject(json)) {
644
739
  const text = JSON.stringify(json, null, this.prettifySpace);
645
740
  if (text) {
646
- this.writeNL();
647
741
  this.writePlainTextDivider();
648
742
  this.writeNL();
649
743
  this.write(Breakscape_1.Breakscape.breakscape(text, {
@@ -664,27 +758,15 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
664
758
  }
665
759
  else {
666
760
  // handle plain text
667
- this.writeNL();
668
761
  this.writePlainTextDivider();
669
762
  this.writeNL();
670
763
  const s = (StringUtils_1.StringUtils.isString(body.body) ? body.body : '');
671
764
  this.write(Breakscape_1.Breakscape.breakscape(`${s}`, {
672
765
  textFormat: TextFormat_1.TextFormat.text,
673
766
  }));
674
- this.writeNL();
675
767
  }
676
768
  // Stop traversal of this branch
677
769
  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
770
  }
689
771
  exit_body(_node, _route) {
690
772
  this.inTag = true;
@@ -750,6 +832,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
750
832
  const isBitmarkText = textFormat === TextFormat_1.TextFormat.bitmarkPlusPlus || textFormat === TextFormat_1.TextFormat.bitmarkMinusMinus;
751
833
  if (isBitmarkText) {
752
834
  // handle bitmark text
835
+ this.writeNL();
753
836
  this.write('==== footer ====');
754
837
  this.writeNL();
755
838
  // The text generator will write to the writer
@@ -844,7 +927,6 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
844
927
  if (!this.isCardAllowed(route))
845
928
  return true;
846
929
  this.writeCardSetStart();
847
- this.writeNL();
848
930
  // Continue traversal
849
931
  return true;
850
932
  }
@@ -852,41 +934,27 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
852
934
  // Ignore cards if not allowed
853
935
  if (!this.isCardAllowed(route))
854
936
  return;
855
- this.writeNL();
856
937
  this.writeCardSetCardDivider();
857
- this.writeNL();
858
938
  }
859
939
  exit_cardNode(_node, route) {
860
940
  // Ignore cards if not allowed
861
941
  if (!this.isCardAllowed(route))
862
942
  return;
863
- this.writeNL();
864
943
  this.writeCardSetEnd();
865
944
  if (this.options.cardSetVersion === CardSetVersion_1.CardSetVersion.v1) {
866
- this.writeNL();
945
+ // this.writeNL();
867
946
  }
868
947
  }
869
- // bitmarkAst -> bits -> bitsValue -> cardNode -> cardBitsValue
870
- between_cardBitsValue(_node, _left, _right, _route) {
871
- this.writeNL();
872
- }
873
948
  // bitmarkAst -> bits -> bitsValue -> cardNode -> elements
874
949
  enter_elements(_node, _route) {
875
950
  //
876
951
  }
877
952
  between_elements(_node, _left, _right, _route) {
878
- this.writeNL();
879
953
  this.writeCardSetVariantDivider();
880
- this.writeNL();
881
- }
882
- exit_elements(_node, _route) {
883
- //
884
954
  }
885
955
  // bitmarkAst -> bits -> bitsValue -> cardNode -> flashcards
886
956
  between_flashcards(_node, _left, _right, _route) {
887
- this.writeNL();
888
957
  this.writeCardSetCardDivider();
889
- this.writeNL();
890
958
  }
891
959
  // bitmarkAst -> bits -> bitsValue -> cardNode -> flashcards -> flashcardsValue
892
960
  between_flashcardsValue(_node, _left, right, route) {
@@ -895,67 +963,19 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
895
963
  if (!this.isCardAllowed(route))
896
964
  return;
897
965
  if (right.key === NodeType_1.NodeType.answer) {
898
- this.writeNL();
899
966
  this.writeCardSetSideDivider();
900
- this.writeNL();
901
967
  }
902
968
  else if (right.key === NodeType_1.NodeType.alternativeAnswers && ((_a = right.value) === null || _a === void 0 ? void 0 : _a.length) !== 0) {
903
- this.writeNL();
904
969
  this.writeCardSetVariantDivider();
905
- this.writeNL();
906
970
  }
907
971
  }
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
972
  // bitmarkAst -> bits -> bitsValue -> cardNode -> flashcards -> flashcardsValue -> alternativeAnswers
921
973
  between_alternativeAnswers(_node, _route) {
922
- this.writeNL();
923
974
  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
975
  }
939
976
  // bitmarkAst -> bits -> bitsValue -> cardNode -> definitions -> definitionsValue -> alternativeDefintions
940
977
  between_alternativeDefinitions(_node, _route) {
941
- this.writeNL();
942
978
  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
979
  }
960
980
  // bitmarkAst -> bits -> bitsValue -> cardNode -> statements
961
981
  enter_statements(_node, _route) {
@@ -964,17 +984,13 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
964
984
  between_statements(_node, _left, _right, route) {
965
985
  const isTrueFalse1 = this.isOfBitType(route, BitType_1.BitType.trueFalse1);
966
986
  if (!isTrueFalse1) {
967
- this.writeNL();
968
987
  this.writeCardSetCardDivider();
969
988
  }
970
- this.writeNL();
971
- }
972
- exit_statements(_node, _route) {
973
- //
974
989
  }
975
990
  // bitmarkAst -> bits -> bitsValue -> cardNode -> statements -> statementsValue
976
991
  enter_statementsValue(node, _route) {
977
992
  const statement = node.value;
993
+ this.writeNL();
978
994
  if (statement.isCorrect) {
979
995
  this.writeOPP();
980
996
  }
@@ -986,18 +1002,11 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
986
1002
  // Continue traversal
987
1003
  return true;
988
1004
  }
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
1005
  // bitmarkAst -> bits -> bitsValue -> choices -> choicesValue
998
1006
  // bitmarkAst -> bits -> bitsValue -> cardNode -> quizzes -> quizzesValue -> choices -> choicesValue
999
1007
  enter_choicesValue(node, _route) {
1000
1008
  const choice = node.value;
1009
+ this.writeNL();
1001
1010
  if (choice.isCorrect) {
1002
1011
  this.writeOPP();
1003
1012
  }
@@ -1009,18 +1018,11 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1009
1018
  // Continue traversal
1010
1019
  return true;
1011
1020
  }
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
1021
  // bitmarkAst -> bits -> bitsValue -> responses -> responsesValue
1021
1022
  // bitmarkAst -> bits -> bitsValue -> cardNode -> quizzes -> quizzesValue -> responses -> responsesValue
1022
1023
  enter_responsesValue(node, _route) {
1023
1024
  const response = node.value;
1025
+ this.writeNL();
1024
1026
  if (response.isCorrect) {
1025
1027
  this.writeOPP();
1026
1028
  }
@@ -1037,18 +1039,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1037
1039
  //
1038
1040
  }
1039
1041
  between_quizzes(_node, _left, _right, _route) {
1040
- // this.writeNL();
1041
1042
  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
1043
  }
1053
1044
  // bitmarkAst -> bits -> bitsValue -> cardNode -> heading
1054
1045
  enter_heading(_node, _route) {
@@ -1058,12 +1049,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1058
1049
  // Ignore cards if not allowed
1059
1050
  if (!this.isCardAllowed(route))
1060
1051
  return;
1061
- this.writeNL();
1062
1052
  this.writeCardSetSideDivider();
1063
- this.writeNL();
1064
- }
1065
- exit_heading(_node, _route) {
1066
- //
1067
1053
  }
1068
1054
  // bitmarkAst -> bits -> bitsValue -> cardNode -> heading -> forValues
1069
1055
  enter_forValues(_node, _route) {
@@ -1073,33 +1059,20 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1073
1059
  // Ignore cards if not allowed
1074
1060
  if (!this.isCardAllowed(route))
1075
1061
  return;
1076
- this.writeNL();
1077
1062
  this.writeCardSetSideDivider();
1078
- this.writeNL();
1079
- }
1080
- exit_forValues(_node, _route) {
1081
- //
1082
1063
  }
1083
1064
  // bitmarkAst -> bits -> bitsValue -> cardNode -> pairs
1084
1065
  enter_pairs(_node, _route) {
1085
1066
  //
1086
1067
  }
1087
1068
  between_pairs(_node, _left, _right, _route) {
1088
- this.writeNL();
1089
1069
  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
1070
  }
1099
1071
  // bitmarkAst -> bits -> bitsValue -> cardNode -> pairs -> pairsValue -> keyAudio
1100
1072
  enter_keyAudio(node, _route) {
1101
1073
  const resource = node.value;
1102
1074
  // This is a resource, so handle it with the common code
1075
+ this.writeNL();
1103
1076
  this.writeResource(ResourceTag_1.ResourceTag.audio, resource.src);
1104
1077
  // Stop traversal of this branch
1105
1078
  return false;
@@ -1108,6 +1081,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1108
1081
  enter_keyImage(node, _route) {
1109
1082
  const resource = node.value;
1110
1083
  // This is a resource, so handle it with the common code
1084
+ this.writeNL();
1111
1085
  this.writeResource(ResourceTag_1.ResourceTag.image, resource.src);
1112
1086
  // Stop traversal of this branch
1113
1087
  return false;
@@ -1117,16 +1091,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1117
1091
  //
1118
1092
  }
1119
1093
  between_matrix(_node, _left, _right, _route) {
1120
- this.writeNL();
1121
1094
  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
1095
  }
1131
1096
  // bitmarkAst -> bits -> bitsValue -> cardNode -> pairs -> pairsValue -> values
1132
1097
  // bitmarkAst -> bits -> bitsValue -> cardNode -> matrix -> matrixValue -> cells -> cellsValue -> values
@@ -1134,17 +1099,13 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1134
1099
  // Ignore cards if not allowed
1135
1100
  if (!this.isCardAllowed(route))
1136
1101
  return;
1137
- this.writeNL();
1138
1102
  this.writeCardSetSideDivider();
1139
- this.writeNL();
1140
1103
  }
1141
1104
  between_values(_node, _left, _right, route) {
1142
1105
  // Ignore cards if not allowed
1143
1106
  if (!this.isCardAllowed(route))
1144
1107
  return;
1145
- this.writeNL();
1146
1108
  this.writeCardSetVariantDivider();
1147
- this.writeNL();
1148
1109
  }
1149
1110
  // bitmarkAst -> bits -> bitsValue -> cardNode -> pronunciationTable
1150
1111
  between_pronunciationTable(_node, _left, _right, route) {
@@ -1154,9 +1115,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1154
1115
  // Ignore cards if not allowed
1155
1116
  if (!this.isCardAllowed(route))
1156
1117
  return;
1157
- this.writeNL();
1158
1118
  this.writeCardSetCardDivider();
1159
- this.writeNL();
1160
1119
  }
1161
1120
  // bitmarkAst -> bits -> bitsValue -> cardNode -> table
1162
1121
  between_table(_node, _left, _right, route) {
@@ -1166,9 +1125,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1166
1125
  // Ignore cards if not allowed
1167
1126
  if (!this.isCardAllowed(route))
1168
1127
  return;
1169
- this.writeNL();
1170
1128
  this.writeCardSetCardDivider();
1171
- this.writeNL();
1172
1129
  }
1173
1130
  // bitmarkAst -> bits -> bitsValue -> cardNode -> table -> data
1174
1131
  // bitmarkAst -> bits -> bitsValue -> cardNode -> pronunciationTable -> data
@@ -1176,9 +1133,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1176
1133
  const parent = this.getParentNode(route);
1177
1134
  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
1135
  return;
1179
- this.writeNL();
1180
1136
  this.writeCardSetCardDivider();
1181
- this.writeNL();
1182
1137
  }
1183
1138
  // bitmarkAst -> bits -> bitsValue -> cardNode -> table -> columns
1184
1139
  // bitmarkAst -> bits -> bitsValue -> cardNode -> captionDefinitionList -> columns
@@ -1190,19 +1145,19 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1190
1145
  // Ignore cards if not allowed
1191
1146
  if (!this.isCardAllowed(route))
1192
1147
  return;
1193
- this.writeNL();
1194
1148
  this.writeCardSetSideDivider();
1195
- this.writeNL();
1196
1149
  }
1197
1150
  // bitmarkAst -> bits -> bitsValue -> cardNode -> table -> columns -> columnsValue
1198
1151
  // bitmarkAst -> bits -> bitsValue -> cardNode -> captionDefinitionList -> columns -> columnsValue
1199
1152
  leaf_columnsValue(node, _route) {
1153
+ this.writeNL();
1200
1154
  this.writeOPHASH();
1201
1155
  if (node.value)
1202
1156
  this.writeBreakscapedTagString(node.value);
1203
1157
  this.writeCL();
1204
1158
  }
1205
1159
  enter_columnsValue(node, _route) {
1160
+ this.writeNL();
1206
1161
  this.writeOPHASH();
1207
1162
  if (node.value) {
1208
1163
  this.textGenerator.generateSync(node.value, TextFormat_1.TextFormat.bitmarkMinusMinus);
@@ -1218,15 +1173,14 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1218
1173
  // Ignore cards if not allowed
1219
1174
  if (!this.isCardAllowed(route))
1220
1175
  return;
1221
- this.writeNL();
1222
1176
  this.writeCardSetSideDivider();
1223
- this.writeNL();
1224
1177
  }
1225
1178
  // bitmarkAst -> bits -> bitsValue -> cardNode -> table -> data -> dataValue -> dataValueValue
1226
1179
  leaf_dataValueValue(node, route) {
1227
1180
  const parent = this.getParentNode(route, 3);
1228
1181
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.table)
1229
1182
  return;
1183
+ this.writeNL();
1230
1184
  this.write(node.value);
1231
1185
  }
1232
1186
  // bitmarkAst -> bits -> bitsValue -> cardNode -> table -> data -> dataValue -> dataValueValue
@@ -1242,17 +1196,18 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1242
1196
  // Pronunciation Table
1243
1197
  const cell = node.value;
1244
1198
  if (cell.title) {
1199
+ this.writeNL();
1245
1200
  this.writeOP();
1246
1201
  this.writeHash();
1247
1202
  this.textGenerator.generateSync(cell.title, TextFormat_1.TextFormat.bitmarkMinusMinus);
1248
1203
  this.writeCL();
1249
- this.writeNL();
1250
1204
  }
1251
1205
  if (cell.audio) {
1252
- this.writeResource(ResourceTag_1.ResourceTag.audio, cell.audio.src);
1253
1206
  this.writeNL();
1207
+ this.writeResource(ResourceTag_1.ResourceTag.audio, cell.audio.src);
1254
1208
  }
1255
1209
  if (cell.body) {
1210
+ this.writeNL();
1256
1211
  this.textGenerator.generateSync(cell.body, textFormat);
1257
1212
  }
1258
1213
  // Stop traversal of this branch
@@ -1260,6 +1215,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1260
1215
  }
1261
1216
  else {
1262
1217
  // Table
1218
+ this.writeNL();
1263
1219
  this.textGenerator.generateSync(node.value, textFormat);
1264
1220
  }
1265
1221
  }
@@ -1270,38 +1226,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1270
1226
  const parent = this.getParentNode(route);
1271
1227
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.cardNode)
1272
1228
  return;
1273
- this.writeNL();
1274
1229
  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
1230
  }
1306
1231
  // bitmarkAst -> bits -> bitsValue -> cardNode -> captionDefinitionList -> definitions -> definitionsValue -> term
1307
1232
  leaf_term(node, route) {
@@ -1309,28 +1234,19 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1309
1234
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.definitionsValue)
1310
1235
  return true;
1311
1236
  if (node.value) {
1237
+ this.writeNL();
1312
1238
  this.write(node.value);
1313
1239
  }
1314
1240
  // Stop traversal of this branch
1315
1241
  return false;
1316
1242
  }
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
1243
  // bitmarkAst -> bits -> bitsValue -> cardNode -> captionDefinitionList -> definitions -> definitionsValue -> definition
1329
1244
  leaf_definition(node, route) {
1330
1245
  const parent = this.getParentNode(route);
1331
1246
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.definitionsValue)
1332
1247
  return true;
1333
1248
  if (node.value) {
1249
+ this.writeNL();
1334
1250
  this.write(node.value);
1335
1251
  }
1336
1252
  // Stop traversal of this branch
@@ -1342,9 +1258,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1342
1258
  const parent = this.getParentNode(route);
1343
1259
  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
1260
  return;
1345
- this.writeNL();
1346
1261
  this.writeCardSetCardDivider();
1347
- this.writeNL();
1348
1262
  }
1349
1263
  // bitmarkAst -> bits -> bitsValue -> cardNode -> definitions -> definitionsValue
1350
1264
  between_definitionsValue(_node, _left, right, route) {
@@ -1356,75 +1270,37 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1356
1270
  if (!this.isCardAllowed(route))
1357
1271
  return;
1358
1272
  if (right.key === NodeType_1.NodeType.definition) {
1359
- this.writeNL();
1360
1273
  this.writeCardSetSideDivider();
1361
- this.writeNL();
1362
1274
  }
1363
1275
  else if (right.key === NodeType_1.NodeType.alternativeDefinitions && ((_a = right.value) === null || _a === void 0 ? void 0 : _a.length) > 0) {
1364
- this.writeNL();
1365
1276
  this.writeCardSetVariantDivider();
1366
- this.writeNL();
1367
1277
  }
1368
1278
  }
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
1279
  // bitmarkAst -> bits -> bitsValue -> cardNode -> questions
1386
1280
  enter_questions(_node, _route) {
1387
1281
  //
1388
1282
  }
1389
1283
  between_questions(_node, _left, _right, _route) {
1390
1284
  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
1285
  }
1407
1286
  // bitmarkAst -> bits -> bitsValue -> cardNode -> ingredients
1408
1287
  enter_ingredients(_node, _route) {
1409
1288
  //
1410
1289
  }
1411
1290
  between_ingredients(_node, _left, _right, _route) {
1412
- this.writeNL();
1413
1291
  this.writeCardSetCardDivider();
1414
- this.writeNL();
1415
- }
1416
- exit_ingredients(_node, _route) {
1417
- //
1418
1292
  }
1419
1293
  // bitmarkAst -> bits -> bitsValue -> cardNode -> ingredients -> ingredientsValue
1420
1294
  enter_ingredientsValue(node, _route) {
1421
1295
  const ingredient = node.value;
1422
1296
  if (ingredient.title != null) {
1297
+ this.writeNL();
1423
1298
  this.writeOPHASH();
1424
1299
  this.writeBreakscapedTagString(ingredient.title);
1425
1300
  this.writeCL();
1426
- this.writeNL();
1301
+ // this.writeNL();
1427
1302
  }
1303
+ this.writeNL();
1428
1304
  // [+] / [-]
1429
1305
  if (ingredient.checked) {
1430
1306
  this.writeOPP();
@@ -1468,8 +1344,10 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1468
1344
  ignoreEmpty: true,
1469
1345
  });
1470
1346
  // item
1471
- if (ingredient.item != null)
1347
+ if (ingredient.item != null) {
1348
+ this.writeNL();
1472
1349
  this.write(ingredient.item);
1350
+ }
1473
1351
  // Stop traversal of this branch
1474
1352
  return false;
1475
1353
  }
@@ -1479,35 +1357,20 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1479
1357
  }
1480
1358
  between_botResponses(_node, _left, _right, _route) {
1481
1359
  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
1360
  }
1494
1361
  // bitmarkAst -> bits -> bitsValue -> cardNode -> cardBits
1495
1362
  enter_cardBits(_node, _route) {
1496
1363
  //
1497
1364
  }
1498
1365
  between_cardBits(_node, _left, _right, _route) {
1499
- this.writeNL();
1500
1366
  this.writeCardSetCardDivider();
1501
- this.writeNL();
1502
- }
1503
- exit_cardBits(_node, _route) {
1504
- //
1505
1367
  }
1506
1368
  // bitmarkAst -> bits -> bitsValue -> cardNode -> botResponses -> botResponsesValue -> response
1507
1369
  leaf_response(node, route) {
1508
1370
  const parent = this.getParentNode(route);
1509
1371
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.botResponsesValue)
1510
1372
  return;
1373
+ this.writeNL();
1511
1374
  this.writeOPB();
1512
1375
  this.writeBreakscapedTagString(node.value);
1513
1376
  this.writeCL();
@@ -1517,6 +1380,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1517
1380
  const parent = this.getParentNode(route);
1518
1381
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.botResponsesValue)
1519
1382
  return;
1383
+ this.writeNL();
1520
1384
  this.writeProperty('reaction', node.value, {
1521
1385
  format: PropertyFormat_1.PropertyFormat.trimmedString,
1522
1386
  single: true,
@@ -1530,6 +1394,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1530
1394
  return;
1531
1395
  const feeback = node.value;
1532
1396
  if (feeback) {
1397
+ this.writeNL();
1533
1398
  this.write(feeback);
1534
1399
  }
1535
1400
  }
@@ -1537,12 +1402,13 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1537
1402
  enter_imagePlaceholder(node, _route) {
1538
1403
  const resource = node.value;
1539
1404
  // This is a resource, so handle it with the common code
1405
+ this.writeNL();
1540
1406
  this.writePropertyStyleResource(node.key, resource);
1541
1407
  // Continue traversal
1542
1408
  return true;
1543
1409
  }
1544
1410
  exit_imagePlaceholder(_node, _route) {
1545
- this.writeNL();
1411
+ // this.writeNL();
1546
1412
  }
1547
1413
  // bitmarkAst -> bits -> bitsValue -> posterImage
1548
1414
  // bitmarkAst -> bits -> bitsValue -> resource -> * -> posterImage
@@ -1641,9 +1507,6 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1641
1507
  enter_book(_node, _route) {
1642
1508
  // Block standard property handling
1643
1509
  }
1644
- between_book(_node, _route) {
1645
- this.writeNL();
1646
- }
1647
1510
  enter_bookValue(node, _route) {
1648
1511
  const book = node.value;
1649
1512
  // const parent = this.getParentNode(route);
@@ -1714,10 +1577,11 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1714
1577
  // * -> itemLead --> item
1715
1578
  // * -> itemLead --> lead
1716
1579
  // * -> hint
1717
- enter_hint(node, _route) {
1580
+ enter_hint(node, route) {
1718
1581
  const value = node.value;
1719
1582
  const text = value;
1720
1583
  if (!this.isEmptyText(text)) {
1584
+ this.writeNL_IfNotChain(route);
1721
1585
  this.writeOPQ();
1722
1586
  this.textGenerator.generateSync(text, TextFormat_1.TextFormat.bitmarkMinusMinus);
1723
1587
  this.writeCL();
@@ -1726,10 +1590,11 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1726
1590
  return false;
1727
1591
  }
1728
1592
  // bitmarkAst -> bits -> bitsValue -> * -> instruction
1729
- enter_instruction(node, _route) {
1593
+ enter_instruction(node, route) {
1730
1594
  const value = node.value;
1731
1595
  const text = value;
1732
1596
  if (!this.isEmptyText(text)) {
1597
+ this.writeNL_IfNotChain(route);
1733
1598
  this.writeOPB();
1734
1599
  this.textGenerator.generateSync(text, TextFormat_1.TextFormat.bitmarkMinusMinus);
1735
1600
  this.writeCL();
@@ -1739,6 +1604,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1739
1604
  }
1740
1605
  // bitmarkAst -> bits -> bitsValue -> * -> lang
1741
1606
  enter_lang(node, _route) {
1607
+ this.writeNL();
1742
1608
  this.writeProperty('lang', node.value, {
1743
1609
  format: PropertyFormat_1.PropertyFormat.boolean,
1744
1610
  single: true,
@@ -1747,6 +1613,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1747
1613
  }
1748
1614
  // bitmarkAst -> bits -> bitsValue -> * -> refAuthor
1749
1615
  enter_refAuthor(node, _route) {
1616
+ this.writeNL();
1750
1617
  this.writeProperty('refAuthor', node.value, {
1751
1618
  format: PropertyFormat_1.PropertyFormat.trimmedString,
1752
1619
  single: false,
@@ -1755,6 +1622,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1755
1622
  }
1756
1623
  // bitmarkAst -> bits -> bitsValue -> * -> refBookTitle
1757
1624
  enter_refBookTitle(node, _route) {
1625
+ this.writeNL();
1758
1626
  this.writeProperty('refBookTitle', node.value, {
1759
1627
  format: PropertyFormat_1.PropertyFormat.trimmedString,
1760
1628
  single: true,
@@ -1763,6 +1631,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1763
1631
  }
1764
1632
  // bitmarkAst -> bits -> bitsValue -> * -> refPublisher
1765
1633
  enter_refPublisher(node, _route) {
1634
+ this.writeNL();
1766
1635
  this.writeProperty('refPublisher', node.value, {
1767
1636
  format: PropertyFormat_1.PropertyFormat.trimmedString,
1768
1637
  single: false,
@@ -1779,6 +1648,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1779
1648
  }
1780
1649
  // bitmarkAst -> bits -> bitsValue -> * -> citationStyle
1781
1650
  enter_citationStyle(node, _route) {
1651
+ this.writeNL();
1782
1652
  this.writeProperty('citationStyle', node.value, {
1783
1653
  format: PropertyFormat_1.PropertyFormat.trimmedString,
1784
1654
  single: true,
@@ -1795,6 +1665,8 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1795
1665
  const example = (_a = parent === null || parent === void 0 ? void 0 : parent.value.example) !== null && _a !== void 0 ? _a : null;
1796
1666
  // const __isDefaultExample = parent?.value.__isDefaultExample ?? false;
1797
1667
  if (example != null && example !== '') {
1668
+ // Write a newline if not in a chain
1669
+ this.writeNL_IfNotChain(route);
1798
1670
  this.writeOPA();
1799
1671
  this.writeString('example');
1800
1672
  this.writeColon();
@@ -1824,6 +1696,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1824
1696
  // bitmarkAst -> bits -> bitsValue -> elements -> elementsValue
1825
1697
  leaf_elementsValue(node, _route) {
1826
1698
  if (node.value) {
1699
+ this.writeNL();
1827
1700
  this.writeBreakscapedTagString(node.value);
1828
1701
  }
1829
1702
  }
@@ -1869,18 +1742,21 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1869
1742
  // bitmarkAst -> bits -> bitsValue -> * -> isCorrect
1870
1743
  // bitmarkAst -> bits -> bitsValue -> heading -> forKeys
1871
1744
  leaf_forKeys(node, _route) {
1745
+ this.writeNL();
1872
1746
  this.writeOPHASH();
1873
1747
  this.writeBreakscapedTagString(node.value);
1874
1748
  this.writeCL();
1875
1749
  }
1876
1750
  // bitmarkAst -> bits -> bitsValue -> heading -> forValues
1877
1751
  leaf_forValues(node, _route) {
1752
+ this.writeNL();
1878
1753
  this.writeOPHASH();
1879
1754
  this.writeBreakscapedTagString(node.value);
1880
1755
  this.writeCL();
1881
1756
  }
1882
1757
  // bitmarkAst -> bits -> bitsValue -> heading -> forValuesValue
1883
1758
  leaf_forValuesValue(node, _route) {
1759
+ this.writeNL();
1884
1760
  this.writeOPHASH();
1885
1761
  this.writeBreakscapedTagString(node.value);
1886
1762
  this.writeCL();
@@ -1889,6 +1765,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1889
1765
  // bitmarkAst -> bits -> bitsValue -> matrix -> matrixValue -> key
1890
1766
  leaf_key(node, _route) {
1891
1767
  if (node.value) {
1768
+ this.writeNL();
1892
1769
  this.writeBreakscapedTagString(node.value);
1893
1770
  }
1894
1771
  }
@@ -1896,6 +1773,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1896
1773
  // bitmarkAst -> bits -> bitsValue -> matrix -> matrixValue -> cells -> cellsValue -> values -> valuesValue
1897
1774
  leaf_valuesValue(node, _route) {
1898
1775
  if (node.value) {
1776
+ this.writeNL();
1899
1777
  this.writeBreakscapedTagString(node.value);
1900
1778
  }
1901
1779
  }
@@ -1907,23 +1785,10 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1907
1785
  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
1786
  return;
1909
1787
  if (node.value) {
1788
+ this.writeNL();
1910
1789
  this.writeBreakscapedTagString(node.value);
1911
- // this.writeNL();
1912
1790
  }
1913
1791
  }
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
1792
  // bitmarkAst -> bits -> bitsValue -> statements -> text
1928
1793
  // bitmarkAst -> bits -> bitsValue -> resource -> ...
1929
1794
  // bitmarkAst -> bits -> bitsValue -> resource -> posterImage -> ...
@@ -2028,8 +1893,9 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2028
1893
  ignoreFalse: true,
2029
1894
  });
2030
1895
  }
2031
- enter_caption(node, _route) {
1896
+ enter_caption(node, route) {
2032
1897
  const value = node.value;
1898
+ this.writeNL_IfNotChain(route);
2033
1899
  this.writeProperty('caption', value, {
2034
1900
  format: PropertyFormat_1.PropertyFormat.bitmarkMinusMinus,
2035
1901
  single: true, // ??
@@ -2092,17 +1958,6 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2092
1958
  //
2093
1959
  // Resources
2094
1960
  //
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
1961
  //
2107
1962
  // Generated Node Handlers
2108
1963
  //
@@ -2137,6 +1992,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2137
1992
  // url / src / href / app
2138
1993
  const url = resource.url || resource.src || resource.body || '';
2139
1994
  // Write the resource
1995
+ this.writeNL();
2140
1996
  this.writeResource(type, url);
2141
1997
  // Continue traversal
2142
1998
  return true;
@@ -2149,14 +2005,6 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2149
2005
  /**
2150
2006
  * Generate the handlers for properties, as they are mostly the same, but not quite
2151
2007
  */
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
2008
  generatePropertyHandlers() {
2161
2009
  var _a;
2162
2010
  const propertiesConfig = Config_1.Config.getRawPropertiesConfig();
@@ -2183,6 +2031,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2183
2031
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.bitsValue)
2184
2032
  return;
2185
2033
  // Write the property
2034
+ this.writeNL(); // Only if NOT in chain (how do we know this?)
2186
2035
  this.writeProperty(propertyConfig.tag, node.value, {
2187
2036
  format: (_a = propertyConfig.format) !== null && _a !== void 0 ? _a : PropertyFormat_1.PropertyFormat.trimmedString,
2188
2037
  single: (_b = propertyConfig.single) !== null && _b !== void 0 ? _b : false,
@@ -2195,35 +2044,30 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2195
2044
  this[enterFuncName] = this[enterFuncName].bind(this);
2196
2045
  }
2197
2046
  }
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
2047
  // END NODE HANDLERS
2224
2048
  //
2225
2049
  // UTILITY FUNCTIONS
2226
2050
  //
2051
+ isChain(route) {
2052
+ const parent = this.getParentNode(route);
2053
+ // Root of bit
2054
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) === NodeType_1.NodeType.bitsValue)
2055
+ return false;
2056
+ // Root of card bits
2057
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) === NodeType_1.NodeType.cardBitsValue)
2058
+ return false;
2059
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) === NodeType_1.NodeType.quizzesValue)
2060
+ return false;
2061
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) === NodeType_1.NodeType.pairsValue)
2062
+ return false;
2063
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) === NodeType_1.NodeType.matrixValue)
2064
+ return false;
2065
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) === NodeType_1.NodeType.definitionsValue)
2066
+ return false;
2067
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) === NodeType_1.NodeType.questionsValue)
2068
+ return false;
2069
+ return true;
2070
+ }
2227
2071
  haveValidCardSet(bit) {
2228
2072
  const bitConfig = Config_1.Config.getBitConfig(bit.bitType);
2229
2073
  if (!bitConfig)
@@ -2355,17 +2199,20 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2355
2199
  this.write('#');
2356
2200
  }
2357
2201
  writePlainTextDivider() {
2202
+ this.writeNL();
2358
2203
  this.write('==== text ====');
2359
2204
  }
2360
2205
  writeCardSetStart() {
2206
+ this.writeNL();
2361
2207
  if (this.options.cardSetVersion === CardSetVersion_1.CardSetVersion.v1) {
2362
- this.write('\n===');
2208
+ this.write('===');
2363
2209
  }
2364
2210
  else {
2365
- this.write('\n====');
2211
+ this.write('====');
2366
2212
  }
2367
2213
  }
2368
2214
  writeCardSetEnd() {
2215
+ this.writeNL();
2369
2216
  if (this.options.cardSetVersion === CardSetVersion_1.CardSetVersion.v1) {
2370
2217
  this.write('===');
2371
2218
  }
@@ -2374,6 +2221,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2374
2221
  }
2375
2222
  }
2376
2223
  writeCardSetCardDivider() {
2224
+ this.writeNL();
2377
2225
  if (this.options.cardSetVersion === CardSetVersion_1.CardSetVersion.v1) {
2378
2226
  this.write('===');
2379
2227
  }
@@ -2382,6 +2230,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2382
2230
  }
2383
2231
  }
2384
2232
  writeCardSetSideDivider() {
2233
+ this.writeNL();
2385
2234
  if (this.options.cardSetVersion === CardSetVersion_1.CardSetVersion.v1) {
2386
2235
  this.write('==');
2387
2236
  }
@@ -2390,6 +2239,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2390
2239
  }
2391
2240
  }
2392
2241
  writeCardSetVariantDivider() {
2242
+ this.writeNL();
2393
2243
  if (this.options.cardSetVersion === CardSetVersion_1.CardSetVersion.v1) {
2394
2244
  this.write('--');
2395
2245
  }
@@ -2397,6 +2247,11 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2397
2247
  this.write('++');
2398
2248
  }
2399
2249
  }
2250
+ writeNL_IfNotChain(route) {
2251
+ if (!this.isChain(route)) {
2252
+ this.writeNL();
2253
+ }
2254
+ }
2400
2255
  writeNL() {
2401
2256
  if (this.options.debugGenerationInline) {
2402
2257
  this.write('\\n');
@@ -2416,7 +2271,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2416
2271
  this.writeColon();
2417
2272
  this.writeBreakscapedTagString(src);
2418
2273
  if (resource.type === ResourceTag_1.ResourceTag.article) {
2419
- this.writeNL();
2274
+ // this.writeNL();
2420
2275
  }
2421
2276
  this.writeCL();
2422
2277
  }
@@ -2430,7 +2285,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2430
2285
  this.writeColon();
2431
2286
  this.writeBreakscapedTagString(value);
2432
2287
  if (type === ResourceTag_1.ResourceTag.article) {
2433
- this.writeNL();
2288
+ // this.writeNL();
2434
2289
  }
2435
2290
  this.writeCL();
2436
2291
  }
@@ -2438,7 +2293,6 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2438
2293
  writeProperty(name, values, options) {
2439
2294
  var _a;
2440
2295
  let valuesArray;
2441
- let wroteSomething = false;
2442
2296
  if (values !== undefined) {
2443
2297
  const isBitmarkText = options.format === PropertyFormat_1.PropertyFormat.bitmarkMinusMinus || options.format === PropertyFormat_1.PropertyFormat.bitmarkPlusPlus;
2444
2298
  if (isBitmarkText) {
@@ -2450,7 +2304,6 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2450
2304
  this.writeColon();
2451
2305
  this.textGenerator.generateSync(values, (_a = TextFormat_1.TextFormat.fromValue(options.format)) !== null && _a !== void 0 ? _a : TextFormat_1.TextFormat.bitmarkMinusMinus);
2452
2306
  this.writeCL();
2453
- wroteSomething = true;
2454
2307
  }
2455
2308
  else {
2456
2309
  // Write any other property type
@@ -2463,7 +2316,6 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2463
2316
  if (valuesArray.length > 0) {
2464
2317
  if (options.single)
2465
2318
  valuesArray = valuesArray.slice(valuesArray.length - 1);
2466
- let propertyIndex = 0;
2467
2319
  for (const val of valuesArray) {
2468
2320
  if (val !== undefined) {
2469
2321
  if (options.ignoreFalse && val === false)
@@ -2472,23 +2324,17 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2472
2324
  continue;
2473
2325
  if (options.ignoreEmpty && val === '')
2474
2326
  continue;
2475
- if (propertyIndex > 0)
2476
- this.writeNL();
2477
2327
  this.writeOPA();
2478
2328
  this.writeBreakscapedTagString(name);
2479
2329
  this.writeColon();
2480
2330
  this.writeBreakscapedTagString(`${val}`);
2481
2331
  this.writeCL();
2482
- wroteSomething = true;
2483
- propertyIndex++;
2332
+ // propertyIndex++;
2484
2333
  }
2485
2334
  }
2486
2335
  }
2487
2336
  } // isBitmarkText
2488
2337
  }
2489
- if (!wroteSomething) {
2490
- this.skipNLBetweenBitsValue = true;
2491
- }
2492
2338
  }
2493
2339
  writeInlineDebug(key, state) {
2494
2340
  let tag = key;
@@ -2556,8 +2402,6 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2556
2402
  * @param value - The string value to be written.
2557
2403
  */
2558
2404
  write(value) {
2559
- if (value)
2560
- this.wroteSomething = true;
2561
2405
  this.writer.write(value);
2562
2406
  return this;
2563
2407
  }
@@ -2566,8 +2410,6 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2566
2410
  * @param value - The line to write. When omitted, only the endOfLineString is written.
2567
2411
  */
2568
2412
  writeLine(value) {
2569
- if (value)
2570
- this.wroteSomething = true;
2571
2413
  this.writer.writeLine(value);
2572
2414
  return this;
2573
2415
  }
@@ -2577,8 +2419,6 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2577
2419
  * @param delimiter - An optional delimiter to be written at the end of each line, except for the last one.
2578
2420
  */
2579
2421
  writeLines(values, delimiter) {
2580
- if (values.length > 0 && values.reduce((acc, v) => (v ? true : acc), false))
2581
- this.wroteSomething = true;
2582
2422
  this.writer.writeLines(values, delimiter);
2583
2423
  return this;
2584
2424
  }