@wdprlib/parser 2.1.0 → 2.2.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/index.cjs CHANGED
@@ -646,6 +646,51 @@ var BLOCK_START_TOKENS = [
646
646
  "CLEAR_FLOAT_LEFT",
647
647
  "CLEAR_FLOAT_RIGHT"
648
648
  ];
649
+ var KNOWN_BLOCK_NAMES = new Set([
650
+ "collapsible",
651
+ "div",
652
+ "div_",
653
+ "code",
654
+ "ul",
655
+ "ol",
656
+ "li",
657
+ "table",
658
+ "row",
659
+ "cell",
660
+ "hcell",
661
+ "tabview",
662
+ "tabs",
663
+ "module",
664
+ "module654",
665
+ "bibliography",
666
+ "footnoteblock",
667
+ "toc",
668
+ "iframe",
669
+ "math",
670
+ "html",
671
+ "iftags",
672
+ "include",
673
+ "f",
674
+ "embed",
675
+ "embedvideo",
676
+ "embedaudio",
677
+ "<",
678
+ ">",
679
+ "=",
680
+ "==",
681
+ "span",
682
+ "span_",
683
+ "user",
684
+ "a",
685
+ "anchor",
686
+ "size",
687
+ "footnote",
688
+ "eref",
689
+ "$",
690
+ "image",
691
+ "gallery",
692
+ "file"
693
+ ]);
649
694
 
650
695
  // packages/parser/src/parser/rules/utils.ts
651
696
  var SAFE_ATTRIBUTES = new Set([
@@ -780,6 +825,19 @@ function isExcludedBlockToken(ctx, tokenPos) {
780
825
  const nameResult = parseBlockName(ctx, tokenPos + 1);
781
826
  return nameResult !== null && ctx.excludedBlockNames.has(nameResult.name);
782
827
  }
828
+ function isUnknownBlockToken(ctx, tokenPos) {
829
+ const token = ctx.tokens[tokenPos];
830
+ if (token?.type !== "BLOCK_OPEN" && token?.type !== "BLOCK_END_OPEN")
831
+ return false;
832
+ const nameResult = parseBlockName(ctx, tokenPos + 1);
833
+ if (nameResult === null) {
834
+ if (ctx.tokens[tokenPos + 1]?.type === "EQUALS") {
835
+ return false;
836
+ }
837
+ return true;
838
+ }
839
+ return !KNOWN_BLOCK_NAMES.has(nameResult.name);
840
+ }
783
841
  function canApplyInlineRule(rule, token) {
784
842
  if (rule.startTokens.length === 0) {
785
843
  return true;
@@ -872,7 +930,8 @@ function parseInlineUntil(ctx, endType) {
872
930
  }
873
931
  }
874
932
  const isExcludedBlock = (nextMeaningfulToken?.type === "BLOCK_OPEN" || nextMeaningfulToken?.type === "BLOCK_END_OPEN") && isExcludedBlockToken(ctx, pos + lookAhead);
875
- const isBlockStart = nextMeaningfulToken && BLOCK_START_TOKENS.includes(nextMeaningfulToken.type) && nextMeaningfulToken.lineStart && !isOrphanCloseSpan && !isAnchorName && !isInvalidBlockOpen && !isInvalidHeading && !isExcludedBlock;
933
+ const isUnknownBlock = (nextMeaningfulToken?.type === "BLOCK_OPEN" || nextMeaningfulToken?.type === "BLOCK_END_OPEN") && isUnknownBlockToken(ctx, pos + lookAhead);
934
+ const isBlockStart = nextMeaningfulToken && BLOCK_START_TOKENS.includes(nextMeaningfulToken.type) && nextMeaningfulToken.lineStart && !isOrphanCloseSpan && !isAnchorName && !isInvalidBlockOpen && !isInvalidHeading && !isExcludedBlock && !isUnknownBlock;
876
935
  if (!nextMeaningfulToken || nextMeaningfulToken.type === "NEWLINE" || nextMeaningfulToken.type === "EOF" || isBlockStart) {
877
936
  if (isBlockStart && nodes.length > 0) {
878
937
  const nextPos = pos + lookAhead;
@@ -1209,7 +1268,6 @@ function buildListData(topLtype, list) {
1209
1268
  items
1210
1269
  };
1211
1270
  }
1212
-
1213
1271
  // packages/parser/src/parser/rules/block/utils.ts
1214
1272
  function canApplyBlockRule(rule, token) {
1215
1273
  if (rule.requiresLineStart && !token.lineStart) {
package/dist/index.js CHANGED
@@ -590,6 +590,51 @@ var BLOCK_START_TOKENS = [
590
590
  "CLEAR_FLOAT_LEFT",
591
591
  "CLEAR_FLOAT_RIGHT"
592
592
  ];
593
+ var KNOWN_BLOCK_NAMES = new Set([
594
+ "collapsible",
595
+ "div",
596
+ "div_",
597
+ "code",
598
+ "ul",
599
+ "ol",
600
+ "li",
601
+ "table",
602
+ "row",
603
+ "cell",
604
+ "hcell",
605
+ "tabview",
606
+ "tabs",
607
+ "module",
608
+ "module654",
609
+ "bibliography",
610
+ "footnoteblock",
611
+ "toc",
612
+ "iframe",
613
+ "math",
614
+ "html",
615
+ "iftags",
616
+ "include",
617
+ "f",
618
+ "embed",
619
+ "embedvideo",
620
+ "embedaudio",
621
+ "<",
622
+ ">",
623
+ "=",
624
+ "==",
625
+ "span",
626
+ "span_",
627
+ "user",
628
+ "a",
629
+ "anchor",
630
+ "size",
631
+ "footnote",
632
+ "eref",
633
+ "$",
634
+ "image",
635
+ "gallery",
636
+ "file"
637
+ ]);
593
638
 
594
639
  // packages/parser/src/parser/rules/utils.ts
595
640
  var SAFE_ATTRIBUTES = new Set([
@@ -724,6 +769,19 @@ function isExcludedBlockToken(ctx, tokenPos) {
724
769
  const nameResult = parseBlockName(ctx, tokenPos + 1);
725
770
  return nameResult !== null && ctx.excludedBlockNames.has(nameResult.name);
726
771
  }
772
+ function isUnknownBlockToken(ctx, tokenPos) {
773
+ const token = ctx.tokens[tokenPos];
774
+ if (token?.type !== "BLOCK_OPEN" && token?.type !== "BLOCK_END_OPEN")
775
+ return false;
776
+ const nameResult = parseBlockName(ctx, tokenPos + 1);
777
+ if (nameResult === null) {
778
+ if (ctx.tokens[tokenPos + 1]?.type === "EQUALS") {
779
+ return false;
780
+ }
781
+ return true;
782
+ }
783
+ return !KNOWN_BLOCK_NAMES.has(nameResult.name);
784
+ }
727
785
  function canApplyInlineRule(rule, token) {
728
786
  if (rule.startTokens.length === 0) {
729
787
  return true;
@@ -816,7 +874,8 @@ function parseInlineUntil(ctx, endType) {
816
874
  }
817
875
  }
818
876
  const isExcludedBlock = (nextMeaningfulToken?.type === "BLOCK_OPEN" || nextMeaningfulToken?.type === "BLOCK_END_OPEN") && isExcludedBlockToken(ctx, pos + lookAhead);
819
- const isBlockStart = nextMeaningfulToken && BLOCK_START_TOKENS.includes(nextMeaningfulToken.type) && nextMeaningfulToken.lineStart && !isOrphanCloseSpan && !isAnchorName && !isInvalidBlockOpen && !isInvalidHeading && !isExcludedBlock;
877
+ const isUnknownBlock = (nextMeaningfulToken?.type === "BLOCK_OPEN" || nextMeaningfulToken?.type === "BLOCK_END_OPEN") && isUnknownBlockToken(ctx, pos + lookAhead);
878
+ const isBlockStart = nextMeaningfulToken && BLOCK_START_TOKENS.includes(nextMeaningfulToken.type) && nextMeaningfulToken.lineStart && !isOrphanCloseSpan && !isAnchorName && !isInvalidBlockOpen && !isInvalidHeading && !isExcludedBlock && !isUnknownBlock;
820
879
  if (!nextMeaningfulToken || nextMeaningfulToken.type === "NEWLINE" || nextMeaningfulToken.type === "EOF" || isBlockStart) {
821
880
  if (isBlockStart && nodes.length > 0) {
822
881
  const nextPos = pos + lookAhead;
@@ -1153,7 +1212,6 @@ function buildListData(topLtype, list) {
1153
1212
  items
1154
1213
  };
1155
1214
  }
1156
-
1157
1215
  // packages/parser/src/parser/rules/block/utils.ts
1158
1216
  function canApplyBlockRule(rule, token) {
1159
1217
  if (rule.requiresLineStart && !token.lineStart) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wdprlib/parser",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "Parser for Wikidot markup",
5
5
  "keywords": [
6
6
  "ast",