@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
@@ -29,6 +29,9 @@ const DEFAULT_OPTIONS = {
29
29
  };
30
30
  /**
31
31
  * Generate bitmark markup from a bitmark AST
32
+ *
33
+ * NOTE: Newlines - a newline is written BEFORE each content that requries a newline
34
+ *
32
35
  */
33
36
  class BitmarkGenerator extends AstWalkerGenerator {
34
37
  /**
@@ -51,10 +54,9 @@ class BitmarkGenerator extends AstWalkerGenerator {
51
54
  super();
52
55
  this.ast = new Ast();
53
56
  // State
57
+ this.firstBit = true;
54
58
  this.hasCardSet = false;
55
59
  this.hasFooter = false;
56
- this.skipNLBetweenBitsValue = false;
57
- this.wroteSomething = false;
58
60
  this.inTag = true;
59
61
  // Keep TS happy
60
62
  this.inTag;
@@ -127,10 +129,9 @@ class BitmarkGenerator extends AstWalkerGenerator {
127
129
  this.writer.closeSync();
128
130
  }
129
131
  resetState() {
132
+ this.firstBit = true;
130
133
  this.hasCardSet = false;
131
134
  this.hasFooter = false;
132
- this.skipNLBetweenBitsValue = false;
133
- this.wroteSomething = false;
134
135
  this.inTag = true;
135
136
  this.printed = false;
136
137
  }
@@ -147,12 +148,6 @@ class BitmarkGenerator extends AstWalkerGenerator {
147
148
  // Non-Terminal nodes (branches)
148
149
  //
149
150
  // bitmark
150
- // bitmarkAst -> bits
151
- between_bits(_node, _left, _right, _route) {
152
- this.writeNL();
153
- this.writeNL();
154
- this.writeNL();
155
- }
156
151
  // bitmarkAst -> bits -> bitsValue
157
152
  enter_bitsValue(node, _route) {
158
153
  const bit = node.value;
@@ -160,6 +155,12 @@ class BitmarkGenerator extends AstWalkerGenerator {
160
155
  const bitResourcesConfig = Config.getBitResourcesConfig(bit.bitType, bit.resourceType);
161
156
  this.hasCardSet = this.haveValidCardSet(bit);
162
157
  this.hasFooter = this.haveValidFooter(bit);
158
+ // Separate the bits with 3 newlines
159
+ if (!this.firstBit) {
160
+ this.writeNL();
161
+ this.writeNL();
162
+ this.writeNL();
163
+ }
163
164
  // Write the bit tag opening
164
165
  this.writeOPD(bit.bitLevel);
165
166
  if (bit.isCommented)
@@ -195,22 +196,12 @@ class BitmarkGenerator extends AstWalkerGenerator {
195
196
  this.writeBreakscapedTagString(resourceType);
196
197
  }
197
198
  this.writeCL();
198
- this.writeNL();
199
+ // this.writeNL();
199
200
  // Continue traversal
200
201
  return true;
201
202
  }
202
- between_bitsValue(node, left, right, route) {
203
- // The following keys are combined with other keys so don't need newlines
204
- const noNlKeys = [
205
- NodeType.bitType,
206
- NodeType.textFormat,
207
- NodeType.level,
208
- NodeType.progress,
209
- NodeType.toc,
210
- NodeType.referenceEnd,
211
- NodeType.labelFalse,
212
- ];
213
- this.writeNlBetween(node, left, right, route, noNlKeys);
203
+ exit_bitsValue(_node, _route) {
204
+ this.firstBit = false;
214
205
  }
215
206
  // bitmarkAst -> bits -> bitsValue -> internalComment
216
207
  enter_internalComment(node, route) {
@@ -221,14 +212,12 @@ class BitmarkGenerator extends AstWalkerGenerator {
221
212
  return true;
222
213
  for (let i = 0; i < internalComment.length; i++) {
223
214
  const comment = internalComment[i];
224
- const last = i === internalComment.length - 1;
215
+ this.writeNL();
225
216
  this.writeProperty('internalComment', comment, {
226
217
  format: PropertyFormat.trimmedString,
227
218
  single: false,
228
219
  ignoreEmpty: true,
229
220
  });
230
- if (!last)
231
- this.writeNL();
232
221
  }
233
222
  // Stop traversal of this branch
234
223
  return false;
@@ -242,13 +231,18 @@ class BitmarkGenerator extends AstWalkerGenerator {
242
231
  return true;
243
232
  const bit = parent === null || parent === void 0 ? void 0 : parent.value;
244
233
  if (bit) {
245
- if (value != '')
234
+ const haveTrue = value != '';
235
+ const haveFalse = bit.labelFalse && bit.labelFalse[0] != '';
236
+ if (haveTrue || haveFalse) {
237
+ this.writeNL();
238
+ }
239
+ if (haveTrue)
246
240
  this.writeProperty(PropertyTag.labelTrue, value, {
247
241
  format: PropertyFormat.trimmedString,
248
242
  single: true,
249
243
  ignoreEmpty: true,
250
244
  });
251
- if (bit.labelFalse && bit.labelFalse[0] != '')
245
+ if (haveFalse)
252
246
  this.writeProperty(PropertyTag.labelFalse, bit.labelFalse, {
253
247
  format: PropertyFormat.trimmedString,
254
248
  single: true,
@@ -258,6 +252,10 @@ class BitmarkGenerator extends AstWalkerGenerator {
258
252
  // Stop traversal of this branch
259
253
  return false;
260
254
  }
255
+ enter_labelFalse(_node, _route) {
256
+ // Handled above in enter_labelTrue(), but this function needed to block automatic property handling
257
+ return true;
258
+ }
261
259
  // bitmarkAst -> bits -> bitsValue -> imageSource
262
260
  enter_imageSource(node, route) {
263
261
  const imageSource = node.value;
@@ -266,6 +264,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
266
264
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.bitsValue)
267
265
  return true;
268
266
  const { url, mockupId, size, format, trim } = imageSource;
267
+ this.writeNL();
269
268
  this.writeProperty('imageSource', url, {
270
269
  format: PropertyFormat.trimmedString,
271
270
  single: true,
@@ -308,6 +307,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
308
307
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.bitsValue)
309
308
  return true;
310
309
  const { technicalTerm, lang } = nodeValue;
310
+ this.writeNL();
311
311
  this.writeProperty('technicalTerm', technicalTerm, {
312
312
  format: PropertyFormat.trimmedString,
313
313
  single: true,
@@ -331,6 +331,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
331
331
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.bitsValue)
332
332
  return true;
333
333
  const { servings, unit, unitAbbr, decimalPlaces, disableCalculation, hint } = nodeValue;
334
+ this.writeNL();
334
335
  this.writeProperty('servings', servings, {
335
336
  format: PropertyFormat.trimmedString,
336
337
  single: true,
@@ -384,6 +385,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
384
385
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.bitsValue)
385
386
  return true;
386
387
  const { name, title, avatarImage } = person;
388
+ this.writeNL();
387
389
  this.writeProperty('person', name, {
388
390
  format: PropertyFormat.trimmedString,
389
391
  single: true,
@@ -402,6 +404,88 @@ class BitmarkGenerator extends AstWalkerGenerator {
402
404
  // Stop traversal of this branch
403
405
  return false;
404
406
  }
407
+ // bitmarkAst -> bits -> bitsValue -> cardNode -> definitions -> definitionsValue -> term -> text
408
+ // bitmarkAst -> bits -> bitsValue -> cardNode -> definitions -> definitionsValue -> definition -> text
409
+ // bitmarkAst -> bits -> bitsValue -> cardNode -> definitions -> definitionsValue -> alternativeDefinitions
410
+ // -> alternativeDefinitionsValue -> text
411
+ // bitmarkAst -> bits -> bitsValue -> cardNode -> flashcards -> flashcardsValue -> question -> text
412
+ // bitmarkAst -> bits -> bitsValue -> cardNode -> flashcards -> flashcardsValue -> answer -> text
413
+ // bitmarkAst -> bits -> bitsValue -> cardNode -> flashcards -> flashcardsValue -> alternativeAnswers ->
414
+ // -> alternativeAnswersValue -> text
415
+ enter_text(node, route) {
416
+ const parent = this.getParentNode(route);
417
+ if (!parent ||
418
+ (parent.key !== NodeType.term &&
419
+ parent.key !== NodeType.definition &&
420
+ parent.key !== NodeType.alternativeDefinitionsValue &&
421
+ parent.key !== NodeType.question &&
422
+ parent.key !== NodeType.answer &&
423
+ parent.key !== NodeType.alternativeAnswersValue)) {
424
+ return true;
425
+ }
426
+ if (node.value) {
427
+ this.writeNL();
428
+ this.textGenerator.generateSync(node.value, TextFormat.bitmarkMinusMinus);
429
+ }
430
+ // Stop traversal of this branch
431
+ return false;
432
+ }
433
+ leaf_text(node, route) {
434
+ const parent = this.getParentNode(route);
435
+ if (!parent ||
436
+ (parent.key !== NodeType.term &&
437
+ parent.key !== NodeType.definition &&
438
+ parent.key !== NodeType.alternativeDefinitionsValue &&
439
+ parent.key !== NodeType.question &&
440
+ parent.key !== NodeType.answer &&
441
+ parent.key !== NodeType.alternativeAnswersValue)) {
442
+ return true;
443
+ }
444
+ if (StringUtils.isString(node.value)) {
445
+ const str = node.value;
446
+ this.writeNL();
447
+ this.write(Breakscape.breakscape(str, {
448
+ textFormat: TextFormat.text,
449
+ }));
450
+ }
451
+ // Stop traversal of this branch
452
+ return false;
453
+ }
454
+ // bitmarkAst -> bits -> bitsValue -> * -> term -> icon
455
+ // bitmarkAst -> bits -> bitsValue -> * -> definition -> icon
456
+ // bitmarkAst -> bits -> bitsValue -> * -> alternativeDefinitionsValue -> icon
457
+ enter_icon(node, route) {
458
+ const resource = node.value;
459
+ const parent = this.getParentNode(route);
460
+ if (!parent)
461
+ return true;
462
+ if (parent.key !== NodeType.term &&
463
+ parent.key !== NodeType.definition &&
464
+ parent.key !== NodeType.alternativeDefinitionsValue &&
465
+ parent.key !== NodeType.question &&
466
+ parent.key !== NodeType.answer &&
467
+ parent.key !== NodeType.alternativeAnswersValue) {
468
+ // Continue traversal of this branch
469
+ return true;
470
+ }
471
+ // This is a resource, so handle it with the common code
472
+ this.writeNL();
473
+ this.writeResource(ResourceTag.icon, resource.src);
474
+ // this.writePropertyStyleResource(ResourceTag.icon, resource as ResourceJson);
475
+ // Continue traversal of this branch (for the chained properties)
476
+ return true;
477
+ }
478
+ leaf_iconValue(node, _route) {
479
+ // Handle as a standard icon property
480
+ this.writeNL();
481
+ this.writeProperty('icon', node.value, {
482
+ format: PropertyFormat.trimmedString,
483
+ single: true,
484
+ ignoreEmpty: true,
485
+ });
486
+ // Stop traversal of this branch
487
+ return false;
488
+ }
405
489
  // bitmarkAst -> bits -> bitsValue -> ratingLevelStart
406
490
  enter_ratingLevelStart(node, route) {
407
491
  this.enterRatingLevelStartEndCommon(node, route);
@@ -423,6 +507,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
423
507
  return true;
424
508
  const { level, label } = n;
425
509
  const levelKey = node.key === NodeType.ratingLevelStart ? PropertyTag.ratingLevelStart : PropertyTag.ratingLevelEnd;
510
+ this.writeNL();
426
511
  this.writeProperty(levelKey, level, {
427
512
  format: PropertyFormat.trimmedString,
428
513
  single: true,
@@ -452,6 +537,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
452
537
  return true;
453
538
  const { mark, color, emphasis } = markConfig;
454
539
  if (mark) {
540
+ this.writeNL();
455
541
  this.writeProperty('mark', mark, {
456
542
  format: PropertyFormat.trimmedString,
457
543
  single: true,
@@ -471,74 +557,79 @@ class BitmarkGenerator extends AstWalkerGenerator {
471
557
  ignoreEmpty: true,
472
558
  });
473
559
  }
474
- this.writeNL();
475
560
  }
476
561
  // Stop traversal of this branch
477
562
  return false;
478
563
  }
479
564
  // bitmarkAst -> bits -> bitsValue -> partialAnswer
480
565
  enter_partialAnswer(node, _route) {
481
- this.writeProperty('partialAnswer', node.value, {
482
- format: PropertyFormat.trimmedString,
483
- single: true,
484
- ignoreEmpty: true,
485
- });
566
+ if (node.value) {
567
+ this.writeNL();
568
+ this.writeProperty('partialAnswer', node.value, {
569
+ format: PropertyFormat.trimmedString,
570
+ single: true,
571
+ ignoreEmpty: true,
572
+ });
573
+ }
486
574
  // Stop traversal of this branch
487
575
  return false;
488
576
  }
489
577
  // bitmarkAst -> bits -> bitsValue -> questions -> questionsValue -> partialAnswer
490
578
  leaf_partialAnswer(node, _route) {
491
- this.writeProperty('partialAnswer', node.value, {
492
- format: PropertyFormat.trimmedString,
493
- single: true,
494
- ignoreEmpty: true,
495
- });
579
+ if (node.value) {
580
+ this.writeNL();
581
+ this.writeProperty('partialAnswer', node.value, {
582
+ format: PropertyFormat.trimmedString,
583
+ single: true,
584
+ ignoreEmpty: true,
585
+ });
586
+ }
496
587
  // Stop traversal of this branch
497
588
  return false;
498
589
  }
499
590
  // bitmarkAst -> bits -> bitsValue -> sampleSolution
500
591
  // bitmarkAst -> bits -> bitsValue -> questions -> questionsValue -> sampleSolution
501
592
  enter_sampleSolution(node, _route) {
502
- this.writeProperty('sampleSolution', node.value, {
503
- format: PropertyFormat.trimmedString,
504
- single: true,
505
- ignoreEmpty: true,
506
- });
593
+ if (node.value) {
594
+ this.writeNL();
595
+ this.writeProperty('sampleSolution', node.value, {
596
+ format: PropertyFormat.trimmedString,
597
+ single: true,
598
+ ignoreEmpty: true,
599
+ });
600
+ }
507
601
  // Stop traversal of this branch
508
602
  return false;
509
603
  }
510
604
  leaf_sampleSolution(node, _route) {
511
- this.writeProperty('sampleSolution', node.value, {
512
- format: PropertyFormat.trimmedString,
513
- single: true,
514
- ignoreEmpty: true,
515
- });
605
+ if (node.value) {
606
+ this.writeNL();
607
+ this.writeProperty('sampleSolution', node.value, {
608
+ format: PropertyFormat.trimmedString,
609
+ single: true,
610
+ ignoreEmpty: true,
611
+ });
612
+ }
516
613
  // Stop traversal of this branch
517
614
  return false;
518
615
  }
519
616
  // bitmarkAst -> bits -> bitsValue -> reasonableNumOfChars
520
617
  // bitmarkAst -> bits -> bitsValue -> questions -> questionsValue -> reasonableNumOfChars
521
618
  leaf_reasonableNumOfChars(node, _route) {
619
+ this.writeNL();
522
620
  this.writeProperty('reasonableNumOfChars', node.value, {
523
621
  format: PropertyFormat.trimmedString,
524
622
  single: true,
525
623
  ignoreEmpty: true,
526
624
  });
527
625
  }
528
- // bitmarkAst -> bits -> bitsValue -> questions -> questionsValue -> additionalSolutions
529
- between_additionalSolutions(_node, _left, _right, route) {
530
- // Ignore values that are not at the bit level as they might be handled elsewhere
531
- const parent = this.getParentNode(route);
532
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.questionsValue)
533
- return;
534
- this.writeNL();
535
- }
536
626
  // bitmarkAst -> bits -> bitsValue -> questions -> questionsValue -> additionalSolutions -> additionalSolutionsValue
537
627
  leaf_additionalSolutionsValue(node, route) {
538
628
  // Ignore values that are not at the bit level as they might be handled elsewhere
539
629
  const parent = this.getParentNode(route, 2);
540
630
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.questionsValue)
541
631
  return;
632
+ this.writeNL();
542
633
  this.writeProperty('additionalSolutions', node.value, {
543
634
  format: PropertyFormat.trimmedString,
544
635
  single: false,
@@ -557,6 +648,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
557
648
  return true; // Will be handled by pageNumber
558
649
  if (!this.isEmptyText((_c = parent === null || parent === void 0 ? void 0 : parent.value) === null || _c === void 0 ? void 0 : _c.marginNumber))
559
650
  return true; // Will be handled by marginNumber
651
+ this.writeNL_IfNotChain(route);
560
652
  this.writeOPC();
561
653
  this.textGenerator.generateSync(item, TextFormat.bitmarkMinusMinus);
562
654
  this.writeCL();
@@ -573,6 +665,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
573
665
  return true; // Will be handled by pageNumber
574
666
  if (!this.isEmptyText((_b = parent === null || parent === void 0 ? void 0 : parent.value) === null || _b === void 0 ? void 0 : _b.marginNumber))
575
667
  return true; // Will be handled by marginNumber
668
+ this.writeNL_IfNotChain(route);
576
669
  this.writeOPC();
577
670
  this.textGenerator.generateSync((_d = (_c = parent === null || parent === void 0 ? void 0 : parent.value) === null || _c === void 0 ? void 0 : _c.item) !== null && _d !== void 0 ? _d : '', TextFormat.bitmarkMinusMinus);
578
671
  this.writeCL();
@@ -590,6 +683,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
590
683
  return false; // Ignore empty
591
684
  if (!this.isEmptyText((_a = parent === null || parent === void 0 ? void 0 : parent.value) === null || _a === void 0 ? void 0 : _a.marginNumber))
592
685
  return true; // Will be handled by marginNumber
686
+ this.writeNL_IfNotChain(route);
593
687
  this.writeOPC();
594
688
  this.textGenerator.generateSync((_c = (_b = parent === null || parent === void 0 ? void 0 : parent.value) === null || _b === void 0 ? void 0 : _b.item) !== null && _c !== void 0 ? _c : '', TextFormat.bitmarkMinusMinus);
595
689
  this.writeCL();
@@ -608,6 +702,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
608
702
  const parent = this.getParentNode(route);
609
703
  if (this.isEmptyText(marginNumber))
610
704
  return false; // Ignore empty
705
+ this.writeNL_IfNotChain(route);
611
706
  this.writeOPC();
612
707
  this.textGenerator.generateSync((_b = (_a = parent === null || parent === void 0 ? void 0 : parent.value) === null || _a === void 0 ? void 0 : _a.item) !== null && _b !== void 0 ? _b : '', TextFormat.bitmarkMinusMinus);
613
708
  this.writeCL();
@@ -630,7 +725,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
630
725
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.bitsValue && (parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.cardBitsValue)
631
726
  return true;
632
727
  this.inTag = false;
633
- // always write a NL before the body content if there is any?
728
+ // Always write a NL before the body content if there is any (see Handle body)
634
729
  const body = node.value;
635
730
  const textFormat = this.getTextFormat(route);
636
731
  const isBitmarkText = textFormat === TextFormat.bitmarkPlusPlus || textFormat === TextFormat.bitmarkMinusMinus;
@@ -640,7 +735,6 @@ class BitmarkGenerator extends AstWalkerGenerator {
640
735
  if (Array.isArray(json) || ObjectUtils.isObject(json)) {
641
736
  const text = JSON.stringify(json, null, this.prettifySpace);
642
737
  if (text) {
643
- this.writeNL();
644
738
  this.writePlainTextDivider();
645
739
  this.writeNL();
646
740
  this.write(Breakscape.breakscape(text, {
@@ -661,27 +755,15 @@ class BitmarkGenerator extends AstWalkerGenerator {
661
755
  }
662
756
  else {
663
757
  // handle plain text
664
- this.writeNL();
665
758
  this.writePlainTextDivider();
666
759
  this.writeNL();
667
760
  const s = (StringUtils.isString(body.body) ? body.body : '');
668
761
  this.write(Breakscape.breakscape(`${s}`, {
669
762
  textFormat: TextFormat.text,
670
763
  }));
671
- this.writeNL();
672
764
  }
673
765
  // Stop traversal of this branch
674
766
  return false;
675
- // if ((body.body && body.body.length > 0) || body.bodyJson) {
676
- // this.writeNL();
677
- // // Write the plain text divider if not bitmark++/-- format
678
- // const textFormat = this.getTextFormat(route);
679
- // const isBitmarkText = textFormat === TextFormat.bitmarkPlusPlus || textFormat === TextFormat.bitmarkMinusMinus;
680
- // if (!isBitmarkText) {
681
- // this.writePlainTextDivider();
682
- // this.writeNL();
683
- // }
684
- // }
685
767
  }
686
768
  exit_body(_node, _route) {
687
769
  this.inTag = true;
@@ -747,6 +829,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
747
829
  const isBitmarkText = textFormat === TextFormat.bitmarkPlusPlus || textFormat === TextFormat.bitmarkMinusMinus;
748
830
  if (isBitmarkText) {
749
831
  // handle bitmark text
832
+ this.writeNL();
750
833
  this.write('==== footer ====');
751
834
  this.writeNL();
752
835
  // The text generator will write to the writer
@@ -841,7 +924,6 @@ class BitmarkGenerator extends AstWalkerGenerator {
841
924
  if (!this.isCardAllowed(route))
842
925
  return true;
843
926
  this.writeCardSetStart();
844
- this.writeNL();
845
927
  // Continue traversal
846
928
  return true;
847
929
  }
@@ -849,41 +931,27 @@ class BitmarkGenerator extends AstWalkerGenerator {
849
931
  // Ignore cards if not allowed
850
932
  if (!this.isCardAllowed(route))
851
933
  return;
852
- this.writeNL();
853
934
  this.writeCardSetCardDivider();
854
- this.writeNL();
855
935
  }
856
936
  exit_cardNode(_node, route) {
857
937
  // Ignore cards if not allowed
858
938
  if (!this.isCardAllowed(route))
859
939
  return;
860
- this.writeNL();
861
940
  this.writeCardSetEnd();
862
941
  if (this.options.cardSetVersion === CardSetVersion.v1) {
863
- this.writeNL();
942
+ // this.writeNL();
864
943
  }
865
944
  }
866
- // bitmarkAst -> bits -> bitsValue -> cardNode -> cardBitsValue
867
- between_cardBitsValue(_node, _left, _right, _route) {
868
- this.writeNL();
869
- }
870
945
  // bitmarkAst -> bits -> bitsValue -> cardNode -> elements
871
946
  enter_elements(_node, _route) {
872
947
  //
873
948
  }
874
949
  between_elements(_node, _left, _right, _route) {
875
- this.writeNL();
876
950
  this.writeCardSetVariantDivider();
877
- this.writeNL();
878
- }
879
- exit_elements(_node, _route) {
880
- //
881
951
  }
882
952
  // bitmarkAst -> bits -> bitsValue -> cardNode -> flashcards
883
953
  between_flashcards(_node, _left, _right, _route) {
884
- this.writeNL();
885
954
  this.writeCardSetCardDivider();
886
- this.writeNL();
887
955
  }
888
956
  // bitmarkAst -> bits -> bitsValue -> cardNode -> flashcards -> flashcardsValue
889
957
  between_flashcardsValue(_node, _left, right, route) {
@@ -892,67 +960,19 @@ class BitmarkGenerator extends AstWalkerGenerator {
892
960
  if (!this.isCardAllowed(route))
893
961
  return;
894
962
  if (right.key === NodeType.answer) {
895
- this.writeNL();
896
963
  this.writeCardSetSideDivider();
897
- this.writeNL();
898
964
  }
899
965
  else if (right.key === NodeType.alternativeAnswers && ((_a = right.value) === null || _a === void 0 ? void 0 : _a.length) !== 0) {
900
- this.writeNL();
901
966
  this.writeCardSetVariantDivider();
902
- this.writeNL();
903
967
  }
904
968
  }
905
- // bitmarkAst -> bits -> bitsValue -> cardNode -> flashcards -> flashcardsValue -> answer
906
- enter_answer(node, route) {
907
- // Ignore responses that are not at the flashcardsValue level as they are handled elsewhere
908
- const parent = this.getParentNode(route);
909
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.flashcardsValue)
910
- return true;
911
- if (node.value) {
912
- this.textGenerator.generateSync(node.value, TextFormat.bitmarkMinusMinus);
913
- }
914
- // Stop traversal of this branch
915
- return false;
916
- }
917
969
  // bitmarkAst -> bits -> bitsValue -> cardNode -> flashcards -> flashcardsValue -> alternativeAnswers
918
970
  between_alternativeAnswers(_node, _route) {
919
- this.writeNL();
920
971
  this.writeCardSetVariantDivider();
921
- this.writeNL();
922
- }
923
- // bitmarkAst -> bits -> bitsValue -> cardNode -> flashcards -> flashcardsValue -> alternativeAnswers -> alternativeAnswersValue
924
- enter_alternativeAnswersValue(node, route) {
925
- // Ignore responses that are not at the alternativeAnswers level as they are handled elsewhere
926
- const parent = this.getParentNode(route);
927
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.alternativeAnswers)
928
- return true;
929
- if (node.value) {
930
- // this.writeBreakscapedTagString(node.value);
931
- this.textGenerator.generateSync(node.value, TextFormat.bitmarkMinusMinus);
932
- }
933
- // Stop traversal of this branch
934
- return false;
935
972
  }
936
973
  // bitmarkAst -> bits -> bitsValue -> cardNode -> definitions -> definitionsValue -> alternativeDefintions
937
974
  between_alternativeDefinitions(_node, _route) {
938
- this.writeNL();
939
975
  this.writeCardSetVariantDivider();
940
- this.writeNL();
941
- }
942
- // bitmarkAst -> bits -> bitsValue -> cardNode -> definitions -> definitionsValue -> alternativeDefinitions -> alternativeDefinitionsValue
943
- enter_alternativeDefinitionsValue(node, route) {
944
- // Ignore responses that are not at the alternativeAnswers level as they are handled elsewhere
945
- const parent = this.getParentNode(route);
946
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.alternativeDefinitions)
947
- return true;
948
- if (node.value) {
949
- // this.writeNL();
950
- // this.writeCardSetVariantDivider();
951
- // this.writeNL();
952
- this.textGenerator.generateSync(node.value, TextFormat.bitmarkMinusMinus);
953
- }
954
- // Stop traversal of this branch
955
- return false;
956
976
  }
957
977
  // bitmarkAst -> bits -> bitsValue -> cardNode -> statements
958
978
  enter_statements(_node, _route) {
@@ -961,17 +981,13 @@ class BitmarkGenerator extends AstWalkerGenerator {
961
981
  between_statements(_node, _left, _right, route) {
962
982
  const isTrueFalse1 = this.isOfBitType(route, BitType.trueFalse1);
963
983
  if (!isTrueFalse1) {
964
- this.writeNL();
965
984
  this.writeCardSetCardDivider();
966
985
  }
967
- this.writeNL();
968
- }
969
- exit_statements(_node, _route) {
970
- //
971
986
  }
972
987
  // bitmarkAst -> bits -> bitsValue -> cardNode -> statements -> statementsValue
973
988
  enter_statementsValue(node, _route) {
974
989
  const statement = node.value;
990
+ this.writeNL();
975
991
  if (statement.isCorrect) {
976
992
  this.writeOPP();
977
993
  }
@@ -983,18 +999,11 @@ class BitmarkGenerator extends AstWalkerGenerator {
983
999
  // Continue traversal
984
1000
  return true;
985
1001
  }
986
- // bitmarkAst -> bits -> bitsValue -> choices
987
- // bitmarkAst -> bits -> bitsValue -> cardNode -> quizzes -> quizzesValue -> choices
988
- between_choices(_node, _left, _right, _route) {
989
- this.writeNL();
990
- }
991
- exit_choices(_node, _route) {
992
- this.writeNL();
993
- }
994
1002
  // bitmarkAst -> bits -> bitsValue -> choices -> choicesValue
995
1003
  // bitmarkAst -> bits -> bitsValue -> cardNode -> quizzes -> quizzesValue -> choices -> choicesValue
996
1004
  enter_choicesValue(node, _route) {
997
1005
  const choice = node.value;
1006
+ this.writeNL();
998
1007
  if (choice.isCorrect) {
999
1008
  this.writeOPP();
1000
1009
  }
@@ -1006,18 +1015,11 @@ class BitmarkGenerator extends AstWalkerGenerator {
1006
1015
  // Continue traversal
1007
1016
  return true;
1008
1017
  }
1009
- // bitmarkAst -> bits -> bitsValue -> responses
1010
- // bitmarkAst -> bits -> bitsValue -> cardNode -> quizzes -> quizzesValue -> responses
1011
- between_responses(_node, _left, _right, _route) {
1012
- this.writeNL();
1013
- }
1014
- exit_responses(_node, _route) {
1015
- this.writeNL();
1016
- }
1017
1018
  // bitmarkAst -> bits -> bitsValue -> responses -> responsesValue
1018
1019
  // bitmarkAst -> bits -> bitsValue -> cardNode -> quizzes -> quizzesValue -> responses -> responsesValue
1019
1020
  enter_responsesValue(node, _route) {
1020
1021
  const response = node.value;
1022
+ this.writeNL();
1021
1023
  if (response.isCorrect) {
1022
1024
  this.writeOPP();
1023
1025
  }
@@ -1034,18 +1036,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
1034
1036
  //
1035
1037
  }
1036
1038
  between_quizzes(_node, _left, _right, _route) {
1037
- // this.writeNL();
1038
1039
  this.writeCardSetCardDivider();
1039
- this.writeNL();
1040
- }
1041
- exit_quizzes(_node, _route) {
1042
- //
1043
- }
1044
- // bitmarkAst -> bits -> bitsValue -> cardNode -> quizzes -> quizzesValue
1045
- between_quizzesValue(_node, _left, right, _route) {
1046
- if (right.key === NodeType.choices || right.key === NodeType.responses) {
1047
- this.writeNL();
1048
- }
1049
1040
  }
1050
1041
  // bitmarkAst -> bits -> bitsValue -> cardNode -> heading
1051
1042
  enter_heading(_node, _route) {
@@ -1055,12 +1046,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
1055
1046
  // Ignore cards if not allowed
1056
1047
  if (!this.isCardAllowed(route))
1057
1048
  return;
1058
- this.writeNL();
1059
1049
  this.writeCardSetSideDivider();
1060
- this.writeNL();
1061
- }
1062
- exit_heading(_node, _route) {
1063
- //
1064
1050
  }
1065
1051
  // bitmarkAst -> bits -> bitsValue -> cardNode -> heading -> forValues
1066
1052
  enter_forValues(_node, _route) {
@@ -1070,33 +1056,20 @@ class BitmarkGenerator extends AstWalkerGenerator {
1070
1056
  // Ignore cards if not allowed
1071
1057
  if (!this.isCardAllowed(route))
1072
1058
  return;
1073
- this.writeNL();
1074
1059
  this.writeCardSetSideDivider();
1075
- this.writeNL();
1076
- }
1077
- exit_forValues(_node, _route) {
1078
- //
1079
1060
  }
1080
1061
  // bitmarkAst -> bits -> bitsValue -> cardNode -> pairs
1081
1062
  enter_pairs(_node, _route) {
1082
1063
  //
1083
1064
  }
1084
1065
  between_pairs(_node, _left, _right, _route) {
1085
- this.writeNL();
1086
1066
  this.writeCardSetCardDivider();
1087
- this.writeNL();
1088
- }
1089
- exit_pairs(_node, _route) {
1090
- //
1091
- }
1092
- // bitmarkAst -> bits -> bitsValue -> cardNode -> pairs -> pairsValue
1093
- between_pairsValue(_node, _left, _right, _route) {
1094
- //
1095
1067
  }
1096
1068
  // bitmarkAst -> bits -> bitsValue -> cardNode -> pairs -> pairsValue -> keyAudio
1097
1069
  enter_keyAudio(node, _route) {
1098
1070
  const resource = node.value;
1099
1071
  // This is a resource, so handle it with the common code
1072
+ this.writeNL();
1100
1073
  this.writeResource(ResourceTag.audio, resource.src);
1101
1074
  // Stop traversal of this branch
1102
1075
  return false;
@@ -1105,6 +1078,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
1105
1078
  enter_keyImage(node, _route) {
1106
1079
  const resource = node.value;
1107
1080
  // This is a resource, so handle it with the common code
1081
+ this.writeNL();
1108
1082
  this.writeResource(ResourceTag.image, resource.src);
1109
1083
  // Stop traversal of this branch
1110
1084
  return false;
@@ -1114,16 +1088,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
1114
1088
  //
1115
1089
  }
1116
1090
  between_matrix(_node, _left, _right, _route) {
1117
- this.writeNL();
1118
1091
  this.writeCardSetCardDivider();
1119
- this.writeNL();
1120
- }
1121
- exit_matrix(_node, _route) {
1122
- //
1123
- }
1124
- // bitmarkAst -> bits -> bitsValue -> cardNode -> matrix -> matrixValue
1125
- between_matrixValue(_node, _left, _right, _route) {
1126
- //
1127
1092
  }
1128
1093
  // bitmarkAst -> bits -> bitsValue -> cardNode -> pairs -> pairsValue -> values
1129
1094
  // bitmarkAst -> bits -> bitsValue -> cardNode -> matrix -> matrixValue -> cells -> cellsValue -> values
@@ -1131,17 +1096,13 @@ class BitmarkGenerator extends AstWalkerGenerator {
1131
1096
  // Ignore cards if not allowed
1132
1097
  if (!this.isCardAllowed(route))
1133
1098
  return;
1134
- this.writeNL();
1135
1099
  this.writeCardSetSideDivider();
1136
- this.writeNL();
1137
1100
  }
1138
1101
  between_values(_node, _left, _right, route) {
1139
1102
  // Ignore cards if not allowed
1140
1103
  if (!this.isCardAllowed(route))
1141
1104
  return;
1142
- this.writeNL();
1143
1105
  this.writeCardSetVariantDivider();
1144
- this.writeNL();
1145
1106
  }
1146
1107
  // bitmarkAst -> bits -> bitsValue -> cardNode -> pronunciationTable
1147
1108
  between_pronunciationTable(_node, _left, _right, route) {
@@ -1151,9 +1112,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
1151
1112
  // Ignore cards if not allowed
1152
1113
  if (!this.isCardAllowed(route))
1153
1114
  return;
1154
- this.writeNL();
1155
1115
  this.writeCardSetCardDivider();
1156
- this.writeNL();
1157
1116
  }
1158
1117
  // bitmarkAst -> bits -> bitsValue -> cardNode -> table
1159
1118
  between_table(_node, _left, _right, route) {
@@ -1163,9 +1122,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
1163
1122
  // Ignore cards if not allowed
1164
1123
  if (!this.isCardAllowed(route))
1165
1124
  return;
1166
- this.writeNL();
1167
1125
  this.writeCardSetCardDivider();
1168
- this.writeNL();
1169
1126
  }
1170
1127
  // bitmarkAst -> bits -> bitsValue -> cardNode -> table -> data
1171
1128
  // bitmarkAst -> bits -> bitsValue -> cardNode -> pronunciationTable -> data
@@ -1173,9 +1130,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
1173
1130
  const parent = this.getParentNode(route);
1174
1131
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.table && (parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.pronunciationTable)
1175
1132
  return;
1176
- this.writeNL();
1177
1133
  this.writeCardSetCardDivider();
1178
- this.writeNL();
1179
1134
  }
1180
1135
  // bitmarkAst -> bits -> bitsValue -> cardNode -> table -> columns
1181
1136
  // bitmarkAst -> bits -> bitsValue -> cardNode -> captionDefinitionList -> columns
@@ -1187,19 +1142,19 @@ class BitmarkGenerator extends AstWalkerGenerator {
1187
1142
  // Ignore cards if not allowed
1188
1143
  if (!this.isCardAllowed(route))
1189
1144
  return;
1190
- this.writeNL();
1191
1145
  this.writeCardSetSideDivider();
1192
- this.writeNL();
1193
1146
  }
1194
1147
  // bitmarkAst -> bits -> bitsValue -> cardNode -> table -> columns -> columnsValue
1195
1148
  // bitmarkAst -> bits -> bitsValue -> cardNode -> captionDefinitionList -> columns -> columnsValue
1196
1149
  leaf_columnsValue(node, _route) {
1150
+ this.writeNL();
1197
1151
  this.writeOPHASH();
1198
1152
  if (node.value)
1199
1153
  this.writeBreakscapedTagString(node.value);
1200
1154
  this.writeCL();
1201
1155
  }
1202
1156
  enter_columnsValue(node, _route) {
1157
+ this.writeNL();
1203
1158
  this.writeOPHASH();
1204
1159
  if (node.value) {
1205
1160
  this.textGenerator.generateSync(node.value, TextFormat.bitmarkMinusMinus);
@@ -1215,15 +1170,14 @@ class BitmarkGenerator extends AstWalkerGenerator {
1215
1170
  // Ignore cards if not allowed
1216
1171
  if (!this.isCardAllowed(route))
1217
1172
  return;
1218
- this.writeNL();
1219
1173
  this.writeCardSetSideDivider();
1220
- this.writeNL();
1221
1174
  }
1222
1175
  // bitmarkAst -> bits -> bitsValue -> cardNode -> table -> data -> dataValue -> dataValueValue
1223
1176
  leaf_dataValueValue(node, route) {
1224
1177
  const parent = this.getParentNode(route, 3);
1225
1178
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.table)
1226
1179
  return;
1180
+ this.writeNL();
1227
1181
  this.write(node.value);
1228
1182
  }
1229
1183
  // bitmarkAst -> bits -> bitsValue -> cardNode -> table -> data -> dataValue -> dataValueValue
@@ -1239,17 +1193,18 @@ class BitmarkGenerator extends AstWalkerGenerator {
1239
1193
  // Pronunciation Table
1240
1194
  const cell = node.value;
1241
1195
  if (cell.title) {
1196
+ this.writeNL();
1242
1197
  this.writeOP();
1243
1198
  this.writeHash();
1244
1199
  this.textGenerator.generateSync(cell.title, TextFormat.bitmarkMinusMinus);
1245
1200
  this.writeCL();
1246
- this.writeNL();
1247
1201
  }
1248
1202
  if (cell.audio) {
1249
- this.writeResource(ResourceTag.audio, cell.audio.src);
1250
1203
  this.writeNL();
1204
+ this.writeResource(ResourceTag.audio, cell.audio.src);
1251
1205
  }
1252
1206
  if (cell.body) {
1207
+ this.writeNL();
1253
1208
  this.textGenerator.generateSync(cell.body, textFormat);
1254
1209
  }
1255
1210
  // Stop traversal of this branch
@@ -1257,6 +1212,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
1257
1212
  }
1258
1213
  else {
1259
1214
  // Table
1215
+ this.writeNL();
1260
1216
  this.textGenerator.generateSync(node.value, textFormat);
1261
1217
  }
1262
1218
  }
@@ -1267,38 +1223,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
1267
1223
  const parent = this.getParentNode(route);
1268
1224
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.cardNode)
1269
1225
  return;
1270
- this.writeNL();
1271
1226
  this.writeCardSetCardDivider();
1272
- this.writeNL();
1273
- }
1274
- // // bitmarkAst -> bits -> bitsValue -> cardNode -> captionDefinitionList -> definitions
1275
- // protected between_definitions(_node: NodeInfo, _left: NodeInfo, _right: NodeInfo, route: NodeInfo[]): void {
1276
- // const parent = this.getParentNode(route);
1277
- // if (parent?.key !== NodeType.captionDefinitionList) return;
1278
- // this.writeNL();
1279
- // this.writeCardSetCardDivider();
1280
- // this.writeNL();
1281
- // }
1282
- // // bitmarkAst -> bits -> bitsValue -> cardNode -> captionDefinitionList -> definitions -> definitionsValue
1283
- // protected between_definitionsValue(_node: NodeInfo, _left: NodeInfo, _right: NodeInfo, route: NodeInfo[]): void {
1284
- // const parent = this.getParentNode(route);
1285
- // if (parent?.key !== NodeType.definitions) return;
1286
- // // Ignore cards if not allowed
1287
- // if (!this.isCardAllowed(route)) return;
1288
- // this.writeNL();
1289
- // this.writeCardSetSideDivider();
1290
- // this.writeNL();
1291
- // }
1292
- // bitmarkAst -> bits -> bitsValue -> cardNode -> definitions -> definitionsValue -> term
1293
- enter_term(node, route) {
1294
- const parent = this.getParentNode(route);
1295
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.definitionsValue)
1296
- return true;
1297
- if (node.value) {
1298
- this.textGenerator.generateSync(node.value, TextFormat.bitmarkMinusMinus);
1299
- }
1300
- // Stop traversal of this branch
1301
- return false;
1302
1227
  }
1303
1228
  // bitmarkAst -> bits -> bitsValue -> cardNode -> captionDefinitionList -> definitions -> definitionsValue -> term
1304
1229
  leaf_term(node, route) {
@@ -1306,28 +1231,19 @@ class BitmarkGenerator extends AstWalkerGenerator {
1306
1231
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.definitionsValue)
1307
1232
  return true;
1308
1233
  if (node.value) {
1234
+ this.writeNL();
1309
1235
  this.write(node.value);
1310
1236
  }
1311
1237
  // Stop traversal of this branch
1312
1238
  return false;
1313
1239
  }
1314
- // bitmarkAst -> bits -> bitsValue -> cardNode -> definitions -> definitionsValue -> definition
1315
- enter_definition(node, route) {
1316
- const parent = this.getParentNode(route);
1317
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.definitionsValue)
1318
- return true;
1319
- if (node.value) {
1320
- this.textGenerator.generateSync(node.value, TextFormat.bitmarkMinusMinus);
1321
- }
1322
- // Stop traversal of this branch
1323
- return false;
1324
- }
1325
1240
  // bitmarkAst -> bits -> bitsValue -> cardNode -> captionDefinitionList -> definitions -> definitionsValue -> definition
1326
1241
  leaf_definition(node, route) {
1327
1242
  const parent = this.getParentNode(route);
1328
1243
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.definitionsValue)
1329
1244
  return true;
1330
1245
  if (node.value) {
1246
+ this.writeNL();
1331
1247
  this.write(node.value);
1332
1248
  }
1333
1249
  // Stop traversal of this branch
@@ -1339,9 +1255,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
1339
1255
  const parent = this.getParentNode(route);
1340
1256
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.cardNode && (parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.captionDefinitionList)
1341
1257
  return;
1342
- this.writeNL();
1343
1258
  this.writeCardSetCardDivider();
1344
- this.writeNL();
1345
1259
  }
1346
1260
  // bitmarkAst -> bits -> bitsValue -> cardNode -> definitions -> definitionsValue
1347
1261
  between_definitionsValue(_node, _left, right, route) {
@@ -1353,75 +1267,37 @@ class BitmarkGenerator extends AstWalkerGenerator {
1353
1267
  if (!this.isCardAllowed(route))
1354
1268
  return;
1355
1269
  if (right.key === NodeType.definition) {
1356
- this.writeNL();
1357
1270
  this.writeCardSetSideDivider();
1358
- this.writeNL();
1359
1271
  }
1360
1272
  else if (right.key === NodeType.alternativeDefinitions && ((_a = right.value) === null || _a === void 0 ? void 0 : _a.length) > 0) {
1361
- this.writeNL();
1362
1273
  this.writeCardSetVariantDivider();
1363
- this.writeNL();
1364
1274
  }
1365
1275
  }
1366
- // bitmarkAst -> bits -> bitsValue -> cardNode -> captionDefinitionList -> definitions -> definitionsValue
1367
- // protected between_definitionsValue(_node: NodeInfo, _left: NodeInfo, right: NodeInfo, route: NodeInfo[]): void {
1368
- // const parent = this.getParentNode(route);
1369
- // if (parent?.key !== NodeType.definitions) return;
1370
- // // Ignore cards if not allowed
1371
- // if (!this.isCardAllowed(route)) return;
1372
- // if (right.key === NodeType.definition) {
1373
- // this.writeNL();
1374
- // this.writeCardSetSideDivider();
1375
- // this.writeNL();
1376
- // } else if (right.key === NodeType.alternativeDefinitions && right.value?.length > 0) {
1377
- // this.writeNL();
1378
- // this.writeCardSetVariantDivider();
1379
- // this.writeNL();
1380
- // }
1381
- // }
1382
1276
  // bitmarkAst -> bits -> bitsValue -> cardNode -> questions
1383
1277
  enter_questions(_node, _route) {
1384
1278
  //
1385
1279
  }
1386
1280
  between_questions(_node, _left, _right, _route) {
1387
1281
  this.writeCardSetCardDivider();
1388
- this.writeNL();
1389
- }
1390
- exit_questions(_node, _route) {
1391
- //
1392
- }
1393
- // bitmarkAst -> bits -> bitsValue -> cardNode -> questions -> questionsValue
1394
- between_questionsValue(node, left, right, route) {
1395
- // The following keys are combined with other keys so don't need newlines
1396
- const noNlKeys = [
1397
- //
1398
- ];
1399
- this.writeNlBetween(node, left, right, route, noNlKeys);
1400
- }
1401
- exit_questionsValue(_node, _route) {
1402
- this.writeNL();
1403
1282
  }
1404
1283
  // bitmarkAst -> bits -> bitsValue -> cardNode -> ingredients
1405
1284
  enter_ingredients(_node, _route) {
1406
1285
  //
1407
1286
  }
1408
1287
  between_ingredients(_node, _left, _right, _route) {
1409
- this.writeNL();
1410
1288
  this.writeCardSetCardDivider();
1411
- this.writeNL();
1412
- }
1413
- exit_ingredients(_node, _route) {
1414
- //
1415
1289
  }
1416
1290
  // bitmarkAst -> bits -> bitsValue -> cardNode -> ingredients -> ingredientsValue
1417
1291
  enter_ingredientsValue(node, _route) {
1418
1292
  const ingredient = node.value;
1419
1293
  if (ingredient.title != null) {
1294
+ this.writeNL();
1420
1295
  this.writeOPHASH();
1421
1296
  this.writeBreakscapedTagString(ingredient.title);
1422
1297
  this.writeCL();
1423
- this.writeNL();
1298
+ // this.writeNL();
1424
1299
  }
1300
+ this.writeNL();
1425
1301
  // [+] / [-]
1426
1302
  if (ingredient.checked) {
1427
1303
  this.writeOPP();
@@ -1465,8 +1341,10 @@ class BitmarkGenerator extends AstWalkerGenerator {
1465
1341
  ignoreEmpty: true,
1466
1342
  });
1467
1343
  // item
1468
- if (ingredient.item != null)
1344
+ if (ingredient.item != null) {
1345
+ this.writeNL();
1469
1346
  this.write(ingredient.item);
1347
+ }
1470
1348
  // Stop traversal of this branch
1471
1349
  return false;
1472
1350
  }
@@ -1476,35 +1354,20 @@ class BitmarkGenerator extends AstWalkerGenerator {
1476
1354
  }
1477
1355
  between_botResponses(_node, _left, _right, _route) {
1478
1356
  this.writeCardSetCardDivider();
1479
- this.writeNL();
1480
- }
1481
- exit_botResponses(_node, _route) {
1482
- //
1483
- }
1484
- // bitmarkAst -> bits -> bitsValue -> cardNode -> botResponses -> botResponsesValue
1485
- between_botResponsesValue(_node, _left, _right, _route) {
1486
- this.writeNL();
1487
- }
1488
- exit_botResponsesValue(_node, _route) {
1489
- this.writeNL();
1490
1357
  }
1491
1358
  // bitmarkAst -> bits -> bitsValue -> cardNode -> cardBits
1492
1359
  enter_cardBits(_node, _route) {
1493
1360
  //
1494
1361
  }
1495
1362
  between_cardBits(_node, _left, _right, _route) {
1496
- this.writeNL();
1497
1363
  this.writeCardSetCardDivider();
1498
- this.writeNL();
1499
- }
1500
- exit_cardBits(_node, _route) {
1501
- //
1502
1364
  }
1503
1365
  // bitmarkAst -> bits -> bitsValue -> cardNode -> botResponses -> botResponsesValue -> response
1504
1366
  leaf_response(node, route) {
1505
1367
  const parent = this.getParentNode(route);
1506
1368
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.botResponsesValue)
1507
1369
  return;
1370
+ this.writeNL();
1508
1371
  this.writeOPB();
1509
1372
  this.writeBreakscapedTagString(node.value);
1510
1373
  this.writeCL();
@@ -1514,6 +1377,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
1514
1377
  const parent = this.getParentNode(route);
1515
1378
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.botResponsesValue)
1516
1379
  return;
1380
+ this.writeNL();
1517
1381
  this.writeProperty('reaction', node.value, {
1518
1382
  format: PropertyFormat.trimmedString,
1519
1383
  single: true,
@@ -1527,6 +1391,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
1527
1391
  return;
1528
1392
  const feeback = node.value;
1529
1393
  if (feeback) {
1394
+ this.writeNL();
1530
1395
  this.write(feeback);
1531
1396
  }
1532
1397
  }
@@ -1534,12 +1399,13 @@ class BitmarkGenerator extends AstWalkerGenerator {
1534
1399
  enter_imagePlaceholder(node, _route) {
1535
1400
  const resource = node.value;
1536
1401
  // This is a resource, so handle it with the common code
1402
+ this.writeNL();
1537
1403
  this.writePropertyStyleResource(node.key, resource);
1538
1404
  // Continue traversal
1539
1405
  return true;
1540
1406
  }
1541
1407
  exit_imagePlaceholder(_node, _route) {
1542
- this.writeNL();
1408
+ // this.writeNL();
1543
1409
  }
1544
1410
  // bitmarkAst -> bits -> bitsValue -> posterImage
1545
1411
  // bitmarkAst -> bits -> bitsValue -> resource -> * -> posterImage
@@ -1638,9 +1504,6 @@ class BitmarkGenerator extends AstWalkerGenerator {
1638
1504
  enter_book(_node, _route) {
1639
1505
  // Block standard property handling
1640
1506
  }
1641
- between_book(_node, _route) {
1642
- this.writeNL();
1643
- }
1644
1507
  enter_bookValue(node, _route) {
1645
1508
  const book = node.value;
1646
1509
  // const parent = this.getParentNode(route);
@@ -1711,10 +1574,11 @@ class BitmarkGenerator extends AstWalkerGenerator {
1711
1574
  // * -> itemLead --> item
1712
1575
  // * -> itemLead --> lead
1713
1576
  // * -> hint
1714
- enter_hint(node, _route) {
1577
+ enter_hint(node, route) {
1715
1578
  const value = node.value;
1716
1579
  const text = value;
1717
1580
  if (!this.isEmptyText(text)) {
1581
+ this.writeNL_IfNotChain(route);
1718
1582
  this.writeOPQ();
1719
1583
  this.textGenerator.generateSync(text, TextFormat.bitmarkMinusMinus);
1720
1584
  this.writeCL();
@@ -1723,10 +1587,11 @@ class BitmarkGenerator extends AstWalkerGenerator {
1723
1587
  return false;
1724
1588
  }
1725
1589
  // bitmarkAst -> bits -> bitsValue -> * -> instruction
1726
- enter_instruction(node, _route) {
1590
+ enter_instruction(node, route) {
1727
1591
  const value = node.value;
1728
1592
  const text = value;
1729
1593
  if (!this.isEmptyText(text)) {
1594
+ this.writeNL_IfNotChain(route);
1730
1595
  this.writeOPB();
1731
1596
  this.textGenerator.generateSync(text, TextFormat.bitmarkMinusMinus);
1732
1597
  this.writeCL();
@@ -1736,6 +1601,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
1736
1601
  }
1737
1602
  // bitmarkAst -> bits -> bitsValue -> * -> lang
1738
1603
  enter_lang(node, _route) {
1604
+ this.writeNL();
1739
1605
  this.writeProperty('lang', node.value, {
1740
1606
  format: PropertyFormat.boolean,
1741
1607
  single: true,
@@ -1744,6 +1610,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
1744
1610
  }
1745
1611
  // bitmarkAst -> bits -> bitsValue -> * -> refAuthor
1746
1612
  enter_refAuthor(node, _route) {
1613
+ this.writeNL();
1747
1614
  this.writeProperty('refAuthor', node.value, {
1748
1615
  format: PropertyFormat.trimmedString,
1749
1616
  single: false,
@@ -1752,6 +1619,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
1752
1619
  }
1753
1620
  // bitmarkAst -> bits -> bitsValue -> * -> refBookTitle
1754
1621
  enter_refBookTitle(node, _route) {
1622
+ this.writeNL();
1755
1623
  this.writeProperty('refBookTitle', node.value, {
1756
1624
  format: PropertyFormat.trimmedString,
1757
1625
  single: true,
@@ -1760,6 +1628,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
1760
1628
  }
1761
1629
  // bitmarkAst -> bits -> bitsValue -> * -> refPublisher
1762
1630
  enter_refPublisher(node, _route) {
1631
+ this.writeNL();
1763
1632
  this.writeProperty('refPublisher', node.value, {
1764
1633
  format: PropertyFormat.trimmedString,
1765
1634
  single: false,
@@ -1776,6 +1645,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
1776
1645
  }
1777
1646
  // bitmarkAst -> bits -> bitsValue -> * -> citationStyle
1778
1647
  enter_citationStyle(node, _route) {
1648
+ this.writeNL();
1779
1649
  this.writeProperty('citationStyle', node.value, {
1780
1650
  format: PropertyFormat.trimmedString,
1781
1651
  single: true,
@@ -1792,6 +1662,8 @@ class BitmarkGenerator extends AstWalkerGenerator {
1792
1662
  const example = (_a = parent === null || parent === void 0 ? void 0 : parent.value.example) !== null && _a !== void 0 ? _a : null;
1793
1663
  // const __isDefaultExample = parent?.value.__isDefaultExample ?? false;
1794
1664
  if (example != null && example !== '') {
1665
+ // Write a newline if not in a chain
1666
+ this.writeNL_IfNotChain(route);
1795
1667
  this.writeOPA();
1796
1668
  this.writeString('example');
1797
1669
  this.writeColon();
@@ -1821,6 +1693,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
1821
1693
  // bitmarkAst -> bits -> bitsValue -> elements -> elementsValue
1822
1694
  leaf_elementsValue(node, _route) {
1823
1695
  if (node.value) {
1696
+ this.writeNL();
1824
1697
  this.writeBreakscapedTagString(node.value);
1825
1698
  }
1826
1699
  }
@@ -1866,18 +1739,21 @@ class BitmarkGenerator extends AstWalkerGenerator {
1866
1739
  // bitmarkAst -> bits -> bitsValue -> * -> isCorrect
1867
1740
  // bitmarkAst -> bits -> bitsValue -> heading -> forKeys
1868
1741
  leaf_forKeys(node, _route) {
1742
+ this.writeNL();
1869
1743
  this.writeOPHASH();
1870
1744
  this.writeBreakscapedTagString(node.value);
1871
1745
  this.writeCL();
1872
1746
  }
1873
1747
  // bitmarkAst -> bits -> bitsValue -> heading -> forValues
1874
1748
  leaf_forValues(node, _route) {
1749
+ this.writeNL();
1875
1750
  this.writeOPHASH();
1876
1751
  this.writeBreakscapedTagString(node.value);
1877
1752
  this.writeCL();
1878
1753
  }
1879
1754
  // bitmarkAst -> bits -> bitsValue -> heading -> forValuesValue
1880
1755
  leaf_forValuesValue(node, _route) {
1756
+ this.writeNL();
1881
1757
  this.writeOPHASH();
1882
1758
  this.writeBreakscapedTagString(node.value);
1883
1759
  this.writeCL();
@@ -1886,6 +1762,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
1886
1762
  // bitmarkAst -> bits -> bitsValue -> matrix -> matrixValue -> key
1887
1763
  leaf_key(node, _route) {
1888
1764
  if (node.value) {
1765
+ this.writeNL();
1889
1766
  this.writeBreakscapedTagString(node.value);
1890
1767
  }
1891
1768
  }
@@ -1893,6 +1770,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
1893
1770
  // bitmarkAst -> bits -> bitsValue -> matrix -> matrixValue -> cells -> cellsValue -> values -> valuesValue
1894
1771
  leaf_valuesValue(node, _route) {
1895
1772
  if (node.value) {
1773
+ this.writeNL();
1896
1774
  this.writeBreakscapedTagString(node.value);
1897
1775
  }
1898
1776
  }
@@ -1904,23 +1782,10 @@ class BitmarkGenerator extends AstWalkerGenerator {
1904
1782
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.questionsValue && (parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.flashcardsValue)
1905
1783
  return;
1906
1784
  if (node.value) {
1785
+ this.writeNL();
1907
1786
  this.writeBreakscapedTagString(node.value);
1908
- // this.writeNL();
1909
1787
  }
1910
1788
  }
1911
- enter_question(node, route) {
1912
- // Ignore responses that are not at the questionsValue level as they are handled elsewhere
1913
- const parent = this.getParentNode(route);
1914
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.questionsValue && (parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.flashcardsValue)
1915
- return true;
1916
- if (node.value) {
1917
- this.textGenerator.generateSync(node.value, TextFormat.bitmarkMinusMinus);
1918
- // this.writeString(node.value);
1919
- // this.writeNL();
1920
- }
1921
- // Stop traversal of this branch
1922
- return false;
1923
- }
1924
1789
  // bitmarkAst -> bits -> bitsValue -> statements -> text
1925
1790
  // bitmarkAst -> bits -> bitsValue -> resource -> ...
1926
1791
  // bitmarkAst -> bits -> bitsValue -> resource -> posterImage -> ...
@@ -2025,8 +1890,9 @@ class BitmarkGenerator extends AstWalkerGenerator {
2025
1890
  ignoreFalse: true,
2026
1891
  });
2027
1892
  }
2028
- enter_caption(node, _route) {
1893
+ enter_caption(node, route) {
2029
1894
  const value = node.value;
1895
+ this.writeNL_IfNotChain(route);
2030
1896
  this.writeProperty('caption', value, {
2031
1897
  format: PropertyFormat.bitmarkMinusMinus,
2032
1898
  single: true, // ??
@@ -2089,17 +1955,6 @@ class BitmarkGenerator extends AstWalkerGenerator {
2089
1955
  //
2090
1956
  // Resources
2091
1957
  //
2092
- // bitmarkAst -> bits -> bitsValue -> resources
2093
- between_resources(_node, _left, _right, _route) {
2094
- this.writeNL();
2095
- }
2096
- exit_resources(_node, _left, _right, _route) {
2097
- this.writeNL();
2098
- }
2099
- // bitmarkAst -> bits -> bitsValue -> resourcesValue
2100
- between_resourcesValue(_node, _left, _right, _route) {
2101
- this.writeNL();
2102
- }
2103
1958
  //
2104
1959
  // Generated Node Handlers
2105
1960
  //
@@ -2134,6 +1989,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
2134
1989
  // url / src / href / app
2135
1990
  const url = resource.url || resource.src || resource.body || '';
2136
1991
  // Write the resource
1992
+ this.writeNL();
2137
1993
  this.writeResource(type, url);
2138
1994
  // Continue traversal
2139
1995
  return true;
@@ -2146,14 +2002,6 @@ class BitmarkGenerator extends AstWalkerGenerator {
2146
2002
  /**
2147
2003
  * Generate the handlers for properties, as they are mostly the same, but not quite
2148
2004
  */
2149
- // protected enter_labelTrue(node: NodeInfo, _route: NodeInfo[],
2150
- // ): void {
2151
- // const bit = parent?.value as Bit;
2152
- // if (bit) {
2153
- // this.writeProperty('labelTrue', node.value ?? '', true);
2154
- // this.writeProperty('labelFalse', bit.labelFalse ?? '', true);
2155
- // }
2156
- // }
2157
2005
  generatePropertyHandlers() {
2158
2006
  var _a;
2159
2007
  const propertiesConfig = Config.getRawPropertiesConfig();
@@ -2180,6 +2028,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
2180
2028
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.bitsValue)
2181
2029
  return;
2182
2030
  // Write the property
2031
+ this.writeNL(); // Only if NOT in chain (how do we know this?)
2183
2032
  this.writeProperty(propertyConfig.tag, node.value, {
2184
2033
  format: (_a = propertyConfig.format) !== null && _a !== void 0 ? _a : PropertyFormat.trimmedString,
2185
2034
  single: (_b = propertyConfig.single) !== null && _b !== void 0 ? _b : false,
@@ -2192,35 +2041,30 @@ class BitmarkGenerator extends AstWalkerGenerator {
2192
2041
  this[enterFuncName] = this[enterFuncName].bind(this);
2193
2042
  }
2194
2043
  }
2195
- writeNlBetween(node, left, _right, _route,
2196
- // The following keys are combined with other keys so don't need newlines
2197
- noNlKeys) {
2198
- const bit = node.value;
2199
- if (bit.book) {
2200
- // If the book node exists, remove the newline caused by reference as it will be bound to book
2201
- noNlKeys.push(NodeType.reference);
2202
- }
2203
- // Check if a no newline key is to the left in this 'between' callback
2204
- const noNl = (() => {
2205
- if (!this.wroteSomething || this.skipNLBetweenBitsValue) {
2206
- return true;
2207
- }
2208
- for (const keyType of noNlKeys) {
2209
- if (left.key === keyType /*|| right.key === keyType*/)
2210
- return true;
2211
- }
2212
- return false;
2213
- })();
2214
- if (!noNl) {
2215
- this.writeNL();
2216
- }
2217
- this.skipNLBetweenBitsValue = false;
2218
- this.wroteSomething = false;
2219
- }
2220
2044
  // END NODE HANDLERS
2221
2045
  //
2222
2046
  // UTILITY FUNCTIONS
2223
2047
  //
2048
+ isChain(route) {
2049
+ const parent = this.getParentNode(route);
2050
+ // Root of bit
2051
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) === NodeType.bitsValue)
2052
+ return false;
2053
+ // Root of card bits
2054
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) === NodeType.cardBitsValue)
2055
+ return false;
2056
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) === NodeType.quizzesValue)
2057
+ return false;
2058
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) === NodeType.pairsValue)
2059
+ return false;
2060
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) === NodeType.matrixValue)
2061
+ return false;
2062
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) === NodeType.definitionsValue)
2063
+ return false;
2064
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) === NodeType.questionsValue)
2065
+ return false;
2066
+ return true;
2067
+ }
2224
2068
  haveValidCardSet(bit) {
2225
2069
  const bitConfig = Config.getBitConfig(bit.bitType);
2226
2070
  if (!bitConfig)
@@ -2352,17 +2196,20 @@ class BitmarkGenerator extends AstWalkerGenerator {
2352
2196
  this.write('#');
2353
2197
  }
2354
2198
  writePlainTextDivider() {
2199
+ this.writeNL();
2355
2200
  this.write('==== text ====');
2356
2201
  }
2357
2202
  writeCardSetStart() {
2203
+ this.writeNL();
2358
2204
  if (this.options.cardSetVersion === CardSetVersion.v1) {
2359
- this.write('\n===');
2205
+ this.write('===');
2360
2206
  }
2361
2207
  else {
2362
- this.write('\n====');
2208
+ this.write('====');
2363
2209
  }
2364
2210
  }
2365
2211
  writeCardSetEnd() {
2212
+ this.writeNL();
2366
2213
  if (this.options.cardSetVersion === CardSetVersion.v1) {
2367
2214
  this.write('===');
2368
2215
  }
@@ -2371,6 +2218,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
2371
2218
  }
2372
2219
  }
2373
2220
  writeCardSetCardDivider() {
2221
+ this.writeNL();
2374
2222
  if (this.options.cardSetVersion === CardSetVersion.v1) {
2375
2223
  this.write('===');
2376
2224
  }
@@ -2379,6 +2227,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
2379
2227
  }
2380
2228
  }
2381
2229
  writeCardSetSideDivider() {
2230
+ this.writeNL();
2382
2231
  if (this.options.cardSetVersion === CardSetVersion.v1) {
2383
2232
  this.write('==');
2384
2233
  }
@@ -2387,6 +2236,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
2387
2236
  }
2388
2237
  }
2389
2238
  writeCardSetVariantDivider() {
2239
+ this.writeNL();
2390
2240
  if (this.options.cardSetVersion === CardSetVersion.v1) {
2391
2241
  this.write('--');
2392
2242
  }
@@ -2394,6 +2244,11 @@ class BitmarkGenerator extends AstWalkerGenerator {
2394
2244
  this.write('++');
2395
2245
  }
2396
2246
  }
2247
+ writeNL_IfNotChain(route) {
2248
+ if (!this.isChain(route)) {
2249
+ this.writeNL();
2250
+ }
2251
+ }
2397
2252
  writeNL() {
2398
2253
  if (this.options.debugGenerationInline) {
2399
2254
  this.write('\\n');
@@ -2413,7 +2268,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
2413
2268
  this.writeColon();
2414
2269
  this.writeBreakscapedTagString(src);
2415
2270
  if (resource.type === ResourceTag.article) {
2416
- this.writeNL();
2271
+ // this.writeNL();
2417
2272
  }
2418
2273
  this.writeCL();
2419
2274
  }
@@ -2427,7 +2282,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
2427
2282
  this.writeColon();
2428
2283
  this.writeBreakscapedTagString(value);
2429
2284
  if (type === ResourceTag.article) {
2430
- this.writeNL();
2285
+ // this.writeNL();
2431
2286
  }
2432
2287
  this.writeCL();
2433
2288
  }
@@ -2435,7 +2290,6 @@ class BitmarkGenerator extends AstWalkerGenerator {
2435
2290
  writeProperty(name, values, options) {
2436
2291
  var _a;
2437
2292
  let valuesArray;
2438
- let wroteSomething = false;
2439
2293
  if (values !== undefined) {
2440
2294
  const isBitmarkText = options.format === PropertyFormat.bitmarkMinusMinus || options.format === PropertyFormat.bitmarkPlusPlus;
2441
2295
  if (isBitmarkText) {
@@ -2447,7 +2301,6 @@ class BitmarkGenerator extends AstWalkerGenerator {
2447
2301
  this.writeColon();
2448
2302
  this.textGenerator.generateSync(values, (_a = TextFormat.fromValue(options.format)) !== null && _a !== void 0 ? _a : TextFormat.bitmarkMinusMinus);
2449
2303
  this.writeCL();
2450
- wroteSomething = true;
2451
2304
  }
2452
2305
  else {
2453
2306
  // Write any other property type
@@ -2460,7 +2313,6 @@ class BitmarkGenerator extends AstWalkerGenerator {
2460
2313
  if (valuesArray.length > 0) {
2461
2314
  if (options.single)
2462
2315
  valuesArray = valuesArray.slice(valuesArray.length - 1);
2463
- let propertyIndex = 0;
2464
2316
  for (const val of valuesArray) {
2465
2317
  if (val !== undefined) {
2466
2318
  if (options.ignoreFalse && val === false)
@@ -2469,23 +2321,17 @@ class BitmarkGenerator extends AstWalkerGenerator {
2469
2321
  continue;
2470
2322
  if (options.ignoreEmpty && val === '')
2471
2323
  continue;
2472
- if (propertyIndex > 0)
2473
- this.writeNL();
2474
2324
  this.writeOPA();
2475
2325
  this.writeBreakscapedTagString(name);
2476
2326
  this.writeColon();
2477
2327
  this.writeBreakscapedTagString(`${val}`);
2478
2328
  this.writeCL();
2479
- wroteSomething = true;
2480
- propertyIndex++;
2329
+ // propertyIndex++;
2481
2330
  }
2482
2331
  }
2483
2332
  }
2484
2333
  } // isBitmarkText
2485
2334
  }
2486
- if (!wroteSomething) {
2487
- this.skipNLBetweenBitsValue = true;
2488
- }
2489
2335
  }
2490
2336
  writeInlineDebug(key, state) {
2491
2337
  let tag = key;
@@ -2553,8 +2399,6 @@ class BitmarkGenerator extends AstWalkerGenerator {
2553
2399
  * @param value - The string value to be written.
2554
2400
  */
2555
2401
  write(value) {
2556
- if (value)
2557
- this.wroteSomething = true;
2558
2402
  this.writer.write(value);
2559
2403
  return this;
2560
2404
  }
@@ -2563,8 +2407,6 @@ class BitmarkGenerator extends AstWalkerGenerator {
2563
2407
  * @param value - The line to write. When omitted, only the endOfLineString is written.
2564
2408
  */
2565
2409
  writeLine(value) {
2566
- if (value)
2567
- this.wroteSomething = true;
2568
2410
  this.writer.writeLine(value);
2569
2411
  return this;
2570
2412
  }
@@ -2574,8 +2416,6 @@ class BitmarkGenerator extends AstWalkerGenerator {
2574
2416
  * @param delimiter - An optional delimiter to be written at the end of each line, except for the last one.
2575
2417
  */
2576
2418
  writeLines(values, delimiter) {
2577
- if (values.length > 0 && values.reduce((acc, v) => (v ? true : acc), false))
2578
- this.wroteSomething = true;
2579
2419
  this.writer.writeLines(values, delimiter);
2580
2420
  return this;
2581
2421
  }