@wdprlib/parser 2.2.0 → 3.1.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 +921 -471
- package/dist/index.d.cts +50 -1
- package/dist/index.d.ts +50 -1
- package/dist/index.js +921 -471
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -80,6 +80,15 @@ declare class Lexer {
|
|
|
80
80
|
private state;
|
|
81
81
|
private options;
|
|
82
82
|
private splitBlockClosePositions;
|
|
83
|
+
/**
|
|
84
|
+
* Nesting depth of block-opener context (between `[[` / `[[/` and the
|
|
85
|
+
* matching `]]`). Used to scope `QUOTED_STRING` recognition so that
|
|
86
|
+
* `"` after `=` only becomes a quoted attribute value while we are
|
|
87
|
+
* actually parsing block attributes — otherwise inline `=` followed by
|
|
88
|
+
* `"` (e.g. inside `[[footnote]]="[[/footnote]]`) would erroneously
|
|
89
|
+
* consume content up to the next `"` or newline.
|
|
90
|
+
*/
|
|
91
|
+
private blockOpenerDepth;
|
|
83
92
|
constructor(source: string, options?: LexerOptions);
|
|
84
93
|
/**
|
|
85
94
|
* Tokenize the entire source
|
|
@@ -160,6 +169,25 @@ interface ParserOptions {
|
|
|
160
169
|
* Defaults to {@link DEFAULT_SETTINGS} (full page mode).
|
|
161
170
|
*/
|
|
162
171
|
settings?: WikitextSettings;
|
|
172
|
+
/**
|
|
173
|
+
* Page tags consulted when expanding `[[iftags]]` directives that are
|
|
174
|
+
* embedded inside another block's opener — e.g.
|
|
175
|
+
* `[[div_ class="x" [[iftags +foo]]style="..."[[/iftags]]]]`. Such
|
|
176
|
+
* iftags must be collapsed at text level *before* tokenization;
|
|
177
|
+
* otherwise the outer opener loses its well-formed structure and the
|
|
178
|
+
* whole `[[div_ ... ]]` line is emitted as raw text.
|
|
179
|
+
*
|
|
180
|
+
* Values:
|
|
181
|
+
* - omitted / `undefined`: no preprocess pass. Existing behaviour;
|
|
182
|
+
* opener-embedded iftags will still break the surrounding opener.
|
|
183
|
+
* - `null`: opener-embedded iftags only, evaluated as if the page has
|
|
184
|
+
* no tags (lossy fallback that keeps tokenization working when real
|
|
185
|
+
* tags are unknown). Block-level iftags remain in the AST for
|
|
186
|
+
* `resolveModules` to evaluate later via `getPageTags`.
|
|
187
|
+
* - `string[]`: every iftags block is evaluated against the given
|
|
188
|
+
* tags eagerly; no `if-tags` nodes survive in the AST.
|
|
189
|
+
*/
|
|
190
|
+
pageTags?: string[] | null;
|
|
163
191
|
}
|
|
164
192
|
/**
|
|
165
193
|
* Converts a token stream into a Wikidot {@link SyntaxTree}.
|
|
@@ -848,6 +876,27 @@ declare function parseNumericSelector(value: string): NormalizedNumericSelector
|
|
|
848
876
|
* @returns Normalized query with structured types
|
|
849
877
|
*/
|
|
850
878
|
declare function normalizeQuery(query: ListPagesQuery): NormalizedListPagesQuery;
|
|
879
|
+
/**
|
|
880
|
+
* Expand `[[iftags ...]]X[[/iftags]]` directives in `source` against the
|
|
881
|
+
* current page's tags.
|
|
882
|
+
*
|
|
883
|
+
* Behaviour:
|
|
884
|
+
* - Raw regions (`[[code]]`, `[[html]]`, `@@...@@`, `@<...>@`) are
|
|
885
|
+
* protected: literal `[[iftags]]` tokens inside them are not expanded.
|
|
886
|
+
* - Nested `[[iftags]]` are processed innermost-first, so an outer
|
|
887
|
+
* block can re-process the now-flattened inner body uniformly.
|
|
888
|
+
* - `pageTags === null`: only `[[iftags]]` blocks embedded inside
|
|
889
|
+
* another block's opener are collapsed (using an empty-tag fallback
|
|
890
|
+
* so `+tag` conditions fail and `-tag` conditions pass). Block-level
|
|
891
|
+
* iftags are left intact for the AST-level resolver.
|
|
892
|
+
*
|
|
893
|
+
* @param source Raw wikitext (typically after include expansion).
|
|
894
|
+
* @param pageTags Tags of the page being rendered, or `null` for the
|
|
895
|
+
* opener-embedded-only fallback mode.
|
|
896
|
+
* @returns Source with matching iftags replaced by their bodies and
|
|
897
|
+
* unmatched iftags removed entirely.
|
|
898
|
+
*/
|
|
899
|
+
declare function preprocessIftags(source: string, pageTags: string[] | null): string;
|
|
851
900
|
import { PageRef, WikitextSettings as WikitextSettings3 } from "@wdprlib/ast";
|
|
852
901
|
/**
|
|
853
902
|
* Callback to fetch page content for include resolution.
|
|
@@ -1011,4 +1060,4 @@ interface ResolveOptions {
|
|
|
1011
1060
|
*/
|
|
1012
1061
|
declare function resolveModules(ast: SyntaxTree2, dataProvider: DataProvider, options: ResolveOptions): Promise<SyntaxTree2>;
|
|
1013
1062
|
import { STYLE_SLOT_PREFIX } from "@wdprlib/ast";
|
|
1014
|
-
export { tokenize, text, resolveModules, resolveListUsers, resolveIncludesAsync, 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, SyntaxTree3 as SyntaxTree, SiteContext, STYLE_SLOT_PREFIX, ResolveOptions, ResolveIncludesOptions, Position2 as Position, Point, ParserOptions, Parser, ParseResult2 as ParseResult, 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, DiagnosticSeverity, Diagnostic2 as Diagnostic, DefinitionListItem, DateItem, DataRequirements, DataProvider, DEFAULT_SETTINGS, ContainerType, ContainerData, CompiledTemplate, CollapsibleData, CodeBlockData2 as CodeBlockData, ClearFloat, AttributeMap, AsyncIncludeFetcher, AnchorTarget, Alignment, AlignType };
|
|
1063
|
+
export { tokenize, text, resolveModules, resolveListUsers, resolveIncludesAsync, resolveIncludes, preprocessIftags, 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, SyntaxTree3 as SyntaxTree, SiteContext, STYLE_SLOT_PREFIX, ResolveOptions, ResolveIncludesOptions, Position2 as Position, Point, ParserOptions, Parser, ParseResult2 as ParseResult, 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, DiagnosticSeverity, Diagnostic2 as Diagnostic, DefinitionListItem, DateItem, DataRequirements, DataProvider, DEFAULT_SETTINGS, ContainerType, ContainerData, CompiledTemplate, CollapsibleData, CodeBlockData2 as CodeBlockData, ClearFloat, AttributeMap, AsyncIncludeFetcher, AnchorTarget, Alignment, AlignType };
|
package/dist/index.d.ts
CHANGED
|
@@ -80,6 +80,15 @@ declare class Lexer {
|
|
|
80
80
|
private state;
|
|
81
81
|
private options;
|
|
82
82
|
private splitBlockClosePositions;
|
|
83
|
+
/**
|
|
84
|
+
* Nesting depth of block-opener context (between `[[` / `[[/` and the
|
|
85
|
+
* matching `]]`). Used to scope `QUOTED_STRING` recognition so that
|
|
86
|
+
* `"` after `=` only becomes a quoted attribute value while we are
|
|
87
|
+
* actually parsing block attributes — otherwise inline `=` followed by
|
|
88
|
+
* `"` (e.g. inside `[[footnote]]="[[/footnote]]`) would erroneously
|
|
89
|
+
* consume content up to the next `"` or newline.
|
|
90
|
+
*/
|
|
91
|
+
private blockOpenerDepth;
|
|
83
92
|
constructor(source: string, options?: LexerOptions);
|
|
84
93
|
/**
|
|
85
94
|
* Tokenize the entire source
|
|
@@ -160,6 +169,25 @@ interface ParserOptions {
|
|
|
160
169
|
* Defaults to {@link DEFAULT_SETTINGS} (full page mode).
|
|
161
170
|
*/
|
|
162
171
|
settings?: WikitextSettings;
|
|
172
|
+
/**
|
|
173
|
+
* Page tags consulted when expanding `[[iftags]]` directives that are
|
|
174
|
+
* embedded inside another block's opener — e.g.
|
|
175
|
+
* `[[div_ class="x" [[iftags +foo]]style="..."[[/iftags]]]]`. Such
|
|
176
|
+
* iftags must be collapsed at text level *before* tokenization;
|
|
177
|
+
* otherwise the outer opener loses its well-formed structure and the
|
|
178
|
+
* whole `[[div_ ... ]]` line is emitted as raw text.
|
|
179
|
+
*
|
|
180
|
+
* Values:
|
|
181
|
+
* - omitted / `undefined`: no preprocess pass. Existing behaviour;
|
|
182
|
+
* opener-embedded iftags will still break the surrounding opener.
|
|
183
|
+
* - `null`: opener-embedded iftags only, evaluated as if the page has
|
|
184
|
+
* no tags (lossy fallback that keeps tokenization working when real
|
|
185
|
+
* tags are unknown). Block-level iftags remain in the AST for
|
|
186
|
+
* `resolveModules` to evaluate later via `getPageTags`.
|
|
187
|
+
* - `string[]`: every iftags block is evaluated against the given
|
|
188
|
+
* tags eagerly; no `if-tags` nodes survive in the AST.
|
|
189
|
+
*/
|
|
190
|
+
pageTags?: string[] | null;
|
|
163
191
|
}
|
|
164
192
|
/**
|
|
165
193
|
* Converts a token stream into a Wikidot {@link SyntaxTree}.
|
|
@@ -848,6 +876,27 @@ declare function parseNumericSelector(value: string): NormalizedNumericSelector
|
|
|
848
876
|
* @returns Normalized query with structured types
|
|
849
877
|
*/
|
|
850
878
|
declare function normalizeQuery(query: ListPagesQuery): NormalizedListPagesQuery;
|
|
879
|
+
/**
|
|
880
|
+
* Expand `[[iftags ...]]X[[/iftags]]` directives in `source` against the
|
|
881
|
+
* current page's tags.
|
|
882
|
+
*
|
|
883
|
+
* Behaviour:
|
|
884
|
+
* - Raw regions (`[[code]]`, `[[html]]`, `@@...@@`, `@<...>@`) are
|
|
885
|
+
* protected: literal `[[iftags]]` tokens inside them are not expanded.
|
|
886
|
+
* - Nested `[[iftags]]` are processed innermost-first, so an outer
|
|
887
|
+
* block can re-process the now-flattened inner body uniformly.
|
|
888
|
+
* - `pageTags === null`: only `[[iftags]]` blocks embedded inside
|
|
889
|
+
* another block's opener are collapsed (using an empty-tag fallback
|
|
890
|
+
* so `+tag` conditions fail and `-tag` conditions pass). Block-level
|
|
891
|
+
* iftags are left intact for the AST-level resolver.
|
|
892
|
+
*
|
|
893
|
+
* @param source Raw wikitext (typically after include expansion).
|
|
894
|
+
* @param pageTags Tags of the page being rendered, or `null` for the
|
|
895
|
+
* opener-embedded-only fallback mode.
|
|
896
|
+
* @returns Source with matching iftags replaced by their bodies and
|
|
897
|
+
* unmatched iftags removed entirely.
|
|
898
|
+
*/
|
|
899
|
+
declare function preprocessIftags(source: string, pageTags: string[] | null): string;
|
|
851
900
|
import { PageRef, WikitextSettings as WikitextSettings3 } from "@wdprlib/ast";
|
|
852
901
|
/**
|
|
853
902
|
* Callback to fetch page content for include resolution.
|
|
@@ -1011,4 +1060,4 @@ interface ResolveOptions {
|
|
|
1011
1060
|
*/
|
|
1012
1061
|
declare function resolveModules(ast: SyntaxTree2, dataProvider: DataProvider, options: ResolveOptions): Promise<SyntaxTree2>;
|
|
1013
1062
|
import { STYLE_SLOT_PREFIX } from "@wdprlib/ast";
|
|
1014
|
-
export { tokenize, text, resolveModules, resolveListUsers, resolveIncludesAsync, 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, SyntaxTree3 as SyntaxTree, SiteContext, STYLE_SLOT_PREFIX, ResolveOptions, ResolveIncludesOptions, Position2 as Position, Point, ParserOptions, Parser, ParseResult2 as ParseResult, 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, DiagnosticSeverity, Diagnostic2 as Diagnostic, DefinitionListItem, DateItem, DataRequirements, DataProvider, DEFAULT_SETTINGS, ContainerType, ContainerData, CompiledTemplate, CollapsibleData, CodeBlockData2 as CodeBlockData, ClearFloat, AttributeMap, AsyncIncludeFetcher, AnchorTarget, Alignment, AlignType };
|
|
1063
|
+
export { tokenize, text, resolveModules, resolveListUsers, resolveIncludesAsync, resolveIncludes, preprocessIftags, 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, SyntaxTree3 as SyntaxTree, SiteContext, STYLE_SLOT_PREFIX, ResolveOptions, ResolveIncludesOptions, Position2 as Position, Point, ParserOptions, Parser, ParseResult2 as ParseResult, 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, DiagnosticSeverity, Diagnostic2 as Diagnostic, DefinitionListItem, DateItem, DataRequirements, DataProvider, DEFAULT_SETTINGS, ContainerType, ContainerData, CompiledTemplate, CollapsibleData, CodeBlockData2 as CodeBlockData, ClearFloat, AttributeMap, AsyncIncludeFetcher, AnchorTarget, Alignment, AlignType };
|