@wdprlib/parser 1.1.2 → 1.1.4
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 +47 -23
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +29 -5
- package/package.json +2 -2
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: () =>
|
|
34
|
+
text: () => import_ast5.text,
|
|
35
35
|
resolveModules: () => resolveModules,
|
|
36
36
|
resolveListUsers: () => resolveListUsers,
|
|
37
37
|
resolveIncludes: () => resolveIncludes,
|
|
@@ -42,34 +42,35 @@ __export(exports_src, {
|
|
|
42
42
|
parseDateSelector: () => parseDateSelector,
|
|
43
43
|
parseCategory: () => parseCategory,
|
|
44
44
|
parse: () => parse,
|
|
45
|
-
paragraph: () =>
|
|
45
|
+
paragraph: () => import_ast5.paragraph,
|
|
46
46
|
normalizeQuery: () => normalizeQuery,
|
|
47
|
-
listItemSubList: () =>
|
|
48
|
-
listItemElements: () =>
|
|
49
|
-
list: () =>
|
|
50
|
-
link: () =>
|
|
51
|
-
lineBreak: () =>
|
|
52
|
-
italics: () =>
|
|
47
|
+
listItemSubList: () => import_ast5.listItemSubList,
|
|
48
|
+
listItemElements: () => import_ast5.listItemElements,
|
|
49
|
+
list: () => import_ast5.list,
|
|
50
|
+
link: () => import_ast5.link,
|
|
51
|
+
lineBreak: () => import_ast5.lineBreak,
|
|
52
|
+
italics: () => import_ast5.italics,
|
|
53
53
|
isListUsersModule: () => isListUsersModule2,
|
|
54
|
-
horizontalRule: () =>
|
|
55
|
-
heading: () =>
|
|
54
|
+
horizontalRule: () => import_ast5.horizontalRule,
|
|
55
|
+
heading: () => import_ast5.heading,
|
|
56
56
|
extractListUsersVariables: () => extractListUsersVariables,
|
|
57
57
|
extractDataRequirements: () => extractDataRequirements,
|
|
58
58
|
createToken: () => createToken,
|
|
59
|
-
createSettings: () =>
|
|
60
|
-
createPosition: () =>
|
|
61
|
-
createPoint: () =>
|
|
62
|
-
container: () =>
|
|
59
|
+
createSettings: () => import_ast6.createSettings,
|
|
60
|
+
createPosition: () => import_ast5.createPosition,
|
|
61
|
+
createPoint: () => import_ast5.createPoint,
|
|
62
|
+
container: () => import_ast5.container,
|
|
63
63
|
compileTemplate: () => compileTemplate,
|
|
64
64
|
compileListUsersTemplate: () => compileListUsersTemplate,
|
|
65
|
-
bold: () =>
|
|
65
|
+
bold: () => import_ast5.bold,
|
|
66
|
+
STYLE_SLOT_PREFIX: () => import_ast4.STYLE_SLOT_PREFIX,
|
|
66
67
|
Parser: () => Parser,
|
|
67
68
|
Lexer: () => Lexer,
|
|
68
|
-
DEFAULT_SETTINGS: () =>
|
|
69
|
+
DEFAULT_SETTINGS: () => import_ast6.DEFAULT_SETTINGS
|
|
69
70
|
});
|
|
70
71
|
module.exports = __toCommonJS(exports_src);
|
|
71
|
-
var
|
|
72
|
-
var
|
|
72
|
+
var import_ast5 = require("@wdprlib/ast");
|
|
73
|
+
var import_ast6 = require("@wdprlib/ast");
|
|
73
74
|
|
|
74
75
|
// packages/parser/src/lexer/tokens.ts
|
|
75
76
|
function createToken(type, value, position, lineStart = false) {
|
|
@@ -9580,6 +9581,7 @@ function resolveAndNormalizeQuery(requirement, urlParams) {
|
|
|
9580
9581
|
function parseTagCondition(condition) {
|
|
9581
9582
|
const required = [];
|
|
9582
9583
|
const forbidden = [];
|
|
9584
|
+
const optional = [];
|
|
9583
9585
|
const parts = condition.trim().split(/\s+/);
|
|
9584
9586
|
for (const part of parts) {
|
|
9585
9587
|
if (!part)
|
|
@@ -9593,12 +9595,15 @@ function parseTagCondition(condition) {
|
|
|
9593
9595
|
if (tag)
|
|
9594
9596
|
forbidden.push(tag);
|
|
9595
9597
|
} else {
|
|
9596
|
-
|
|
9598
|
+
optional.push(part);
|
|
9597
9599
|
}
|
|
9598
9600
|
}
|
|
9599
|
-
return { required, forbidden };
|
|
9601
|
+
return { required, forbidden, optional };
|
|
9600
9602
|
}
|
|
9601
9603
|
function evaluateTagCondition(condition, pageTags) {
|
|
9604
|
+
if (condition.required.length === 0 && condition.forbidden.length === 0 && condition.optional.length === 0) {
|
|
9605
|
+
return false;
|
|
9606
|
+
}
|
|
9602
9607
|
const tagSet = new Set(pageTags);
|
|
9603
9608
|
for (const tag of condition.required) {
|
|
9604
9609
|
if (!tagSet.has(tag)) {
|
|
@@ -9610,6 +9615,11 @@ function evaluateTagCondition(condition, pageTags) {
|
|
|
9610
9615
|
return false;
|
|
9611
9616
|
}
|
|
9612
9617
|
}
|
|
9618
|
+
if (condition.optional.length > 0) {
|
|
9619
|
+
if (!condition.optional.some((tag) => tagSet.has(tag))) {
|
|
9620
|
+
return false;
|
|
9621
|
+
}
|
|
9622
|
+
}
|
|
9613
9623
|
return true;
|
|
9614
9624
|
}
|
|
9615
9625
|
// packages/parser/src/parser/rules/block/module/iftags/resolve.ts
|
|
@@ -9745,6 +9755,7 @@ function resolveListUsers(_module, data, compiledTemplate, parse2) {
|
|
|
9745
9755
|
return itemAst.elements;
|
|
9746
9756
|
}
|
|
9747
9757
|
// packages/parser/src/parser/rules/block/module/resolve.ts
|
|
9758
|
+
var import_ast3 = require("@wdprlib/ast");
|
|
9748
9759
|
async function resolveModules(ast, dataProvider, options) {
|
|
9749
9760
|
let listPagesCtx = null;
|
|
9750
9761
|
const listPagesReqs = options.requirements.listPages ?? [];
|
|
@@ -9909,18 +9920,31 @@ function countModulesInElements(elements) {
|
|
|
9909
9920
|
}
|
|
9910
9921
|
function collectStyles(elements) {
|
|
9911
9922
|
const styles = [];
|
|
9912
|
-
const
|
|
9923
|
+
const ctx = { nextSlotId: 0 };
|
|
9924
|
+
const filtered = collectStylesFromElements(elements, styles, ctx);
|
|
9913
9925
|
return { elements: filtered, styles };
|
|
9914
9926
|
}
|
|
9915
|
-
function collectStylesFromElements(elements, styles) {
|
|
9927
|
+
function collectStylesFromElements(elements, styles, ctx) {
|
|
9916
9928
|
const result = [];
|
|
9917
9929
|
for (const element of elements) {
|
|
9918
9930
|
if (element.element === "style") {
|
|
9919
9931
|
styles.push(element.data);
|
|
9920
9932
|
continue;
|
|
9921
9933
|
}
|
|
9922
|
-
|
|
9934
|
+
if (element.element === "if-tags") {
|
|
9935
|
+
const slotId = ctx.nextSlotId++;
|
|
9936
|
+
styles.push(`${import_ast3.STYLE_SLOT_PREFIX}${slotId}`);
|
|
9937
|
+
result.push({
|
|
9938
|
+
element: "if-tags",
|
|
9939
|
+
data: { ...element.data, _styleSlot: slotId }
|
|
9940
|
+
});
|
|
9941
|
+
continue;
|
|
9942
|
+
}
|
|
9943
|
+
const mapped = mapElementChildren(element, (children) => collectStylesFromElements(children, styles, ctx));
|
|
9923
9944
|
result.push(mapped);
|
|
9924
9945
|
}
|
|
9925
9946
|
return result;
|
|
9926
9947
|
}
|
|
9948
|
+
|
|
9949
|
+
// packages/parser/src/parser/rules/block/module/index.ts
|
|
9950
|
+
var import_ast4 = require("@wdprlib/ast");
|
package/dist/index.d.cts
CHANGED
|
@@ -964,4 +964,5 @@ interface ResolveOptions {
|
|
|
964
964
|
* @param options - Resolution options including requirements
|
|
965
965
|
*/
|
|
966
966
|
declare function resolveModules(ast: SyntaxTree3, dataProvider: DataProvider, options: ResolveOptions): Promise<SyntaxTree3>;
|
|
967
|
-
|
|
967
|
+
import { STYLE_SLOT_PREFIX } from "@wdprlib/ast";
|
|
968
|
+
export { tokenize, text, resolveModules, resolveListUsers, resolveIncludes, parseTags, parseParent, parseOrder, parseNumericSelector, parseDateSelector, parseCategory, parse, paragraph, normalizeQuery, listItemSubList, listItemElements, list, link, lineBreak, italics, isListUsersModule, horizontalRule, heading, extractListUsersVariables, extractDataRequirements, createToken, createSettings, createPosition, createPoint, container, compileTemplate, compileListUsersTemplate, bold, WikitextSettings4 as WikitextSettings, WikitextMode, Version2 as Version, VariableMap, VariableContext, UserInfo, TokenType, Token, TocEntry2 as TocEntry, TableRow, TableData, TableCell, TabData, SyntaxTree4 as SyntaxTree, SiteContext, STYLE_SLOT_PREFIX, ResolveOptions, ResolveIncludesOptions, Position2 as Position, Point, ParserOptions, Parser, ParseFunction, PageRef2 as PageRef, PageData, NormalizedTags, NormalizedParent, NormalizedOrder, NormalizedNumericSelector, NormalizedListPagesQuery, NormalizedDateSelector, NormalizedCategory, Module4 as Module, ListUsersVariableContext, ListUsersVariable, ListUsersUserData, ListUsersExternalData, ListUsersDataRequirement, ListUsersDataFetcher, ListUsersCompiledTemplate, ListType, ListPagesVariable, ListPagesQuery, ListPagesExternalData, ListPagesDataRequirement, ListPagesDataFetcher, ListItem, ListData, LinkType, LinkLocation, LinkLabel, LexerOptions, Lexer, IncludeFetcher, ImageSource, HeadingLevel, Heading, HeaderType, FloatAlignment, ExtractionResult, Embed, Element6 as Element, DefinitionListItem, DateItem, DataRequirements, DataProvider, DEFAULT_SETTINGS, ContainerType, ContainerData, CompiledTemplate, CollapsibleData, CodeBlockData2 as CodeBlockData, ClearFloat, AttributeMap, AnchorTarget, Alignment, AlignType };
|
package/dist/index.d.ts
CHANGED
|
@@ -964,4 +964,5 @@ interface ResolveOptions {
|
|
|
964
964
|
* @param options - Resolution options including requirements
|
|
965
965
|
*/
|
|
966
966
|
declare function resolveModules(ast: SyntaxTree3, dataProvider: DataProvider, options: ResolveOptions): Promise<SyntaxTree3>;
|
|
967
|
-
|
|
967
|
+
import { STYLE_SLOT_PREFIX } from "@wdprlib/ast";
|
|
968
|
+
export { tokenize, text, resolveModules, resolveListUsers, resolveIncludes, parseTags, parseParent, parseOrder, parseNumericSelector, parseDateSelector, parseCategory, parse, paragraph, normalizeQuery, listItemSubList, listItemElements, list, link, lineBreak, italics, isListUsersModule, horizontalRule, heading, extractListUsersVariables, extractDataRequirements, createToken, createSettings, createPosition, createPoint, container, compileTemplate, compileListUsersTemplate, bold, WikitextSettings4 as WikitextSettings, WikitextMode, Version2 as Version, VariableMap, VariableContext, UserInfo, TokenType, Token, TocEntry2 as TocEntry, TableRow, TableData, TableCell, TabData, SyntaxTree4 as SyntaxTree, SiteContext, STYLE_SLOT_PREFIX, ResolveOptions, ResolveIncludesOptions, Position2 as Position, Point, ParserOptions, Parser, ParseFunction, PageRef2 as PageRef, PageData, NormalizedTags, NormalizedParent, NormalizedOrder, NormalizedNumericSelector, NormalizedListPagesQuery, NormalizedDateSelector, NormalizedCategory, Module4 as Module, ListUsersVariableContext, ListUsersVariable, ListUsersUserData, ListUsersExternalData, ListUsersDataRequirement, ListUsersDataFetcher, ListUsersCompiledTemplate, ListType, ListPagesVariable, ListPagesQuery, ListPagesExternalData, ListPagesDataRequirement, ListPagesDataFetcher, ListItem, ListData, LinkType, LinkLocation, LinkLabel, LexerOptions, Lexer, IncludeFetcher, ImageSource, HeadingLevel, Heading, HeaderType, FloatAlignment, ExtractionResult, Embed, Element6 as Element, DefinitionListItem, DateItem, DataRequirements, DataProvider, DEFAULT_SETTINGS, ContainerType, ContainerData, CompiledTemplate, CollapsibleData, CodeBlockData2 as CodeBlockData, ClearFloat, AttributeMap, AnchorTarget, Alignment, AlignType };
|
package/dist/index.js
CHANGED
|
@@ -9526,6 +9526,7 @@ function resolveAndNormalizeQuery(requirement, urlParams) {
|
|
|
9526
9526
|
function parseTagCondition(condition) {
|
|
9527
9527
|
const required = [];
|
|
9528
9528
|
const forbidden = [];
|
|
9529
|
+
const optional = [];
|
|
9529
9530
|
const parts = condition.trim().split(/\s+/);
|
|
9530
9531
|
for (const part of parts) {
|
|
9531
9532
|
if (!part)
|
|
@@ -9539,12 +9540,15 @@ function parseTagCondition(condition) {
|
|
|
9539
9540
|
if (tag)
|
|
9540
9541
|
forbidden.push(tag);
|
|
9541
9542
|
} else {
|
|
9542
|
-
|
|
9543
|
+
optional.push(part);
|
|
9543
9544
|
}
|
|
9544
9545
|
}
|
|
9545
|
-
return { required, forbidden };
|
|
9546
|
+
return { required, forbidden, optional };
|
|
9546
9547
|
}
|
|
9547
9548
|
function evaluateTagCondition(condition, pageTags) {
|
|
9549
|
+
if (condition.required.length === 0 && condition.forbidden.length === 0 && condition.optional.length === 0) {
|
|
9550
|
+
return false;
|
|
9551
|
+
}
|
|
9548
9552
|
const tagSet = new Set(pageTags);
|
|
9549
9553
|
for (const tag of condition.required) {
|
|
9550
9554
|
if (!tagSet.has(tag)) {
|
|
@@ -9556,6 +9560,11 @@ function evaluateTagCondition(condition, pageTags) {
|
|
|
9556
9560
|
return false;
|
|
9557
9561
|
}
|
|
9558
9562
|
}
|
|
9563
|
+
if (condition.optional.length > 0) {
|
|
9564
|
+
if (!condition.optional.some((tag) => tagSet.has(tag))) {
|
|
9565
|
+
return false;
|
|
9566
|
+
}
|
|
9567
|
+
}
|
|
9559
9568
|
return true;
|
|
9560
9569
|
}
|
|
9561
9570
|
// packages/parser/src/parser/rules/block/module/iftags/resolve.ts
|
|
@@ -9691,6 +9700,7 @@ function resolveListUsers(_module, data, compiledTemplate, parse2) {
|
|
|
9691
9700
|
return itemAst.elements;
|
|
9692
9701
|
}
|
|
9693
9702
|
// packages/parser/src/parser/rules/block/module/resolve.ts
|
|
9703
|
+
import { STYLE_SLOT_PREFIX } from "@wdprlib/ast";
|
|
9694
9704
|
async function resolveModules(ast, dataProvider, options) {
|
|
9695
9705
|
let listPagesCtx = null;
|
|
9696
9706
|
const listPagesReqs = options.requirements.listPages ?? [];
|
|
@@ -9855,21 +9865,34 @@ function countModulesInElements(elements) {
|
|
|
9855
9865
|
}
|
|
9856
9866
|
function collectStyles(elements) {
|
|
9857
9867
|
const styles = [];
|
|
9858
|
-
const
|
|
9868
|
+
const ctx = { nextSlotId: 0 };
|
|
9869
|
+
const filtered = collectStylesFromElements(elements, styles, ctx);
|
|
9859
9870
|
return { elements: filtered, styles };
|
|
9860
9871
|
}
|
|
9861
|
-
function collectStylesFromElements(elements, styles) {
|
|
9872
|
+
function collectStylesFromElements(elements, styles, ctx) {
|
|
9862
9873
|
const result = [];
|
|
9863
9874
|
for (const element of elements) {
|
|
9864
9875
|
if (element.element === "style") {
|
|
9865
9876
|
styles.push(element.data);
|
|
9866
9877
|
continue;
|
|
9867
9878
|
}
|
|
9868
|
-
|
|
9879
|
+
if (element.element === "if-tags") {
|
|
9880
|
+
const slotId = ctx.nextSlotId++;
|
|
9881
|
+
styles.push(`${STYLE_SLOT_PREFIX}${slotId}`);
|
|
9882
|
+
result.push({
|
|
9883
|
+
element: "if-tags",
|
|
9884
|
+
data: { ...element.data, _styleSlot: slotId }
|
|
9885
|
+
});
|
|
9886
|
+
continue;
|
|
9887
|
+
}
|
|
9888
|
+
const mapped = mapElementChildren(element, (children) => collectStylesFromElements(children, styles, ctx));
|
|
9869
9889
|
result.push(mapped);
|
|
9870
9890
|
}
|
|
9871
9891
|
return result;
|
|
9872
9892
|
}
|
|
9893
|
+
|
|
9894
|
+
// packages/parser/src/parser/rules/block/module/index.ts
|
|
9895
|
+
import { STYLE_SLOT_PREFIX as STYLE_SLOT_PREFIX2 } from "@wdprlib/ast";
|
|
9873
9896
|
export {
|
|
9874
9897
|
tokenize,
|
|
9875
9898
|
text,
|
|
@@ -9904,6 +9927,7 @@ export {
|
|
|
9904
9927
|
compileTemplate,
|
|
9905
9928
|
compileListUsersTemplate,
|
|
9906
9929
|
bold,
|
|
9930
|
+
STYLE_SLOT_PREFIX2 as STYLE_SLOT_PREFIX,
|
|
9907
9931
|
Parser,
|
|
9908
9932
|
Lexer,
|
|
9909
9933
|
DEFAULT_SETTINGS2 as DEFAULT_SETTINGS
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wdprlib/parser",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
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.1.
|
|
42
|
+
"@wdprlib/ast": "1.1.1"
|
|
43
43
|
}
|
|
44
44
|
}
|