@gmb/bitmark-parser-generator 5.20.0 → 5.21.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.
@@ -3515,6 +3515,11 @@ declare abstract class AstWalkerGenerator<AstType, R, Context = undefined> imple
3515
3515
  exit(node: NodeInfo, route: NodeInfo[], context: Context): void;
3516
3516
  leaf(node: NodeInfo, route: NodeInfo[], context: Context): void;
3517
3517
  protected getParentNode(route: NodeInfo[], nodesBack?: number): NodeInfo | undefined;
3518
+ protected getSiblingNodes(route: NodeInfo[]): {
3519
+ left?: unknown;
3520
+ right?: unknown;
3521
+ };
3522
+ protected isEmptyParagraph(node: TextNode): boolean;
3518
3523
  protected abstract writeInlineDebug(key: string, state: {
3519
3524
  open?: boolean;
3520
3525
  close?: boolean;
@@ -3578,7 +3583,6 @@ declare class TextGenerator extends AstWalkerGenerator<TextAst, BreakscapedStrin
3578
3583
  private inParagraph;
3579
3584
  private inHeading;
3580
3585
  private inCodeBlock;
3581
- private exitedCodeBlock;
3582
3586
  private inBulletList;
3583
3587
  private inInline;
3584
3588
  private markDepth;
@@ -3692,7 +3696,7 @@ declare class TextGenerator extends AstWalkerGenerator<TextAst, BreakscapedStrin
3692
3696
  * @param start true if starting (before) the text, false if ending (after) the text
3693
3697
  */
3694
3698
  protected writeMarks(node: TextNode, stage: StageType): void | false;
3695
- protected writeParagraph(node: TextNode): void;
3699
+ protected writeParagraph(node: TextNode, route: NodeInfo[]): void;
3696
3700
  protected writeHardBreak(_node: TextNode): void;
3697
3701
  protected writeHeading(node: HeadingTextNode): void;
3698
3702
  protected writeSection(node: SectionTextNode): void;
@@ -3515,6 +3515,11 @@ declare abstract class AstWalkerGenerator<AstType, R, Context = undefined> imple
3515
3515
  exit(node: NodeInfo, route: NodeInfo[], context: Context): void;
3516
3516
  leaf(node: NodeInfo, route: NodeInfo[], context: Context): void;
3517
3517
  protected getParentNode(route: NodeInfo[], nodesBack?: number): NodeInfo | undefined;
3518
+ protected getSiblingNodes(route: NodeInfo[]): {
3519
+ left?: unknown;
3520
+ right?: unknown;
3521
+ };
3522
+ protected isEmptyParagraph(node: TextNode): boolean;
3518
3523
  protected abstract writeInlineDebug(key: string, state: {
3519
3524
  open?: boolean;
3520
3525
  close?: boolean;
@@ -3578,7 +3583,6 @@ declare class TextGenerator extends AstWalkerGenerator<TextAst, BreakscapedStrin
3578
3583
  private inParagraph;
3579
3584
  private inHeading;
3580
3585
  private inCodeBlock;
3581
- private exitedCodeBlock;
3582
3586
  private inBulletList;
3583
3587
  private inInline;
3584
3588
  private markDepth;
@@ -3692,7 +3696,7 @@ declare class TextGenerator extends AstWalkerGenerator<TextAst, BreakscapedStrin
3692
3696
  * @param start true if starting (before) the text, false if ending (after) the text
3693
3697
  */
3694
3698
  protected writeMarks(node: TextNode, stage: StageType): void | false;
3695
- protected writeParagraph(node: TextNode): void;
3699
+ protected writeParagraph(node: TextNode, route: NodeInfo[]): void;
3696
3700
  protected writeHardBreak(_node: TextNode): void;
3697
3701
  protected writeHeading(node: HeadingTextNode): void;
3698
3702
  protected writeSection(node: SectionTextNode): void;
@@ -11016,7 +11016,7 @@ var instance2 = new Config();
11016
11016
  // src/generated/package_info.ts
11017
11017
  var PACKAGE_INFO = {
11018
11018
  "name": "@gmb/bitmark-parser-generator",
11019
- "version": "5.20.0",
11019
+ "version": "5.21.0",
11020
11020
  "author": "Get More Brain Ltd",
11021
11021
  "license": "ISC",
11022
11022
  "description": "A bitmark parser and generator using Peggy.js"
@@ -12771,6 +12771,31 @@ var AstWalkerGenerator = class {
12771
12771
  }
12772
12772
  return void 0;
12773
12773
  }
12774
+ getSiblingNodes(route) {
12775
+ const parentNode = this.getParentNode(route);
12776
+ if (!parentNode || !parentNode.value || !Array.isArray(parentNode.value)) {
12777
+ return {};
12778
+ }
12779
+ const siblings = parentNode.value;
12780
+ const index = siblings.findIndex((s) => s === route[route.length - 1]?.value);
12781
+ if (index === -1) {
12782
+ return {};
12783
+ }
12784
+ return {
12785
+ left: index > 0 ? siblings[index - 1] : void 0,
12786
+ right: index < siblings.length - 1 ? siblings[index + 1] : void 0
12787
+ };
12788
+ }
12789
+ isEmptyParagraph(node) {
12790
+ if (!node) return false;
12791
+ if (node.type !== TextNodeType.paragraph) return false;
12792
+ if (!node.content || !Array.isArray(node.content)) return true;
12793
+ for (const contentNode of node.content) {
12794
+ if (contentNode.type !== TextNodeType.text) return false;
12795
+ if (contentNode.text && contentNode.text.trim() !== "") return false;
12796
+ }
12797
+ return true;
12798
+ }
12774
12799
  };
12775
12800
 
12776
12801
  // src/generator/text/TextGenerator.ts
@@ -12896,7 +12921,6 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
12896
12921
  __publicField(this, "inParagraph", false);
12897
12922
  __publicField(this, "inHeading", false);
12898
12923
  __publicField(this, "inCodeBlock", false);
12899
- __publicField(this, "exitedCodeBlock", false);
12900
12924
  __publicField(this, "inBulletList", false);
12901
12925
  __publicField(this, "inInline", false);
12902
12926
  __publicField(this, "markDepth", 0);
@@ -12985,7 +13009,6 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
12985
13009
  this.inParagraph = false;
12986
13010
  this.inHeading = false;
12987
13011
  this.inCodeBlock = false;
12988
- this.exitedCodeBlock = false;
12989
13012
  this.inBulletList = false;
12990
13013
  this.inInline = false;
12991
13014
  this.markDepth = 0;
@@ -13051,7 +13074,7 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
13051
13074
  switch (node.type) {
13052
13075
  case TextNodeType.paragraph:
13053
13076
  this.inParagraph = true;
13054
- this.writeParagraph(node);
13077
+ this.writeParagraph(node, route);
13055
13078
  break;
13056
13079
  case TextNodeType.hardBreak:
13057
13080
  this.writeHardBreak(node);
@@ -13108,7 +13131,6 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
13108
13131
  return false;
13109
13132
  default:
13110
13133
  }
13111
- this.exitedCodeBlock = false;
13112
13134
  }
13113
13135
  handleBetweenNode(node, _left, _right, _route) {
13114
13136
  switch (node.type) {
@@ -13142,7 +13164,6 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
13142
13164
  this.writeNL();
13143
13165
  this.writeNL();
13144
13166
  this.inCodeBlock = false;
13145
- this.exitedCodeBlock = true;
13146
13167
  break;
13147
13168
  case TextNodeType.noBulletList:
13148
13169
  case TextNodeType.bulletList:
@@ -13506,21 +13527,19 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
13506
13527
  }
13507
13528
  }
13508
13529
  }
13509
- writeParagraph(node) {
13530
+ writeParagraph(node, route) {
13510
13531
  if (this.textFormat === TextFormat2.bitmarkText) {
13511
13532
  if (this.inBulletList) return;
13512
- const nodeContentLength = node.content?.length ?? 0;
13513
- if (this.nodeIndex === 0) {
13514
- if (nodeContentLength === 1) {
13515
- const isTextNode = node.content?.[0].type === TextNodeType.text;
13516
- const text = node.content?.[0].text ?? "";
13517
- if (!isTextNode || text !== "") return;
13518
- }
13519
- if (nodeContentLength > 1) return;
13533
+ const siblingNodes = this.getSiblingNodes(route);
13534
+ const prevSiblingNodeType = siblingNodes.left?.type;
13535
+ const inBody = this.textLocation === TextLocation2.body;
13536
+ const isEmptyParagraph = this.isEmptyParagraph(node);
13537
+ if (!inBody || !isEmptyParagraph && !(prevSiblingNodeType === TextNodeType.codeBlock || prevSiblingNodeType === TextNodeType.paragraph)) {
13538
+ return;
13520
13539
  }
13521
13540
  this.write("|");
13522
13541
  this.writeNL();
13523
- if (this.exitedCodeBlock) {
13542
+ if (prevSiblingNodeType === TextNodeType.codeBlock) {
13524
13543
  this.writeNL();
13525
13544
  }
13526
13545
  }