@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.
package/dist/cli/main.js CHANGED
@@ -10972,7 +10972,7 @@ var instance2 = new Config();
10972
10972
  // src/generated/package_info.ts
10973
10973
  var PACKAGE_INFO = {
10974
10974
  "name": "@gmb/bitmark-parser-generator",
10975
- "version": "5.20.0",
10975
+ "version": "5.21.0",
10976
10976
  "license": "ISC"};
10977
10977
  var Environment = {
10978
10978
  unknown: "",
@@ -12671,6 +12671,31 @@ var AstWalkerGenerator = class {
12671
12671
  }
12672
12672
  return void 0;
12673
12673
  }
12674
+ getSiblingNodes(route) {
12675
+ const parentNode = this.getParentNode(route);
12676
+ if (!parentNode || !parentNode.value || !Array.isArray(parentNode.value)) {
12677
+ return {};
12678
+ }
12679
+ const siblings = parentNode.value;
12680
+ const index = siblings.findIndex((s) => s === route[route.length - 1]?.value);
12681
+ if (index === -1) {
12682
+ return {};
12683
+ }
12684
+ return {
12685
+ left: index > 0 ? siblings[index - 1] : void 0,
12686
+ right: index < siblings.length - 1 ? siblings[index + 1] : void 0
12687
+ };
12688
+ }
12689
+ isEmptyParagraph(node) {
12690
+ if (!node) return false;
12691
+ if (node.type !== TextNodeType.paragraph) return false;
12692
+ if (!node.content || !Array.isArray(node.content)) return true;
12693
+ for (const contentNode of node.content) {
12694
+ if (contentNode.type !== TextNodeType.text) return false;
12695
+ if (contentNode.text && contentNode.text.trim() !== "") return false;
12696
+ }
12697
+ return true;
12698
+ }
12674
12699
  };
12675
12700
 
12676
12701
  // src/generator/text/TextGenerator.ts
@@ -12788,7 +12813,6 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
12788
12813
  inParagraph = false;
12789
12814
  inHeading = false;
12790
12815
  inCodeBlock = false;
12791
- exitedCodeBlock = false;
12792
12816
  inBulletList = false;
12793
12817
  inInline = false;
12794
12818
  markDepth = 0;
@@ -12883,7 +12907,6 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
12883
12907
  this.inParagraph = false;
12884
12908
  this.inHeading = false;
12885
12909
  this.inCodeBlock = false;
12886
- this.exitedCodeBlock = false;
12887
12910
  this.inBulletList = false;
12888
12911
  this.inInline = false;
12889
12912
  this.markDepth = 0;
@@ -12949,7 +12972,7 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
12949
12972
  switch (node.type) {
12950
12973
  case TextNodeType.paragraph:
12951
12974
  this.inParagraph = true;
12952
- this.writeParagraph(node);
12975
+ this.writeParagraph(node, route);
12953
12976
  break;
12954
12977
  case TextNodeType.hardBreak:
12955
12978
  this.writeHardBreak(node);
@@ -13005,7 +13028,6 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
13005
13028
  this.writeBodyBit(node, route);
13006
13029
  return false;
13007
13030
  }
13008
- this.exitedCodeBlock = false;
13009
13031
  }
13010
13032
  handleBetweenNode(node, _left, _right, _route) {
13011
13033
  switch (node.type) {
@@ -13038,7 +13060,6 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
13038
13060
  this.writeNL();
13039
13061
  this.writeNL();
13040
13062
  this.inCodeBlock = false;
13041
- this.exitedCodeBlock = true;
13042
13063
  break;
13043
13064
  case TextNodeType.noBulletList:
13044
13065
  case TextNodeType.bulletList:
@@ -13396,21 +13417,19 @@ var TextGenerator = class _TextGenerator extends AstWalkerGenerator {
13396
13417
  }
13397
13418
  }
13398
13419
  }
13399
- writeParagraph(node) {
13420
+ writeParagraph(node, route) {
13400
13421
  if (this.textFormat === TextFormat.bitmarkText) {
13401
13422
  if (this.inBulletList) return;
13402
- const nodeContentLength = node.content?.length ?? 0;
13403
- if (this.nodeIndex === 0) {
13404
- if (nodeContentLength === 1) {
13405
- const isTextNode = node.content?.[0].type === TextNodeType.text;
13406
- const text = node.content?.[0].text ?? "";
13407
- if (!isTextNode || text !== "") return;
13408
- }
13409
- if (nodeContentLength > 1) return;
13423
+ const siblingNodes = this.getSiblingNodes(route);
13424
+ const prevSiblingNodeType = siblingNodes.left?.type;
13425
+ const inBody = this.textLocation === TextLocation.body;
13426
+ const isEmptyParagraph = this.isEmptyParagraph(node);
13427
+ if (!inBody || !isEmptyParagraph && !(prevSiblingNodeType === TextNodeType.codeBlock || prevSiblingNodeType === TextNodeType.paragraph)) {
13428
+ return;
13410
13429
  }
13411
13430
  this.write("|");
13412
13431
  this.writeNL();
13413
- if (this.exitedCodeBlock) {
13432
+ if (prevSiblingNodeType === TextNodeType.codeBlock) {
13414
13433
  this.writeNL();
13415
13434
  }
13416
13435
  }