@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 +65 -25
- package/dist/index.d.cts +277 -62
- package/dist/index.d.ts +277 -62
- package/dist/index.js +50 -10
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
listItemElements,
|
|
16
16
|
listItemSubList
|
|
17
17
|
} from "@wdprlib/ast";
|
|
18
|
+
import { createSettings, DEFAULT_SETTINGS as DEFAULT_SETTINGS2 } from "@wdprlib/ast";
|
|
18
19
|
|
|
19
20
|
// packages/parser/src/lexer/tokens.ts
|
|
20
21
|
function createToken(type, value, position, lineStart = false) {
|
|
@@ -503,6 +504,9 @@ function preprocess(text) {
|
|
|
503
504
|
return result;
|
|
504
505
|
}
|
|
505
506
|
|
|
507
|
+
// packages/parser/src/parser/parse.ts
|
|
508
|
+
import { DEFAULT_SETTINGS } from "@wdprlib/ast";
|
|
509
|
+
|
|
506
510
|
// packages/parser/src/parser/rules/types.ts
|
|
507
511
|
function currentToken(ctx) {
|
|
508
512
|
return ctx.tokens[ctx.pos] ?? eofToken();
|
|
@@ -3507,6 +3511,9 @@ var moduleRule = {
|
|
|
3507
3511
|
if (!nameResult || nameResult.name !== "module" && nameResult.name !== "module654") {
|
|
3508
3512
|
return { success: false };
|
|
3509
3513
|
}
|
|
3514
|
+
if (!ctx.settings.enablePageSyntax) {
|
|
3515
|
+
return { success: false };
|
|
3516
|
+
}
|
|
3510
3517
|
pos += nameResult.consumed;
|
|
3511
3518
|
consumed += nameResult.consumed;
|
|
3512
3519
|
while (ctx.tokens[pos]?.type === "WHITESPACE") {
|
|
@@ -4221,6 +4228,9 @@ var includeRule = {
|
|
|
4221
4228
|
if (!nameResult || nameResult.name.toLowerCase() !== "include") {
|
|
4222
4229
|
return { success: false };
|
|
4223
4230
|
}
|
|
4231
|
+
if (!ctx.settings.enablePageSyntax) {
|
|
4232
|
+
return { success: false };
|
|
4233
|
+
}
|
|
4224
4234
|
pos += nameResult.consumed;
|
|
4225
4235
|
consumed += nameResult.consumed;
|
|
4226
4236
|
while (ctx.tokens[pos]?.type === "WHITESPACE") {
|
|
@@ -4828,6 +4838,9 @@ var tocRule = {
|
|
|
4828
4838
|
}
|
|
4829
4839
|
const firstValue = firstToken.value.toLowerCase();
|
|
4830
4840
|
if (firstValue === "toc") {
|
|
4841
|
+
if (!ctx.settings.enablePageSyntax) {
|
|
4842
|
+
return { success: false };
|
|
4843
|
+
}
|
|
4831
4844
|
pos++;
|
|
4832
4845
|
} else if (firstValue === "f") {
|
|
4833
4846
|
pos++;
|
|
@@ -4851,6 +4864,9 @@ var tocRule = {
|
|
|
4851
4864
|
if (tocToken.value.toLowerCase() !== "toc") {
|
|
4852
4865
|
return { success: false };
|
|
4853
4866
|
}
|
|
4867
|
+
if (!ctx.settings.enablePageSyntax) {
|
|
4868
|
+
return { success: false };
|
|
4869
|
+
}
|
|
4854
4870
|
pos++;
|
|
4855
4871
|
} else {
|
|
4856
4872
|
return { success: false };
|
|
@@ -5933,10 +5949,8 @@ var newlineLineBreakRule = {
|
|
|
5933
5949
|
}
|
|
5934
5950
|
const nextMeaningfulToken = ctx.tokens[ctx.pos + lookAhead];
|
|
5935
5951
|
let isValidBlock = isBlockStartToken(nextMeaningfulToken?.type);
|
|
5936
|
-
if (isValidBlock &&
|
|
5937
|
-
|
|
5938
|
-
isValidBlock = false;
|
|
5939
|
-
}
|
|
5952
|
+
if (isValidBlock && !nextMeaningfulToken?.lineStart) {
|
|
5953
|
+
isValidBlock = false;
|
|
5940
5954
|
}
|
|
5941
5955
|
if (isValidBlock && nextMeaningfulToken?.type === "HEADING_MARKER") {
|
|
5942
5956
|
const markerLen = nextMeaningfulToken.value.length;
|
|
@@ -7683,6 +7697,7 @@ var bibciteRule = {
|
|
|
7683
7697
|
return { success: false };
|
|
7684
7698
|
}
|
|
7685
7699
|
let label = "";
|
|
7700
|
+
let foundClose = false;
|
|
7686
7701
|
while (pos < ctx.tokens.length) {
|
|
7687
7702
|
const t = ctx.tokens[pos];
|
|
7688
7703
|
if (!t)
|
|
@@ -7691,6 +7706,7 @@ var bibciteRule = {
|
|
|
7691
7706
|
const nextT = ctx.tokens[pos + 1];
|
|
7692
7707
|
if (nextT?.type === "TEXT" && nextT.value === ")") {
|
|
7693
7708
|
consumed += 2;
|
|
7709
|
+
foundClose = true;
|
|
7694
7710
|
break;
|
|
7695
7711
|
}
|
|
7696
7712
|
}
|
|
@@ -7701,6 +7717,9 @@ var bibciteRule = {
|
|
|
7701
7717
|
pos++;
|
|
7702
7718
|
consumed++;
|
|
7703
7719
|
}
|
|
7720
|
+
if (!foundClose) {
|
|
7721
|
+
return { success: false };
|
|
7722
|
+
}
|
|
7704
7723
|
label = label.trim();
|
|
7705
7724
|
if (!label) {
|
|
7706
7725
|
return { success: false };
|
|
@@ -8236,6 +8255,7 @@ class Parser {
|
|
|
8236
8255
|
pos: 0,
|
|
8237
8256
|
version: options.version ?? "wikidot",
|
|
8238
8257
|
trackPositions: options.trackPositions ?? true,
|
|
8258
|
+
settings: options.settings ?? DEFAULT_SETTINGS,
|
|
8239
8259
|
footnotes: [],
|
|
8240
8260
|
tocEntries: [],
|
|
8241
8261
|
codeBlocks: [],
|
|
@@ -9535,6 +9555,9 @@ function resolveIfTags(data, pageTags) {
|
|
|
9535
9555
|
}
|
|
9536
9556
|
// packages/parser/src/parser/rules/block/module/include/resolve.ts
|
|
9537
9557
|
function resolveIncludes(source, fetcher, options) {
|
|
9558
|
+
if (options?.settings && !options.settings.enablePageSyntax) {
|
|
9559
|
+
return source;
|
|
9560
|
+
}
|
|
9538
9561
|
const maxDepth = options?.maxDepth ?? 5;
|
|
9539
9562
|
const cache = new Map;
|
|
9540
9563
|
const cachedFetcher = (pageRef) => {
|
|
@@ -9553,16 +9576,31 @@ function resolveIncludes(source, fetcher, options) {
|
|
|
9553
9576
|
};
|
|
9554
9577
|
return expandText(source, cachedFetcher, 0, maxDepth, []);
|
|
9555
9578
|
}
|
|
9556
|
-
var INCLUDE_PATTERN = /\[\[include\s
|
|
9579
|
+
var INCLUDE_PATTERN = /\[\[include\s([^\]]*(?:\](?!\])[^\]]*)*)\]\]/gi;
|
|
9557
9580
|
function parseIncludeDirective(inner) {
|
|
9558
9581
|
const normalized = inner.replace(/\n/g, " ");
|
|
9559
9582
|
const parts = normalized.split("|");
|
|
9560
|
-
const
|
|
9561
|
-
const
|
|
9583
|
+
const firstSegment = parts[0].trim();
|
|
9584
|
+
const spaceIndex = firstSegment.indexOf(" ");
|
|
9585
|
+
let target;
|
|
9586
|
+
const varSegments = [];
|
|
9587
|
+
if (spaceIndex !== -1) {
|
|
9588
|
+
target = firstSegment.slice(0, spaceIndex);
|
|
9589
|
+
const rest = firstSegment.slice(spaceIndex + 1).trim();
|
|
9590
|
+
if (rest) {
|
|
9591
|
+
varSegments.push(rest);
|
|
9592
|
+
}
|
|
9593
|
+
} else {
|
|
9594
|
+
target = firstSegment;
|
|
9595
|
+
}
|
|
9562
9596
|
for (let i = 1;i < parts.length; i++) {
|
|
9563
9597
|
const segment = parts[i].trim();
|
|
9564
|
-
if (
|
|
9565
|
-
|
|
9598
|
+
if (segment) {
|
|
9599
|
+
varSegments.push(segment);
|
|
9600
|
+
}
|
|
9601
|
+
}
|
|
9602
|
+
const variables = {};
|
|
9603
|
+
for (const segment of varSegments) {
|
|
9566
9604
|
const eqIndex = segment.indexOf("=");
|
|
9567
9605
|
if (eqIndex !== -1) {
|
|
9568
9606
|
const key = segment.slice(0, eqIndex).trim();
|
|
@@ -9842,6 +9880,7 @@ export {
|
|
|
9842
9880
|
extractListUsersVariables,
|
|
9843
9881
|
extractDataRequirements,
|
|
9844
9882
|
createToken,
|
|
9883
|
+
createSettings,
|
|
9845
9884
|
createPosition2 as createPosition,
|
|
9846
9885
|
createPoint2 as createPoint,
|
|
9847
9886
|
container,
|
|
@@ -9849,5 +9888,6 @@ export {
|
|
|
9849
9888
|
compileListUsersTemplate,
|
|
9850
9889
|
bold,
|
|
9851
9890
|
Parser,
|
|
9852
|
-
Lexer
|
|
9891
|
+
Lexer,
|
|
9892
|
+
DEFAULT_SETTINGS2 as DEFAULT_SETTINGS
|
|
9853
9893
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wdprlib/parser",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Parser for Wikidot markup",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ast",
|
|
@@ -39,6 +39,6 @@
|
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@braintree/sanitize-url": "^7.1.1",
|
|
42
|
-
"@wdprlib/ast": "1.
|
|
42
|
+
"@wdprlib/ast": "1.1.0"
|
|
43
43
|
}
|
|
44
44
|
}
|