@wdprlib/parser 2.0.9 → 2.0.10

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 (3) hide show
  1. package/dist/index.cjs +151 -172
  2. package/dist/index.js +151 -172
  3. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -646,7 +646,139 @@ var BLOCK_START_TOKENS = [
646
646
  "CLEAR_FLOAT_RIGHT"
647
647
  ];
648
648
 
649
+ // packages/parser/src/parser/rules/utils.ts
650
+ var SAFE_ATTRIBUTES = new Set([
651
+ "accept",
652
+ "align",
653
+ "alt",
654
+ "autocapitalize",
655
+ "autoplay",
656
+ "background",
657
+ "bgcolor",
658
+ "border",
659
+ "buffered",
660
+ "checked",
661
+ "cite",
662
+ "class",
663
+ "cols",
664
+ "colspan",
665
+ "contenteditable",
666
+ "controls",
667
+ "coords",
668
+ "datetime",
669
+ "decoding",
670
+ "default",
671
+ "dir",
672
+ "dirname",
673
+ "disabled",
674
+ "download",
675
+ "draggable",
676
+ "for",
677
+ "form",
678
+ "headers",
679
+ "height",
680
+ "hidden",
681
+ "high",
682
+ "href",
683
+ "hreflang",
684
+ "id",
685
+ "inputmode",
686
+ "ismap",
687
+ "itemprop",
688
+ "kind",
689
+ "label",
690
+ "lang",
691
+ "list",
692
+ "loop",
693
+ "low",
694
+ "max",
695
+ "maxlength",
696
+ "min",
697
+ "minlength",
698
+ "multiple",
699
+ "muted",
700
+ "name",
701
+ "optimum",
702
+ "pattern",
703
+ "placeholder",
704
+ "poster",
705
+ "preload",
706
+ "readonly",
707
+ "required",
708
+ "reversed",
709
+ "role",
710
+ "rows",
711
+ "rowspan",
712
+ "scope",
713
+ "selected",
714
+ "shape",
715
+ "size",
716
+ "sizes",
717
+ "span",
718
+ "spellcheck",
719
+ "src",
720
+ "srclang",
721
+ "srcset",
722
+ "start",
723
+ "step",
724
+ "style",
725
+ "tabindex",
726
+ "target",
727
+ "title",
728
+ "translate",
729
+ "type",
730
+ "usemap",
731
+ "value",
732
+ "width",
733
+ "wrap"
734
+ ]);
735
+ function filterUnsafeAttributes(attrs) {
736
+ const result = {};
737
+ for (const [key, value] of Object.entries(attrs)) {
738
+ const lower = key.toLowerCase();
739
+ if (lower.startsWith("on"))
740
+ continue;
741
+ if (lower.startsWith("aria-") || lower.startsWith("data-")) {
742
+ result[key] = value;
743
+ continue;
744
+ }
745
+ if (!SAFE_ATTRIBUTES.has(lower))
746
+ continue;
747
+ if (lower === "id") {
748
+ result[key] = value.startsWith("u-") ? value : `u-${value}`;
749
+ continue;
750
+ }
751
+ result[key] = value;
752
+ }
753
+ return result;
754
+ }
755
+ function parseBlockName(ctx, startPos) {
756
+ let pos = startPos;
757
+ let consumed = 0;
758
+ const token = ctx.tokens[pos];
759
+ if (!token || token.type !== "TEXT" && token.type !== "IDENTIFIER") {
760
+ return null;
761
+ }
762
+ let name = token.value.toLowerCase();
763
+ consumed++;
764
+ pos++;
765
+ if (ctx.tokens[pos]?.type === "UNDERSCORE") {
766
+ name += "_";
767
+ consumed++;
768
+ }
769
+ return { name, consumed };
770
+ }
771
+
649
772
  // packages/parser/src/parser/rules/inline/utils.ts
773
+ function isExcludedBlockToken(ctx, tokenPos) {
774
+ if (!ctx.excludedBlockNames?.size)
775
+ return false;
776
+ const token = ctx.tokens[tokenPos];
777
+ if (token?.type !== "BLOCK_OPEN" && token?.type !== "BLOCK_END_OPEN")
778
+ return false;
779
+ const nameResult = parseBlockName(ctx, tokenPos + 1);
780
+ return nameResult !== null && ctx.excludedBlockNames.has(nameResult.name);
781
+ }
650
782
  function canApplyInlineRule(rule, token) {
651
783
  if (rule.startTokens.length === 0) {
652
784
  return true;
@@ -738,7 +870,8 @@ function parseInlineUntil(ctx, endType) {
738
870
  isInvalidHeading = true;
739
871
  }
740
872
  }
741
- const isBlockStart = nextMeaningfulToken && BLOCK_START_TOKENS.includes(nextMeaningfulToken.type) && nextMeaningfulToken.lineStart && !isOrphanCloseSpan && !isAnchorName && !isInvalidBlockOpen && !isInvalidHeading;
873
+ const isExcludedBlock = (nextMeaningfulToken?.type === "BLOCK_OPEN" || nextMeaningfulToken?.type === "BLOCK_END_OPEN") && isExcludedBlockToken(ctx, pos + lookAhead);
874
+ const isBlockStart = nextMeaningfulToken && BLOCK_START_TOKENS.includes(nextMeaningfulToken.type) && nextMeaningfulToken.lineStart && !isOrphanCloseSpan && !isAnchorName && !isInvalidBlockOpen && !isInvalidHeading && !isExcludedBlock;
742
875
  if (!nextMeaningfulToken || nextMeaningfulToken.type === "NEWLINE" || nextMeaningfulToken.type === "EOF" || isBlockStart) {
743
876
  if (isBlockStart && nodes.length > 0) {
744
877
  const nextPos = pos + lookAhead;
@@ -1076,129 +1209,6 @@ function buildListData(topLtype, list) {
1076
1209
  };
1077
1210
  }
1078
1211
 
1079
- // packages/parser/src/parser/rules/utils.ts
1080
- var SAFE_ATTRIBUTES = new Set([
1081
- "accept",
1082
- "align",
1083
- "alt",
1084
- "autocapitalize",
1085
- "autoplay",
1086
- "background",
1087
- "bgcolor",
1088
- "border",
1089
- "buffered",
1090
- "checked",
1091
- "cite",
1092
- "class",
1093
- "cols",
1094
- "colspan",
1095
- "contenteditable",
1096
- "controls",
1097
- "coords",
1098
- "datetime",
1099
- "decoding",
1100
- "default",
1101
- "dir",
1102
- "dirname",
1103
- "disabled",
1104
- "download",
1105
- "draggable",
1106
- "for",
1107
- "form",
1108
- "headers",
1109
- "height",
1110
- "hidden",
1111
- "high",
1112
- "href",
1113
- "hreflang",
1114
- "id",
1115
- "inputmode",
1116
- "ismap",
1117
- "itemprop",
1118
- "kind",
1119
- "label",
1120
- "lang",
1121
- "list",
1122
- "loop",
1123
- "low",
1124
- "max",
1125
- "maxlength",
1126
- "min",
1127
- "minlength",
1128
- "multiple",
1129
- "muted",
1130
- "name",
1131
- "optimum",
1132
- "pattern",
1133
- "placeholder",
1134
- "poster",
1135
- "preload",
1136
- "readonly",
1137
- "required",
1138
- "reversed",
1139
- "role",
1140
- "rows",
1141
- "rowspan",
1142
- "scope",
1143
- "selected",
1144
- "shape",
1145
- "size",
1146
- "sizes",
1147
- "span",
1148
- "spellcheck",
1149
- "src",
1150
- "srclang",
1151
- "srcset",
1152
- "start",
1153
- "step",
1154
- "style",
1155
- "tabindex",
1156
- "target",
1157
- "title",
1158
- "translate",
1159
- "type",
1160
- "usemap",
1161
- "value",
1162
- "width",
1163
- "wrap"
1164
- ]);
1165
- function filterUnsafeAttributes(attrs) {
1166
- const result = {};
1167
- for (const [key, value] of Object.entries(attrs)) {
1168
- const lower = key.toLowerCase();
1169
- if (lower.startsWith("on"))
1170
- continue;
1171
- if (lower.startsWith("aria-") || lower.startsWith("data-")) {
1172
- result[key] = value;
1173
- continue;
1174
- }
1175
- if (!SAFE_ATTRIBUTES.has(lower))
1176
- continue;
1177
- if (lower === "id") {
1178
- result[key] = value.startsWith("u-") ? value : `u-${value}`;
1179
- continue;
1180
- }
1181
- result[key] = value;
1182
- }
1183
- return result;
1184
- }
1185
- function parseBlockName(ctx, startPos) {
1186
- let pos = startPos;
1187
- let consumed = 0;
1188
- const token = ctx.tokens[pos];
1189
- if (!token || token.type !== "TEXT" && token.type !== "IDENTIFIER") {
1190
- return null;
1191
- }
1192
- let name = token.value.toLowerCase();
1193
- consumed++;
1194
- pos++;
1195
- if (ctx.tokens[pos]?.type === "UNDERSCORE") {
1196
- name += "_";
1197
- consumed++;
1198
- }
1199
- return { name, consumed };
1200
- }
1201
-
1202
1212
  // packages/parser/src/parser/rules/block/utils.ts
1203
1213
  function canApplyBlockRule(rule, token) {
1204
1214
  if (rule.requiresLineStart && !token.lineStart) {
@@ -1209,11 +1219,13 @@ function canApplyBlockRule(rule, token) {
1209
1219
  }
1210
1220
  return rule.startTokens.includes(token.type);
1211
1221
  }
1212
- function parseBlocksUntil(ctx, closeCondition) {
1222
+ function parseBlocksUntil(ctx, closeCondition, options) {
1213
1223
  const elements = [];
1214
1224
  let consumed = 0;
1215
1225
  let pos = ctx.pos;
1216
- const { blockRules, blockFallbackRule } = ctx;
1226
+ const excluded = options?.excludedBlockNames;
1227
+ const blockRules = excluded ? ctx.blockRules.filter((r) => !excluded.has(r.name)) : ctx.blockRules;
1228
+ const { blockFallbackRule } = ctx;
1217
1229
  while (pos < ctx.tokens.length) {
1218
1230
  const token = ctx.tokens[pos];
1219
1231
  if (!token || token.type === "EOF") {
@@ -1234,7 +1246,13 @@ function parseBlocksUntil(ctx, closeCondition) {
1234
1246
  continue;
1235
1247
  }
1236
1248
  let matched = false;
1237
- const blockCtx = { ...ctx, pos, blockCloseCondition: closeCondition };
1249
+ const blockCtx = {
1250
+ ...ctx,
1251
+ pos,
1252
+ blockRules,
1253
+ blockCloseCondition: closeCondition,
1254
+ excludedBlockNames: excluded
1255
+ };
1238
1256
  for (const rule of blockRules) {
1239
1257
  if (canApplyBlockRule(rule, token)) {
1240
1258
  const result = rule.parse(blockCtx);
@@ -2619,44 +2637,7 @@ function consumeCloseTag2(ctx, pos) {
2619
2637
  closeConsumed++;
2620
2638
  return closeConsumed;
2621
2639
  }
2622
- function mergeParagraphs(elements) {
2623
- const result = [];
2624
- let mergedElements = [];
2625
- for (const elem of elements) {
2626
- if (elem.element === "container" && elem.data && typeof elem.data === "object" && "type" in elem.data && elem.data.type === "paragraph") {
2627
- if (mergedElements.length > 0) {
2628
- mergedElements.push({ element: "line-break" });
2629
- }
2630
- if ("elements" in elem.data && Array.isArray(elem.data.elements)) {
2631
- mergedElements.push(...elem.data.elements);
2632
- }
2633
- } else {
2634
- if (mergedElements.length > 0) {
2635
- result.push({
2636
- element: "container",
2637
- data: {
2638
- type: "paragraph",
2639
- attributes: {},
2640
- elements: mergedElements
2641
- }
2642
- });
2643
- mergedElements = [];
2644
- }
2645
- result.push(elem);
2646
- }
2647
- }
2648
- if (mergedElements.length > 0) {
2649
- result.push({
2650
- element: "container",
2651
- data: {
2652
- type: "paragraph",
2653
- attributes: {},
2654
- elements: mergedElements
2655
- }
2656
- });
2657
- }
2658
- return result;
2659
- }
2640
+ var EXCLUDED_BLOCKS = new Set(["collapsible"]);
2660
2641
  var collapsibleRule = {
2661
2642
  name: "collapsible",
2662
2643
  startTokens: ["BLOCK_OPEN"],
@@ -2720,18 +2701,16 @@ var collapsibleRule = {
2720
2701
  bodyElements = [];
2721
2702
  }
2722
2703
  } else {
2723
- const bodyCtx = {
2724
- ...ctx,
2725
- pos,
2726
- blockRules: ctx.blockRules.filter((r) => r.name !== "collapsible")
2727
- };
2704
+ const bodyCtx = { ...ctx, pos };
2728
2705
  const closeCondition = (checkCtx) => {
2729
2706
  return isCollapsibleClose(checkCtx, checkCtx.pos);
2730
2707
  };
2731
- const bodyResult = parseBlocksUntil(bodyCtx, closeCondition);
2708
+ const bodyResult = parseBlocksUntil(bodyCtx, closeCondition, {
2709
+ excludedBlockNames: EXCLUDED_BLOCKS
2710
+ });
2732
2711
  consumed += bodyResult.consumed;
2733
2712
  pos += bodyResult.consumed;
2734
- bodyElements = mergeParagraphs(bodyResult.elements);
2713
+ bodyElements = bodyResult.elements;
2735
2714
  }
2736
2715
  if (!isCollapsibleClose(ctx, pos)) {
2737
2716
  ctx.diagnostics.push({
package/dist/index.js CHANGED
@@ -591,7 +591,139 @@ var BLOCK_START_TOKENS = [
591
591
  "CLEAR_FLOAT_RIGHT"
592
592
  ];
593
593
 
594
+ // packages/parser/src/parser/rules/utils.ts
595
+ var SAFE_ATTRIBUTES = new Set([
596
+ "accept",
597
+ "align",
598
+ "alt",
599
+ "autocapitalize",
600
+ "autoplay",
601
+ "background",
602
+ "bgcolor",
603
+ "border",
604
+ "buffered",
605
+ "checked",
606
+ "cite",
607
+ "class",
608
+ "cols",
609
+ "colspan",
610
+ "contenteditable",
611
+ "controls",
612
+ "coords",
613
+ "datetime",
614
+ "decoding",
615
+ "default",
616
+ "dir",
617
+ "dirname",
618
+ "disabled",
619
+ "download",
620
+ "draggable",
621
+ "for",
622
+ "form",
623
+ "headers",
624
+ "height",
625
+ "hidden",
626
+ "high",
627
+ "href",
628
+ "hreflang",
629
+ "id",
630
+ "inputmode",
631
+ "ismap",
632
+ "itemprop",
633
+ "kind",
634
+ "label",
635
+ "lang",
636
+ "list",
637
+ "loop",
638
+ "low",
639
+ "max",
640
+ "maxlength",
641
+ "min",
642
+ "minlength",
643
+ "multiple",
644
+ "muted",
645
+ "name",
646
+ "optimum",
647
+ "pattern",
648
+ "placeholder",
649
+ "poster",
650
+ "preload",
651
+ "readonly",
652
+ "required",
653
+ "reversed",
654
+ "role",
655
+ "rows",
656
+ "rowspan",
657
+ "scope",
658
+ "selected",
659
+ "shape",
660
+ "size",
661
+ "sizes",
662
+ "span",
663
+ "spellcheck",
664
+ "src",
665
+ "srclang",
666
+ "srcset",
667
+ "start",
668
+ "step",
669
+ "style",
670
+ "tabindex",
671
+ "target",
672
+ "title",
673
+ "translate",
674
+ "type",
675
+ "usemap",
676
+ "value",
677
+ "width",
678
+ "wrap"
679
+ ]);
680
+ function filterUnsafeAttributes(attrs) {
681
+ const result = {};
682
+ for (const [key, value] of Object.entries(attrs)) {
683
+ const lower = key.toLowerCase();
684
+ if (lower.startsWith("on"))
685
+ continue;
686
+ if (lower.startsWith("aria-") || lower.startsWith("data-")) {
687
+ result[key] = value;
688
+ continue;
689
+ }
690
+ if (!SAFE_ATTRIBUTES.has(lower))
691
+ continue;
692
+ if (lower === "id") {
693
+ result[key] = value.startsWith("u-") ? value : `u-${value}`;
694
+ continue;
695
+ }
696
+ result[key] = value;
697
+ }
698
+ return result;
699
+ }
700
+ function parseBlockName(ctx, startPos) {
701
+ let pos = startPos;
702
+ let consumed = 0;
703
+ const token = ctx.tokens[pos];
704
+ if (!token || token.type !== "TEXT" && token.type !== "IDENTIFIER") {
705
+ return null;
706
+ }
707
+ let name = token.value.toLowerCase();
708
+ consumed++;
709
+ pos++;
710
+ if (ctx.tokens[pos]?.type === "UNDERSCORE") {
711
+ name += "_";
712
+ consumed++;
713
+ }
714
+ return { name, consumed };
715
+ }
716
+
594
717
  // packages/parser/src/parser/rules/inline/utils.ts
718
+ function isExcludedBlockToken(ctx, tokenPos) {
719
+ if (!ctx.excludedBlockNames?.size)
720
+ return false;
721
+ const token = ctx.tokens[tokenPos];
722
+ if (token?.type !== "BLOCK_OPEN" && token?.type !== "BLOCK_END_OPEN")
723
+ return false;
724
+ const nameResult = parseBlockName(ctx, tokenPos + 1);
725
+ return nameResult !== null && ctx.excludedBlockNames.has(nameResult.name);
726
+ }
595
727
  function canApplyInlineRule(rule, token) {
596
728
  if (rule.startTokens.length === 0) {
597
729
  return true;
@@ -683,7 +815,8 @@ function parseInlineUntil(ctx, endType) {
683
815
  isInvalidHeading = true;
684
816
  }
685
817
  }
686
- const isBlockStart = nextMeaningfulToken && BLOCK_START_TOKENS.includes(nextMeaningfulToken.type) && nextMeaningfulToken.lineStart && !isOrphanCloseSpan && !isAnchorName && !isInvalidBlockOpen && !isInvalidHeading;
818
+ 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;
687
820
  if (!nextMeaningfulToken || nextMeaningfulToken.type === "NEWLINE" || nextMeaningfulToken.type === "EOF" || isBlockStart) {
688
821
  if (isBlockStart && nodes.length > 0) {
689
822
  const nextPos = pos + lookAhead;
@@ -1021,129 +1154,6 @@ function buildListData(topLtype, list) {
1021
1154
  };
1022
1155
  }
1023
1156
 
1024
- // packages/parser/src/parser/rules/utils.ts
1025
- var SAFE_ATTRIBUTES = new Set([
1026
- "accept",
1027
- "align",
1028
- "alt",
1029
- "autocapitalize",
1030
- "autoplay",
1031
- "background",
1032
- "bgcolor",
1033
- "border",
1034
- "buffered",
1035
- "checked",
1036
- "cite",
1037
- "class",
1038
- "cols",
1039
- "colspan",
1040
- "contenteditable",
1041
- "controls",
1042
- "coords",
1043
- "datetime",
1044
- "decoding",
1045
- "default",
1046
- "dir",
1047
- "dirname",
1048
- "disabled",
1049
- "download",
1050
- "draggable",
1051
- "for",
1052
- "form",
1053
- "headers",
1054
- "height",
1055
- "hidden",
1056
- "high",
1057
- "href",
1058
- "hreflang",
1059
- "id",
1060
- "inputmode",
1061
- "ismap",
1062
- "itemprop",
1063
- "kind",
1064
- "label",
1065
- "lang",
1066
- "list",
1067
- "loop",
1068
- "low",
1069
- "max",
1070
- "maxlength",
1071
- "min",
1072
- "minlength",
1073
- "multiple",
1074
- "muted",
1075
- "name",
1076
- "optimum",
1077
- "pattern",
1078
- "placeholder",
1079
- "poster",
1080
- "preload",
1081
- "readonly",
1082
- "required",
1083
- "reversed",
1084
- "role",
1085
- "rows",
1086
- "rowspan",
1087
- "scope",
1088
- "selected",
1089
- "shape",
1090
- "size",
1091
- "sizes",
1092
- "span",
1093
- "spellcheck",
1094
- "src",
1095
- "srclang",
1096
- "srcset",
1097
- "start",
1098
- "step",
1099
- "style",
1100
- "tabindex",
1101
- "target",
1102
- "title",
1103
- "translate",
1104
- "type",
1105
- "usemap",
1106
- "value",
1107
- "width",
1108
- "wrap"
1109
- ]);
1110
- function filterUnsafeAttributes(attrs) {
1111
- const result = {};
1112
- for (const [key, value] of Object.entries(attrs)) {
1113
- const lower = key.toLowerCase();
1114
- if (lower.startsWith("on"))
1115
- continue;
1116
- if (lower.startsWith("aria-") || lower.startsWith("data-")) {
1117
- result[key] = value;
1118
- continue;
1119
- }
1120
- if (!SAFE_ATTRIBUTES.has(lower))
1121
- continue;
1122
- if (lower === "id") {
1123
- result[key] = value.startsWith("u-") ? value : `u-${value}`;
1124
- continue;
1125
- }
1126
- result[key] = value;
1127
- }
1128
- return result;
1129
- }
1130
- function parseBlockName(ctx, startPos) {
1131
- let pos = startPos;
1132
- let consumed = 0;
1133
- const token = ctx.tokens[pos];
1134
- if (!token || token.type !== "TEXT" && token.type !== "IDENTIFIER") {
1135
- return null;
1136
- }
1137
- let name = token.value.toLowerCase();
1138
- consumed++;
1139
- pos++;
1140
- if (ctx.tokens[pos]?.type === "UNDERSCORE") {
1141
- name += "_";
1142
- consumed++;
1143
- }
1144
- return { name, consumed };
1145
- }
1146
-
1147
1157
  // packages/parser/src/parser/rules/block/utils.ts
1148
1158
  function canApplyBlockRule(rule, token) {
1149
1159
  if (rule.requiresLineStart && !token.lineStart) {
@@ -1154,11 +1164,13 @@ function canApplyBlockRule(rule, token) {
1154
1164
  }
1155
1165
  return rule.startTokens.includes(token.type);
1156
1166
  }
1157
- function parseBlocksUntil(ctx, closeCondition) {
1167
+ function parseBlocksUntil(ctx, closeCondition, options) {
1158
1168
  const elements = [];
1159
1169
  let consumed = 0;
1160
1170
  let pos = ctx.pos;
1161
- const { blockRules, blockFallbackRule } = ctx;
1171
+ const excluded = options?.excludedBlockNames;
1172
+ const blockRules = excluded ? ctx.blockRules.filter((r) => !excluded.has(r.name)) : ctx.blockRules;
1173
+ const { blockFallbackRule } = ctx;
1162
1174
  while (pos < ctx.tokens.length) {
1163
1175
  const token = ctx.tokens[pos];
1164
1176
  if (!token || token.type === "EOF") {
@@ -1179,7 +1191,13 @@ function parseBlocksUntil(ctx, closeCondition) {
1179
1191
  continue;
1180
1192
  }
1181
1193
  let matched = false;
1182
- const blockCtx = { ...ctx, pos, blockCloseCondition: closeCondition };
1194
+ const blockCtx = {
1195
+ ...ctx,
1196
+ pos,
1197
+ blockRules,
1198
+ blockCloseCondition: closeCondition,
1199
+ excludedBlockNames: excluded
1200
+ };
1183
1201
  for (const rule of blockRules) {
1184
1202
  if (canApplyBlockRule(rule, token)) {
1185
1203
  const result = rule.parse(blockCtx);
@@ -2564,44 +2582,7 @@ function consumeCloseTag2(ctx, pos) {
2564
2582
  closeConsumed++;
2565
2583
  return closeConsumed;
2566
2584
  }
2567
- function mergeParagraphs(elements) {
2568
- const result = [];
2569
- let mergedElements = [];
2570
- for (const elem of elements) {
2571
- if (elem.element === "container" && elem.data && typeof elem.data === "object" && "type" in elem.data && elem.data.type === "paragraph") {
2572
- if (mergedElements.length > 0) {
2573
- mergedElements.push({ element: "line-break" });
2574
- }
2575
- if ("elements" in elem.data && Array.isArray(elem.data.elements)) {
2576
- mergedElements.push(...elem.data.elements);
2577
- }
2578
- } else {
2579
- if (mergedElements.length > 0) {
2580
- result.push({
2581
- element: "container",
2582
- data: {
2583
- type: "paragraph",
2584
- attributes: {},
2585
- elements: mergedElements
2586
- }
2587
- });
2588
- mergedElements = [];
2589
- }
2590
- result.push(elem);
2591
- }
2592
- }
2593
- if (mergedElements.length > 0) {
2594
- result.push({
2595
- element: "container",
2596
- data: {
2597
- type: "paragraph",
2598
- attributes: {},
2599
- elements: mergedElements
2600
- }
2601
- });
2602
- }
2603
- return result;
2604
- }
2585
+ var EXCLUDED_BLOCKS = new Set(["collapsible"]);
2605
2586
  var collapsibleRule = {
2606
2587
  name: "collapsible",
2607
2588
  startTokens: ["BLOCK_OPEN"],
@@ -2665,18 +2646,16 @@ var collapsibleRule = {
2665
2646
  bodyElements = [];
2666
2647
  }
2667
2648
  } else {
2668
- const bodyCtx = {
2669
- ...ctx,
2670
- pos,
2671
- blockRules: ctx.blockRules.filter((r) => r.name !== "collapsible")
2672
- };
2649
+ const bodyCtx = { ...ctx, pos };
2673
2650
  const closeCondition = (checkCtx) => {
2674
2651
  return isCollapsibleClose(checkCtx, checkCtx.pos);
2675
2652
  };
2676
- const bodyResult = parseBlocksUntil(bodyCtx, closeCondition);
2653
+ const bodyResult = parseBlocksUntil(bodyCtx, closeCondition, {
2654
+ excludedBlockNames: EXCLUDED_BLOCKS
2655
+ });
2677
2656
  consumed += bodyResult.consumed;
2678
2657
  pos += bodyResult.consumed;
2679
- bodyElements = mergeParagraphs(bodyResult.elements);
2658
+ bodyElements = bodyResult.elements;
2680
2659
  }
2681
2660
  if (!isCollapsibleClose(ctx, pos)) {
2682
2661
  ctx.diagnostics.push({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wdprlib/parser",
3
- "version": "2.0.9",
3
+ "version": "2.0.10",
4
4
  "description": "Parser for Wikidot markup",
5
5
  "keywords": [
6
6
  "ast",