@gmb/bitmark-parser-generator 3.10.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 (105) 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 +40 -0
  10. package/dist/cjs/config/raw/bits.js.map +1 -1
  11. package/dist/cjs/config/raw/cardSets.js +8 -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 +10 -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 +246 -398
  19. package/dist/cjs/generator/bitmark/BitmarkGenerator.js.map +1 -1
  20. package/dist/cjs/generator/json/JsonGenerator.js +9 -6
  21. package/dist/cjs/generator/json/JsonGenerator.js.map +1 -1
  22. package/dist/cjs/model/ast/NodeType.js +3 -0
  23. package/dist/cjs/model/ast/NodeType.js.map +1 -1
  24. package/dist/cjs/model/config/enum/GroupConfigKey.js +1 -0
  25. package/dist/cjs/model/config/enum/GroupConfigKey.js.map +1 -1
  26. package/dist/cjs/model/config/enum/PropertyConfigKey.js +2 -0
  27. package/dist/cjs/model/config/enum/PropertyConfigKey.js.map +1 -1
  28. package/dist/cjs/model/enum/BitType.js +16 -0
  29. package/dist/cjs/model/enum/BitType.js.map +1 -1
  30. package/dist/cjs/model/enum/ResourceTag.js +1 -0
  31. package/dist/cjs/model/enum/ResourceTag.js.map +1 -1
  32. package/dist/cjs/parser/bitmark/peg/BitmarkPegParserTypes.js.map +1 -1
  33. package/dist/cjs/parser/bitmark/peg/contentProcessors/CardContentProcessor.js +26 -16
  34. package/dist/cjs/parser/bitmark/peg/contentProcessors/CardContentProcessor.js.map +1 -1
  35. package/dist/cjs/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.js +5 -0
  36. package/dist/cjs/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.js.map +1 -1
  37. package/dist/esm/ast/BaseBuilder.js +2 -0
  38. package/dist/esm/ast/BaseBuilder.js.map +1 -1
  39. package/dist/esm/ast/Builder.js +32 -3
  40. package/dist/esm/ast/Builder.js.map +1 -1
  41. package/dist/esm/ast/ResourceBuilder.js +1 -0
  42. package/dist/esm/ast/ResourceBuilder.js.map +1 -1
  43. package/dist/esm/config/raw/bits.js +40 -0
  44. package/dist/esm/config/raw/bits.js.map +1 -1
  45. package/dist/esm/config/raw/cardSets.js +8 -0
  46. package/dist/esm/config/raw/cardSets.js.map +1 -1
  47. package/dist/esm/config/raw/groups.js +15 -0
  48. package/dist/esm/config/raw/groups.js.map +1 -1
  49. package/dist/esm/config/raw/properties.js +10 -0
  50. package/dist/esm/config/raw/properties.js.map +1 -1
  51. package/dist/esm/generated/build-info.js +1 -1
  52. package/dist/esm/generator/bitmark/BitmarkGenerator.js +246 -398
  53. package/dist/esm/generator/bitmark/BitmarkGenerator.js.map +1 -1
  54. package/dist/esm/generator/json/JsonGenerator.js +9 -6
  55. package/dist/esm/generator/json/JsonGenerator.js.map +1 -1
  56. package/dist/esm/model/ast/NodeType.js +3 -0
  57. package/dist/esm/model/ast/NodeType.js.map +1 -1
  58. package/dist/esm/model/config/enum/GroupConfigKey.js +1 -0
  59. package/dist/esm/model/config/enum/GroupConfigKey.js.map +1 -1
  60. package/dist/esm/model/config/enum/PropertyConfigKey.js +2 -0
  61. package/dist/esm/model/config/enum/PropertyConfigKey.js.map +1 -1
  62. package/dist/esm/model/enum/BitType.js +16 -0
  63. package/dist/esm/model/enum/BitType.js.map +1 -1
  64. package/dist/esm/model/enum/ResourceTag.js +1 -0
  65. package/dist/esm/model/enum/ResourceTag.js.map +1 -1
  66. package/dist/esm/parser/bitmark/peg/BitmarkPegParserTypes.js.map +1 -1
  67. package/dist/esm/parser/bitmark/peg/contentProcessors/CardContentProcessor.js +26 -16
  68. package/dist/esm/parser/bitmark/peg/contentProcessors/CardContentProcessor.js.map +1 -1
  69. package/dist/esm/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.js +6 -1
  70. package/dist/esm/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.js.map +1 -1
  71. package/dist/types/ast/BaseBuilder.d.ts +2 -0
  72. package/dist/types/ast/BaseBuilder.d.ts.map +1 -1
  73. package/dist/types/ast/Builder.d.ts +4 -1
  74. package/dist/types/ast/Builder.d.ts.map +1 -1
  75. package/dist/types/ast/ResourceBuilder.d.ts.map +1 -1
  76. package/dist/types/config/raw/bits.d.ts.map +1 -1
  77. package/dist/types/config/raw/cardSets.d.ts.map +1 -1
  78. package/dist/types/config/raw/groups.d.ts.map +1 -1
  79. package/dist/types/config/raw/properties.d.ts.map +1 -1
  80. package/dist/types/generator/bitmark/BitmarkGenerator.d.ts +16 -43
  81. package/dist/types/generator/bitmark/BitmarkGenerator.d.ts.map +1 -1
  82. package/dist/types/generator/json/JsonGenerator.d.ts.map +1 -1
  83. package/dist/types/model/ast/NodeType.d.ts +6 -0
  84. package/dist/types/model/ast/NodeType.d.ts.map +1 -1
  85. package/dist/types/model/ast/Nodes.d.ts +2 -0
  86. package/dist/types/model/ast/Nodes.d.ts.map +1 -1
  87. package/dist/types/model/config/enum/ConfigKey.d.ts +6 -0
  88. package/dist/types/model/config/enum/ConfigKey.d.ts.map +1 -1
  89. package/dist/types/model/config/enum/GroupConfigKey.d.ts +3 -0
  90. package/dist/types/model/config/enum/GroupConfigKey.d.ts.map +1 -1
  91. package/dist/types/model/config/enum/PropertyConfigKey.d.ts +6 -0
  92. package/dist/types/model/config/enum/PropertyConfigKey.d.ts.map +1 -1
  93. package/dist/types/model/enum/BitType.d.ts +32 -0
  94. package/dist/types/model/enum/BitType.d.ts.map +1 -1
  95. package/dist/types/model/enum/PropertyTag.d.ts +4 -0
  96. package/dist/types/model/enum/PropertyTag.d.ts.map +1 -1
  97. package/dist/types/model/enum/ResourceTag.d.ts +2 -0
  98. package/dist/types/model/enum/ResourceTag.d.ts.map +1 -1
  99. package/dist/types/model/json/BitJson.d.ts +12 -6
  100. package/dist/types/model/json/BitJson.d.ts.map +1 -1
  101. package/dist/types/parser/bitmark/peg/BitmarkPegParserTypes.d.ts +2 -1
  102. package/dist/types/parser/bitmark/peg/BitmarkPegParserTypes.d.ts.map +1 -1
  103. package/dist/types/parser/bitmark/peg/contentProcessors/CardContentProcessor.d.ts.map +1 -1
  104. package/dist/types/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.d.ts.map +1 -1
  105. 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
- }
907
- }
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
970
  }
917
- // Stop traversal of this branch
918
- return false;
919
971
  }
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,14 +1631,24 @@ 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,
1769
1638
  ignoreEmpty: true,
1770
1639
  });
1771
1640
  }
1641
+ // bitmarkAst -> bits -> bitsValue -> * -> refPublicationYear
1642
+ enter_refPublicationYear(node, _route) {
1643
+ this.writeProperty('refPublicationYear', node.value, {
1644
+ format: PropertyFormat_1.PropertyFormat.trimmedString,
1645
+ single: true,
1646
+ ignoreEmpty: true,
1647
+ });
1648
+ }
1772
1649
  // bitmarkAst -> bits -> bitsValue -> * -> citationStyle
1773
1650
  enter_citationStyle(node, _route) {
1651
+ this.writeNL();
1774
1652
  this.writeProperty('citationStyle', node.value, {
1775
1653
  format: PropertyFormat_1.PropertyFormat.trimmedString,
1776
1654
  single: true,
@@ -1787,6 +1665,8 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1787
1665
  const example = (_a = parent === null || parent === void 0 ? void 0 : parent.value.example) !== null && _a !== void 0 ? _a : null;
1788
1666
  // const __isDefaultExample = parent?.value.__isDefaultExample ?? false;
1789
1667
  if (example != null && example !== '') {
1668
+ // Write a newline if not in a chain
1669
+ this.writeNL_IfNotChain(route);
1790
1670
  this.writeOPA();
1791
1671
  this.writeString('example');
1792
1672
  this.writeColon();
@@ -1816,6 +1696,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1816
1696
  // bitmarkAst -> bits -> bitsValue -> elements -> elementsValue
1817
1697
  leaf_elementsValue(node, _route) {
1818
1698
  if (node.value) {
1699
+ this.writeNL();
1819
1700
  this.writeBreakscapedTagString(node.value);
1820
1701
  }
1821
1702
  }
@@ -1861,18 +1742,21 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1861
1742
  // bitmarkAst -> bits -> bitsValue -> * -> isCorrect
1862
1743
  // bitmarkAst -> bits -> bitsValue -> heading -> forKeys
1863
1744
  leaf_forKeys(node, _route) {
1745
+ this.writeNL();
1864
1746
  this.writeOPHASH();
1865
1747
  this.writeBreakscapedTagString(node.value);
1866
1748
  this.writeCL();
1867
1749
  }
1868
1750
  // bitmarkAst -> bits -> bitsValue -> heading -> forValues
1869
1751
  leaf_forValues(node, _route) {
1752
+ this.writeNL();
1870
1753
  this.writeOPHASH();
1871
1754
  this.writeBreakscapedTagString(node.value);
1872
1755
  this.writeCL();
1873
1756
  }
1874
1757
  // bitmarkAst -> bits -> bitsValue -> heading -> forValuesValue
1875
1758
  leaf_forValuesValue(node, _route) {
1759
+ this.writeNL();
1876
1760
  this.writeOPHASH();
1877
1761
  this.writeBreakscapedTagString(node.value);
1878
1762
  this.writeCL();
@@ -1881,6 +1765,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1881
1765
  // bitmarkAst -> bits -> bitsValue -> matrix -> matrixValue -> key
1882
1766
  leaf_key(node, _route) {
1883
1767
  if (node.value) {
1768
+ this.writeNL();
1884
1769
  this.writeBreakscapedTagString(node.value);
1885
1770
  }
1886
1771
  }
@@ -1888,6 +1773,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1888
1773
  // bitmarkAst -> bits -> bitsValue -> matrix -> matrixValue -> cells -> cellsValue -> values -> valuesValue
1889
1774
  leaf_valuesValue(node, _route) {
1890
1775
  if (node.value) {
1776
+ this.writeNL();
1891
1777
  this.writeBreakscapedTagString(node.value);
1892
1778
  }
1893
1779
  }
@@ -1899,22 +1785,9 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1899
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)
1900
1786
  return;
1901
1787
  if (node.value) {
1788
+ this.writeNL();
1902
1789
  this.writeBreakscapedTagString(node.value);
1903
- // this.writeNL();
1904
- }
1905
- }
1906
- enter_question(node, route) {
1907
- // Ignore responses that are not at the questionsValue level as they are handled elsewhere
1908
- const parent = this.getParentNode(route);
1909
- 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)
1910
- return true;
1911
- if (node.value) {
1912
- this.textGenerator.generateSync(node.value, TextFormat_1.TextFormat.bitmarkMinusMinus);
1913
- // this.writeString(node.value);
1914
- // this.writeNL();
1915
1790
  }
1916
- // Stop traversal of this branch
1917
- return false;
1918
1791
  }
1919
1792
  // bitmarkAst -> bits -> bitsValue -> statements -> text
1920
1793
  // bitmarkAst -> bits -> bitsValue -> resource -> ...
@@ -2020,8 +1893,9 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2020
1893
  ignoreFalse: true,
2021
1894
  });
2022
1895
  }
2023
- enter_caption(node, _route) {
1896
+ enter_caption(node, route) {
2024
1897
  const value = node.value;
1898
+ this.writeNL_IfNotChain(route);
2025
1899
  this.writeProperty('caption', value, {
2026
1900
  format: PropertyFormat_1.PropertyFormat.bitmarkMinusMinus,
2027
1901
  single: true, // ??
@@ -2084,17 +1958,6 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2084
1958
  //
2085
1959
  // Resources
2086
1960
  //
2087
- // bitmarkAst -> bits -> bitsValue -> resources
2088
- between_resources(_node, _left, _right, _route) {
2089
- this.writeNL();
2090
- }
2091
- exit_resources(_node, _left, _right, _route) {
2092
- this.writeNL();
2093
- }
2094
- // bitmarkAst -> bits -> bitsValue -> resourcesValue
2095
- between_resourcesValue(_node, _left, _right, _route) {
2096
- this.writeNL();
2097
- }
2098
1961
  //
2099
1962
  // Generated Node Handlers
2100
1963
  //
@@ -2129,6 +1992,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2129
1992
  // url / src / href / app
2130
1993
  const url = resource.url || resource.src || resource.body || '';
2131
1994
  // Write the resource
1995
+ this.writeNL();
2132
1996
  this.writeResource(type, url);
2133
1997
  // Continue traversal
2134
1998
  return true;
@@ -2141,14 +2005,6 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2141
2005
  /**
2142
2006
  * Generate the handlers for properties, as they are mostly the same, but not quite
2143
2007
  */
2144
- // protected enter_labelTrue(node: NodeInfo, _route: NodeInfo[],
2145
- // ): void {
2146
- // const bit = parent?.value as Bit;
2147
- // if (bit) {
2148
- // this.writeProperty('labelTrue', node.value ?? '', true);
2149
- // this.writeProperty('labelFalse', bit.labelFalse ?? '', true);
2150
- // }
2151
- // }
2152
2008
  generatePropertyHandlers() {
2153
2009
  var _a;
2154
2010
  const propertiesConfig = Config_1.Config.getRawPropertiesConfig();
@@ -2175,6 +2031,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2175
2031
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.bitsValue)
2176
2032
  return;
2177
2033
  // Write the property
2034
+ this.writeNL(); // Only if NOT in chain (how do we know this?)
2178
2035
  this.writeProperty(propertyConfig.tag, node.value, {
2179
2036
  format: (_a = propertyConfig.format) !== null && _a !== void 0 ? _a : PropertyFormat_1.PropertyFormat.trimmedString,
2180
2037
  single: (_b = propertyConfig.single) !== null && _b !== void 0 ? _b : false,
@@ -2187,35 +2044,30 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2187
2044
  this[enterFuncName] = this[enterFuncName].bind(this);
2188
2045
  }
2189
2046
  }
2190
- writeNlBetween(node, left, _right, _route,
2191
- // The following keys are combined with other keys so don't need newlines
2192
- noNlKeys) {
2193
- const bit = node.value;
2194
- if (bit.book) {
2195
- // If the book node exists, remove the newline caused by reference as it will be bound to book
2196
- noNlKeys.push(NodeType_1.NodeType.reference);
2197
- }
2198
- // Check if a no newline key is to the left in this 'between' callback
2199
- const noNl = (() => {
2200
- if (!this.wroteSomething || this.skipNLBetweenBitsValue) {
2201
- return true;
2202
- }
2203
- for (const keyType of noNlKeys) {
2204
- if (left.key === keyType /*|| right.key === keyType*/)
2205
- return true;
2206
- }
2207
- return false;
2208
- })();
2209
- if (!noNl) {
2210
- this.writeNL();
2211
- }
2212
- this.skipNLBetweenBitsValue = false;
2213
- this.wroteSomething = false;
2214
- }
2215
2047
  // END NODE HANDLERS
2216
2048
  //
2217
2049
  // UTILITY FUNCTIONS
2218
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
+ }
2219
2071
  haveValidCardSet(bit) {
2220
2072
  const bitConfig = Config_1.Config.getBitConfig(bit.bitType);
2221
2073
  if (!bitConfig)
@@ -2347,17 +2199,20 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2347
2199
  this.write('#');
2348
2200
  }
2349
2201
  writePlainTextDivider() {
2202
+ this.writeNL();
2350
2203
  this.write('==== text ====');
2351
2204
  }
2352
2205
  writeCardSetStart() {
2206
+ this.writeNL();
2353
2207
  if (this.options.cardSetVersion === CardSetVersion_1.CardSetVersion.v1) {
2354
- this.write('\n===');
2208
+ this.write('===');
2355
2209
  }
2356
2210
  else {
2357
- this.write('\n====');
2211
+ this.write('====');
2358
2212
  }
2359
2213
  }
2360
2214
  writeCardSetEnd() {
2215
+ this.writeNL();
2361
2216
  if (this.options.cardSetVersion === CardSetVersion_1.CardSetVersion.v1) {
2362
2217
  this.write('===');
2363
2218
  }
@@ -2366,6 +2221,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2366
2221
  }
2367
2222
  }
2368
2223
  writeCardSetCardDivider() {
2224
+ this.writeNL();
2369
2225
  if (this.options.cardSetVersion === CardSetVersion_1.CardSetVersion.v1) {
2370
2226
  this.write('===');
2371
2227
  }
@@ -2374,6 +2230,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2374
2230
  }
2375
2231
  }
2376
2232
  writeCardSetSideDivider() {
2233
+ this.writeNL();
2377
2234
  if (this.options.cardSetVersion === CardSetVersion_1.CardSetVersion.v1) {
2378
2235
  this.write('==');
2379
2236
  }
@@ -2382,6 +2239,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2382
2239
  }
2383
2240
  }
2384
2241
  writeCardSetVariantDivider() {
2242
+ this.writeNL();
2385
2243
  if (this.options.cardSetVersion === CardSetVersion_1.CardSetVersion.v1) {
2386
2244
  this.write('--');
2387
2245
  }
@@ -2389,6 +2247,11 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2389
2247
  this.write('++');
2390
2248
  }
2391
2249
  }
2250
+ writeNL_IfNotChain(route) {
2251
+ if (!this.isChain(route)) {
2252
+ this.writeNL();
2253
+ }
2254
+ }
2392
2255
  writeNL() {
2393
2256
  if (this.options.debugGenerationInline) {
2394
2257
  this.write('\\n');
@@ -2408,7 +2271,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2408
2271
  this.writeColon();
2409
2272
  this.writeBreakscapedTagString(src);
2410
2273
  if (resource.type === ResourceTag_1.ResourceTag.article) {
2411
- this.writeNL();
2274
+ // this.writeNL();
2412
2275
  }
2413
2276
  this.writeCL();
2414
2277
  }
@@ -2422,7 +2285,7 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2422
2285
  this.writeColon();
2423
2286
  this.writeBreakscapedTagString(value);
2424
2287
  if (type === ResourceTag_1.ResourceTag.article) {
2425
- this.writeNL();
2288
+ // this.writeNL();
2426
2289
  }
2427
2290
  this.writeCL();
2428
2291
  }
@@ -2430,7 +2293,6 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2430
2293
  writeProperty(name, values, options) {
2431
2294
  var _a;
2432
2295
  let valuesArray;
2433
- let wroteSomething = false;
2434
2296
  if (values !== undefined) {
2435
2297
  const isBitmarkText = options.format === PropertyFormat_1.PropertyFormat.bitmarkMinusMinus || options.format === PropertyFormat_1.PropertyFormat.bitmarkPlusPlus;
2436
2298
  if (isBitmarkText) {
@@ -2442,7 +2304,6 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2442
2304
  this.writeColon();
2443
2305
  this.textGenerator.generateSync(values, (_a = TextFormat_1.TextFormat.fromValue(options.format)) !== null && _a !== void 0 ? _a : TextFormat_1.TextFormat.bitmarkMinusMinus);
2444
2306
  this.writeCL();
2445
- wroteSomething = true;
2446
2307
  }
2447
2308
  else {
2448
2309
  // Write any other property type
@@ -2455,7 +2316,6 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2455
2316
  if (valuesArray.length > 0) {
2456
2317
  if (options.single)
2457
2318
  valuesArray = valuesArray.slice(valuesArray.length - 1);
2458
- let propertyIndex = 0;
2459
2319
  for (const val of valuesArray) {
2460
2320
  if (val !== undefined) {
2461
2321
  if (options.ignoreFalse && val === false)
@@ -2464,23 +2324,17 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2464
2324
  continue;
2465
2325
  if (options.ignoreEmpty && val === '')
2466
2326
  continue;
2467
- if (propertyIndex > 0)
2468
- this.writeNL();
2469
2327
  this.writeOPA();
2470
2328
  this.writeBreakscapedTagString(name);
2471
2329
  this.writeColon();
2472
2330
  this.writeBreakscapedTagString(`${val}`);
2473
2331
  this.writeCL();
2474
- wroteSomething = true;
2475
- propertyIndex++;
2332
+ // propertyIndex++;
2476
2333
  }
2477
2334
  }
2478
2335
  }
2479
2336
  } // isBitmarkText
2480
2337
  }
2481
- if (!wroteSomething) {
2482
- this.skipNLBetweenBitsValue = true;
2483
- }
2484
2338
  }
2485
2339
  writeInlineDebug(key, state) {
2486
2340
  let tag = key;
@@ -2548,8 +2402,6 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2548
2402
  * @param value - The string value to be written.
2549
2403
  */
2550
2404
  write(value) {
2551
- if (value)
2552
- this.wroteSomething = true;
2553
2405
  this.writer.write(value);
2554
2406
  return this;
2555
2407
  }
@@ -2558,8 +2410,6 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2558
2410
  * @param value - The line to write. When omitted, only the endOfLineString is written.
2559
2411
  */
2560
2412
  writeLine(value) {
2561
- if (value)
2562
- this.wroteSomething = true;
2563
2413
  this.writer.writeLine(value);
2564
2414
  return this;
2565
2415
  }
@@ -2569,8 +2419,6 @@ class BitmarkGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2569
2419
  * @param delimiter - An optional delimiter to be written at the end of each line, except for the last one.
2570
2420
  */
2571
2421
  writeLines(values, delimiter) {
2572
- if (values.length > 0 && values.reduce((acc, v) => (v ? true : acc), false))
2573
- this.wroteSomething = true;
2574
2422
  this.writer.writeLines(values, delimiter);
2575
2423
  return this;
2576
2424
  }