@wdprlib/parser 1.1.2 → 2.0.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 +369 -26
- package/dist/index.d.cts +24 -11
- package/dist/index.d.ts +24 -11
- package/dist/index.js +351 -8
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Position as Position2, Point, Version as Version2, Element as Element6, SyntaxTree as
|
|
1
|
+
import { Position as Position2, Point, Version as Version2, Element as Element6, SyntaxTree as SyntaxTree3, ContainerType, ContainerData, AttributeMap, VariableMap, Alignment, LinkType, LinkLocation, LinkLabel, PageRef as PageRef2, ImageSource, FloatAlignment, ListType, ListItem, ListData, CodeBlockData as CodeBlockData2, TabData, TableCell, TableRow, TableData, DefinitionListItem, Module as Module4, CollapsibleData, ClearFloat, AnchorTarget, HeaderType, AlignType, HeadingLevel, Heading, DateItem, Embed, TocEntry as TocEntry2, Diagnostic as Diagnostic2, DiagnosticSeverity, ParseResult as ParseResult2 } from "@wdprlib/ast";
|
|
2
2
|
import { createPoint, createPosition, text, container, paragraph, bold, italics, heading, lineBreak, horizontalRule, link, list, listItemElements, listItemSubList } from "@wdprlib/ast";
|
|
3
3
|
import { WikitextMode, WikitextSettings as WikitextSettings4 } from "@wdprlib/ast";
|
|
4
4
|
import { createSettings, DEFAULT_SETTINGS } from "@wdprlib/ast";
|
|
@@ -134,7 +134,7 @@ declare class Lexer {
|
|
|
134
134
|
* @group Lexer
|
|
135
135
|
*/
|
|
136
136
|
declare function tokenize(source: string, options?: LexerOptions): Token[];
|
|
137
|
-
import {
|
|
137
|
+
import { WikitextSettings, ParseResult } from "@wdprlib/ast";
|
|
138
138
|
/**
|
|
139
139
|
* Configuration for the {@link Parser} and the {@link parse} function.
|
|
140
140
|
*
|
|
@@ -181,9 +181,12 @@ declare class Parser {
|
|
|
181
181
|
private ctx;
|
|
182
182
|
constructor(tokens: Token[], options?: ParserOptions);
|
|
183
183
|
/**
|
|
184
|
-
* Parse tokens into
|
|
184
|
+
* Parse tokens into a {@link ParseResult} containing the AST and
|
|
185
|
+
* any diagnostics emitted during parsing.
|
|
186
|
+
*
|
|
187
|
+
* @since 2.0.0
|
|
185
188
|
*/
|
|
186
|
-
parse():
|
|
189
|
+
parse(): ParseResult;
|
|
187
190
|
/**
|
|
188
191
|
* Check if at end of tokens
|
|
189
192
|
*/
|
|
@@ -207,9 +210,18 @@ declare class Parser {
|
|
|
207
210
|
private parseBlock;
|
|
208
211
|
}
|
|
209
212
|
/**
|
|
210
|
-
* Parse
|
|
213
|
+
* Parse a Wikidot markup string into an AST with diagnostics.
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```ts
|
|
217
|
+
* import { parse } from "@wdprlib/parser";
|
|
218
|
+
*
|
|
219
|
+
* const { ast, diagnostics } = parse("**bold** and //italic//");
|
|
220
|
+
* ```
|
|
221
|
+
*
|
|
222
|
+
* @since 2.0.0
|
|
211
223
|
*/
|
|
212
|
-
declare function parse(source: string, options?: ParserOptions):
|
|
224
|
+
declare function parse(source: string, options?: ParserOptions): ParseResult;
|
|
213
225
|
import { Element as Element2 } from "@wdprlib/ast";
|
|
214
226
|
/**
|
|
215
227
|
* Parser function type for re-parsing substituted template output as wikitext.
|
|
@@ -716,7 +728,7 @@ interface DataProvider {
|
|
|
716
728
|
*/
|
|
717
729
|
getPageTags?: IfTagsResolver;
|
|
718
730
|
}
|
|
719
|
-
import { SyntaxTree
|
|
731
|
+
import { SyntaxTree } from "@wdprlib/ast";
|
|
720
732
|
/**
|
|
721
733
|
* Complete result of extracting data requirements from an AST.
|
|
722
734
|
*
|
|
@@ -746,7 +758,7 @@ interface ExtractionResult {
|
|
|
746
758
|
* @param ast - The parsed syntax tree to analyze
|
|
747
759
|
* @returns Extraction result containing requirements and compiled templates
|
|
748
760
|
*/
|
|
749
|
-
declare function extractDataRequirements(ast:
|
|
761
|
+
declare function extractDataRequirements(ast: SyntaxTree): ExtractionResult;
|
|
750
762
|
/**
|
|
751
763
|
* Compile a ListPages template string into an executable function.
|
|
752
764
|
*
|
|
@@ -914,7 +926,7 @@ declare function isListUsersModule(module: Module3): module is ListUsersModuleDa
|
|
|
914
926
|
* @returns Array of AST elements produced by parsing the rendered template
|
|
915
927
|
*/
|
|
916
928
|
declare function resolveListUsers(_module: ListUsersModuleData, data: ListUsersExternalData, compiledTemplate: ListUsersCompiledTemplate, parse: ParseFunction): Element5[];
|
|
917
|
-
import { SyntaxTree as
|
|
929
|
+
import { SyntaxTree as SyntaxTree2 } from "@wdprlib/ast";
|
|
918
930
|
/**
|
|
919
931
|
* Configuration for {@link resolveModules}.
|
|
920
932
|
*
|
|
@@ -963,5 +975,6 @@ interface ResolveOptions {
|
|
|
963
975
|
* @param dataProvider - Callback provider to fetch data for each module
|
|
964
976
|
* @param options - Resolution options including requirements
|
|
965
977
|
*/
|
|
966
|
-
declare function resolveModules(ast:
|
|
967
|
-
|
|
978
|
+
declare function resolveModules(ast: SyntaxTree2, dataProvider: DataProvider, options: ResolveOptions): Promise<SyntaxTree2>;
|
|
979
|
+
import { STYLE_SLOT_PREFIX } from "@wdprlib/ast";
|
|
980
|
+
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, 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, AnchorTarget, Alignment, AlignType };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Position as Position2, Point, Version as Version2, Element as Element6, SyntaxTree as
|
|
1
|
+
import { Position as Position2, Point, Version as Version2, Element as Element6, SyntaxTree as SyntaxTree3, ContainerType, ContainerData, AttributeMap, VariableMap, Alignment, LinkType, LinkLocation, LinkLabel, PageRef as PageRef2, ImageSource, FloatAlignment, ListType, ListItem, ListData, CodeBlockData as CodeBlockData2, TabData, TableCell, TableRow, TableData, DefinitionListItem, Module as Module4, CollapsibleData, ClearFloat, AnchorTarget, HeaderType, AlignType, HeadingLevel, Heading, DateItem, Embed, TocEntry as TocEntry2, Diagnostic as Diagnostic2, DiagnosticSeverity, ParseResult as ParseResult2 } from "@wdprlib/ast";
|
|
2
2
|
import { createPoint, createPosition, text, container, paragraph, bold, italics, heading, lineBreak, horizontalRule, link, list, listItemElements, listItemSubList } from "@wdprlib/ast";
|
|
3
3
|
import { WikitextMode, WikitextSettings as WikitextSettings4 } from "@wdprlib/ast";
|
|
4
4
|
import { createSettings, DEFAULT_SETTINGS } from "@wdprlib/ast";
|
|
@@ -134,7 +134,7 @@ declare class Lexer {
|
|
|
134
134
|
* @group Lexer
|
|
135
135
|
*/
|
|
136
136
|
declare function tokenize(source: string, options?: LexerOptions): Token[];
|
|
137
|
-
import {
|
|
137
|
+
import { WikitextSettings, ParseResult } from "@wdprlib/ast";
|
|
138
138
|
/**
|
|
139
139
|
* Configuration for the {@link Parser} and the {@link parse} function.
|
|
140
140
|
*
|
|
@@ -181,9 +181,12 @@ declare class Parser {
|
|
|
181
181
|
private ctx;
|
|
182
182
|
constructor(tokens: Token[], options?: ParserOptions);
|
|
183
183
|
/**
|
|
184
|
-
* Parse tokens into
|
|
184
|
+
* Parse tokens into a {@link ParseResult} containing the AST and
|
|
185
|
+
* any diagnostics emitted during parsing.
|
|
186
|
+
*
|
|
187
|
+
* @since 2.0.0
|
|
185
188
|
*/
|
|
186
|
-
parse():
|
|
189
|
+
parse(): ParseResult;
|
|
187
190
|
/**
|
|
188
191
|
* Check if at end of tokens
|
|
189
192
|
*/
|
|
@@ -207,9 +210,18 @@ declare class Parser {
|
|
|
207
210
|
private parseBlock;
|
|
208
211
|
}
|
|
209
212
|
/**
|
|
210
|
-
* Parse
|
|
213
|
+
* Parse a Wikidot markup string into an AST with diagnostics.
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```ts
|
|
217
|
+
* import { parse } from "@wdprlib/parser";
|
|
218
|
+
*
|
|
219
|
+
* const { ast, diagnostics } = parse("**bold** and //italic//");
|
|
220
|
+
* ```
|
|
221
|
+
*
|
|
222
|
+
* @since 2.0.0
|
|
211
223
|
*/
|
|
212
|
-
declare function parse(source: string, options?: ParserOptions):
|
|
224
|
+
declare function parse(source: string, options?: ParserOptions): ParseResult;
|
|
213
225
|
import { Element as Element2 } from "@wdprlib/ast";
|
|
214
226
|
/**
|
|
215
227
|
* Parser function type for re-parsing substituted template output as wikitext.
|
|
@@ -716,7 +728,7 @@ interface DataProvider {
|
|
|
716
728
|
*/
|
|
717
729
|
getPageTags?: IfTagsResolver;
|
|
718
730
|
}
|
|
719
|
-
import { SyntaxTree
|
|
731
|
+
import { SyntaxTree } from "@wdprlib/ast";
|
|
720
732
|
/**
|
|
721
733
|
* Complete result of extracting data requirements from an AST.
|
|
722
734
|
*
|
|
@@ -746,7 +758,7 @@ interface ExtractionResult {
|
|
|
746
758
|
* @param ast - The parsed syntax tree to analyze
|
|
747
759
|
* @returns Extraction result containing requirements and compiled templates
|
|
748
760
|
*/
|
|
749
|
-
declare function extractDataRequirements(ast:
|
|
761
|
+
declare function extractDataRequirements(ast: SyntaxTree): ExtractionResult;
|
|
750
762
|
/**
|
|
751
763
|
* Compile a ListPages template string into an executable function.
|
|
752
764
|
*
|
|
@@ -914,7 +926,7 @@ declare function isListUsersModule(module: Module3): module is ListUsersModuleDa
|
|
|
914
926
|
* @returns Array of AST elements produced by parsing the rendered template
|
|
915
927
|
*/
|
|
916
928
|
declare function resolveListUsers(_module: ListUsersModuleData, data: ListUsersExternalData, compiledTemplate: ListUsersCompiledTemplate, parse: ParseFunction): Element5[];
|
|
917
|
-
import { SyntaxTree as
|
|
929
|
+
import { SyntaxTree as SyntaxTree2 } from "@wdprlib/ast";
|
|
918
930
|
/**
|
|
919
931
|
* Configuration for {@link resolveModules}.
|
|
920
932
|
*
|
|
@@ -963,5 +975,6 @@ interface ResolveOptions {
|
|
|
963
975
|
* @param dataProvider - Callback provider to fetch data for each module
|
|
964
976
|
* @param options - Resolution options including requirements
|
|
965
977
|
*/
|
|
966
|
-
declare function resolveModules(ast:
|
|
967
|
-
|
|
978
|
+
declare function resolveModules(ast: SyntaxTree2, dataProvider: DataProvider, options: ResolveOptions): Promise<SyntaxTree2>;
|
|
979
|
+
import { STYLE_SLOT_PREFIX } from "@wdprlib/ast";
|
|
980
|
+
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, 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, AnchorTarget, Alignment, AlignType };
|