@wdprlib/parser 1.0.0 → 1.1.1

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
@@ -31,7 +31,7 @@ var __export = (target, all) => {
31
31
  var exports_src = {};
32
32
  __export(exports_src, {
33
33
  tokenize: () => tokenize,
34
- text: () => import_ast2.text,
34
+ text: () => import_ast3.text,
35
35
  resolveModules: () => resolveModules,
36
36
  resolveListUsers: () => resolveListUsers,
37
37
  resolveIncludes: () => resolveIncludes,
@@ -42,31 +42,34 @@ __export(exports_src, {
42
42
  parseDateSelector: () => parseDateSelector,
43
43
  parseCategory: () => parseCategory,
44
44
  parse: () => parse,
45
- paragraph: () => import_ast2.paragraph,
45
+ paragraph: () => import_ast3.paragraph,
46
46
  normalizeQuery: () => normalizeQuery,
47
- listItemSubList: () => import_ast2.listItemSubList,
48
- listItemElements: () => import_ast2.listItemElements,
49
- list: () => import_ast2.list,
50
- link: () => import_ast2.link,
51
- lineBreak: () => import_ast2.lineBreak,
52
- italics: () => import_ast2.italics,
47
+ listItemSubList: () => import_ast3.listItemSubList,
48
+ listItemElements: () => import_ast3.listItemElements,
49
+ list: () => import_ast3.list,
50
+ link: () => import_ast3.link,
51
+ lineBreak: () => import_ast3.lineBreak,
52
+ italics: () => import_ast3.italics,
53
53
  isListUsersModule: () => isListUsersModule2,
54
- horizontalRule: () => import_ast2.horizontalRule,
55
- heading: () => import_ast2.heading,
54
+ horizontalRule: () => import_ast3.horizontalRule,
55
+ heading: () => import_ast3.heading,
56
56
  extractListUsersVariables: () => extractListUsersVariables,
57
57
  extractDataRequirements: () => extractDataRequirements,
58
58
  createToken: () => createToken,
59
- createPosition: () => import_ast2.createPosition,
60
- createPoint: () => import_ast2.createPoint,
61
- container: () => import_ast2.container,
59
+ createSettings: () => import_ast4.createSettings,
60
+ createPosition: () => import_ast3.createPosition,
61
+ createPoint: () => import_ast3.createPoint,
62
+ container: () => import_ast3.container,
62
63
  compileTemplate: () => compileTemplate,
63
64
  compileListUsersTemplate: () => compileListUsersTemplate,
64
- bold: () => import_ast2.bold,
65
+ bold: () => import_ast3.bold,
65
66
  Parser: () => Parser,
66
- Lexer: () => Lexer
67
+ Lexer: () => Lexer,
68
+ DEFAULT_SETTINGS: () => import_ast4.DEFAULT_SETTINGS
67
69
  });
68
70
  module.exports = __toCommonJS(exports_src);
69
- var import_ast2 = require("@wdprlib/ast");
71
+ var import_ast3 = require("@wdprlib/ast");
72
+ var import_ast4 = require("@wdprlib/ast");
70
73
 
71
74
  // packages/parser/src/lexer/tokens.ts
72
75
  function createToken(type, value, position, lineStart = false) {
@@ -555,6 +558,9 @@ function preprocess(text) {
555
558
  return result;
556
559
  }
557
560
 
561
+ // packages/parser/src/parser/parse.ts
562
+ var import_ast2 = require("@wdprlib/ast");
563
+
558
564
  // packages/parser/src/parser/rules/types.ts
559
565
  function currentToken(ctx) {
560
566
  return ctx.tokens[ctx.pos] ?? eofToken();
@@ -3559,6 +3565,9 @@ var moduleRule = {
3559
3565
  if (!nameResult || nameResult.name !== "module" && nameResult.name !== "module654") {
3560
3566
  return { success: false };
3561
3567
  }
3568
+ if (!ctx.settings.enablePageSyntax) {
3569
+ return { success: false };
3570
+ }
3562
3571
  pos += nameResult.consumed;
3563
3572
  consumed += nameResult.consumed;
3564
3573
  while (ctx.tokens[pos]?.type === "WHITESPACE") {
@@ -4273,6 +4282,9 @@ var includeRule = {
4273
4282
  if (!nameResult || nameResult.name.toLowerCase() !== "include") {
4274
4283
  return { success: false };
4275
4284
  }
4285
+ if (!ctx.settings.enablePageSyntax) {
4286
+ return { success: false };
4287
+ }
4276
4288
  pos += nameResult.consumed;
4277
4289
  consumed += nameResult.consumed;
4278
4290
  while (ctx.tokens[pos]?.type === "WHITESPACE") {
@@ -4880,6 +4892,9 @@ var tocRule = {
4880
4892
  }
4881
4893
  const firstValue = firstToken.value.toLowerCase();
4882
4894
  if (firstValue === "toc") {
4895
+ if (!ctx.settings.enablePageSyntax) {
4896
+ return { success: false };
4897
+ }
4883
4898
  pos++;
4884
4899
  } else if (firstValue === "f") {
4885
4900
  pos++;
@@ -4903,6 +4918,9 @@ var tocRule = {
4903
4918
  if (tocToken.value.toLowerCase() !== "toc") {
4904
4919
  return { success: false };
4905
4920
  }
4921
+ if (!ctx.settings.enablePageSyntax) {
4922
+ return { success: false };
4923
+ }
4906
4924
  pos++;
4907
4925
  } else {
4908
4926
  return { success: false };
@@ -5985,10 +6003,8 @@ var newlineLineBreakRule = {
5985
6003
  }
5986
6004
  const nextMeaningfulToken = ctx.tokens[ctx.pos + lookAhead];
5987
6005
  let isValidBlock = isBlockStartToken(nextMeaningfulToken?.type);
5988
- if (isValidBlock && (nextMeaningfulToken?.type === "LIST_BULLET" || nextMeaningfulToken?.type === "LIST_NUMBER")) {
5989
- if (!nextMeaningfulToken.lineStart) {
5990
- isValidBlock = false;
5991
- }
6006
+ if (isValidBlock && !nextMeaningfulToken?.lineStart) {
6007
+ isValidBlock = false;
5992
6008
  }
5993
6009
  if (isValidBlock && nextMeaningfulToken?.type === "HEADING_MARKER") {
5994
6010
  const markerLen = nextMeaningfulToken.value.length;
@@ -7735,6 +7751,7 @@ var bibciteRule = {
7735
7751
  return { success: false };
7736
7752
  }
7737
7753
  let label = "";
7754
+ let foundClose = false;
7738
7755
  while (pos < ctx.tokens.length) {
7739
7756
  const t = ctx.tokens[pos];
7740
7757
  if (!t)
@@ -7743,6 +7760,7 @@ var bibciteRule = {
7743
7760
  const nextT = ctx.tokens[pos + 1];
7744
7761
  if (nextT?.type === "TEXT" && nextT.value === ")") {
7745
7762
  consumed += 2;
7763
+ foundClose = true;
7746
7764
  break;
7747
7765
  }
7748
7766
  }
@@ -7753,6 +7771,9 @@ var bibciteRule = {
7753
7771
  pos++;
7754
7772
  consumed++;
7755
7773
  }
7774
+ if (!foundClose) {
7775
+ return { success: false };
7776
+ }
7756
7777
  label = label.trim();
7757
7778
  if (!label) {
7758
7779
  return { success: false };
@@ -8288,6 +8309,7 @@ class Parser {
8288
8309
  pos: 0,
8289
8310
  version: options.version ?? "wikidot",
8290
8311
  trackPositions: options.trackPositions ?? true,
8312
+ settings: options.settings ?? import_ast2.DEFAULT_SETTINGS,
8291
8313
  footnotes: [],
8292
8314
  tocEntries: [],
8293
8315
  codeBlocks: [],
@@ -9587,6 +9609,9 @@ function resolveIfTags(data, pageTags) {
9587
9609
  }
9588
9610
  // packages/parser/src/parser/rules/block/module/include/resolve.ts
9589
9611
  function resolveIncludes(source, fetcher, options) {
9612
+ if (options?.settings && !options.settings.enablePageSyntax) {
9613
+ return source;
9614
+ }
9590
9615
  const maxDepth = options?.maxDepth ?? 5;
9591
9616
  const cache = new Map;
9592
9617
  const cachedFetcher = (pageRef) => {
@@ -9605,16 +9630,31 @@ function resolveIncludes(source, fetcher, options) {
9605
9630
  };
9606
9631
  return expandText(source, cachedFetcher, 0, maxDepth, []);
9607
9632
  }
9608
- var INCLUDE_PATTERN = /\[\[include\s+([\s\S]*?)\]\]/gi;
9633
+ var INCLUDE_PATTERN = /\[\[include\s([^\]]*(?:\](?!\])[^\]]*)*)\]\]/gi;
9609
9634
  function parseIncludeDirective(inner) {
9610
9635
  const normalized = inner.replace(/\n/g, " ");
9611
9636
  const parts = normalized.split("|");
9612
- const target = parts[0].trim();
9613
- const variables = {};
9637
+ const firstSegment = parts[0].trim();
9638
+ const spaceIndex = firstSegment.indexOf(" ");
9639
+ let target;
9640
+ const varSegments = [];
9641
+ if (spaceIndex !== -1) {
9642
+ target = firstSegment.slice(0, spaceIndex);
9643
+ const rest = firstSegment.slice(spaceIndex + 1).trim();
9644
+ if (rest) {
9645
+ varSegments.push(rest);
9646
+ }
9647
+ } else {
9648
+ target = firstSegment;
9649
+ }
9614
9650
  for (let i = 1;i < parts.length; i++) {
9615
9651
  const segment = parts[i].trim();
9616
- if (!segment)
9617
- continue;
9652
+ if (segment) {
9653
+ varSegments.push(segment);
9654
+ }
9655
+ }
9656
+ const variables = {};
9657
+ for (const segment of varSegments) {
9618
9658
  const eqIndex = segment.indexOf("=");
9619
9659
  if (eqIndex !== -1) {
9620
9660
  const key = segment.slice(0, eqIndex).trim();