@wdprlib/ast 1.1.1 → 1.2.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.d.cts +81 -1
- package/dist/index.d.ts +81 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1042,6 +1042,86 @@ declare function isContainerTypeParagraphSafe(type: ContainerType): boolean;
|
|
|
1042
1042
|
*/
|
|
1043
1043
|
declare function isParagraphSafe(element: Element): boolean;
|
|
1044
1044
|
/**
|
|
1045
|
+
* Severity level of a diagnostic.
|
|
1046
|
+
*
|
|
1047
|
+
* - `"error"` — the markup is structurally broken (e.g. inline `[[div]]`
|
|
1048
|
+
* without a newline after `]]`).
|
|
1049
|
+
* - `"warning"` — the markup is likely unintentional but the parser can
|
|
1050
|
+
* recover (e.g. a missing `[[/div]]` close tag).
|
|
1051
|
+
* - `"info"` — informational hints (e.g. deprecated syntax).
|
|
1052
|
+
*
|
|
1053
|
+
* @since 2.0.0
|
|
1054
|
+
* @group Diagnostics
|
|
1055
|
+
*/
|
|
1056
|
+
type DiagnosticSeverity = "error" | "warning" | "info";
|
|
1057
|
+
/**
|
|
1058
|
+
* A single diagnostic emitted during parsing.
|
|
1059
|
+
*
|
|
1060
|
+
* Each diagnostic pinpoints a source location via {@link Position} and
|
|
1061
|
+
* carries a machine-readable {@link Diagnostic.code | code} string for
|
|
1062
|
+
* programmatic filtering (e.g. `"unclosed-block"`, `"inline-block-element"`).
|
|
1063
|
+
*
|
|
1064
|
+
* @example
|
|
1065
|
+
* ```ts
|
|
1066
|
+
* import { parse } from "@wdprlib/parser";
|
|
1067
|
+
*
|
|
1068
|
+
* const { ast, diagnostics } = parse("[[div]]\nHello");
|
|
1069
|
+
* for (const d of diagnostics) {
|
|
1070
|
+
* console.log(`[${d.severity}] ${d.message} (line ${d.position.start.line})`);
|
|
1071
|
+
* }
|
|
1072
|
+
* ```
|
|
1073
|
+
*
|
|
1074
|
+
* @since 2.0.0
|
|
1075
|
+
* @group Diagnostics
|
|
1076
|
+
*/
|
|
1077
|
+
interface Diagnostic {
|
|
1078
|
+
/** How severe the issue is. */
|
|
1079
|
+
severity: DiagnosticSeverity;
|
|
1080
|
+
/**
|
|
1081
|
+
* Machine-readable identifier for the diagnostic kind.
|
|
1082
|
+
*
|
|
1083
|
+
* Current codes:
|
|
1084
|
+
* - `"unclosed-block"` — a block element has no matching close tag.
|
|
1085
|
+
* - `"inline-block-element"` — a block element (e.g. `[[div]]`) is used
|
|
1086
|
+
* inline without the required trailing newline.
|
|
1087
|
+
*/
|
|
1088
|
+
code: string;
|
|
1089
|
+
/** Human-readable description of the issue. */
|
|
1090
|
+
message: string;
|
|
1091
|
+
/** Source range where the issue was detected. */
|
|
1092
|
+
position: Position;
|
|
1093
|
+
/**
|
|
1094
|
+
* An optional related source range that provides additional context
|
|
1095
|
+
* (e.g. the opening tag position when reporting a missing close tag).
|
|
1096
|
+
*/
|
|
1097
|
+
relatedPosition?: Position;
|
|
1098
|
+
}
|
|
1099
|
+
/**
|
|
1100
|
+
* The result of parsing a Wikidot markup string.
|
|
1101
|
+
*
|
|
1102
|
+
* Contains both the parsed AST and any diagnostics emitted during parsing.
|
|
1103
|
+
* The AST is always produced, even when diagnostics are present — the parser
|
|
1104
|
+
* is lenient and recovers from errors.
|
|
1105
|
+
*
|
|
1106
|
+
* @example
|
|
1107
|
+
* ```ts
|
|
1108
|
+
* import { parse } from "@wdprlib/parser";
|
|
1109
|
+
*
|
|
1110
|
+
* const result = parse("**bold** and //italic//");
|
|
1111
|
+
* console.log(result.ast.elements); // AST nodes
|
|
1112
|
+
* console.log(result.diagnostics); // [] (no issues)
|
|
1113
|
+
* ```
|
|
1114
|
+
*
|
|
1115
|
+
* @since 2.0.0
|
|
1116
|
+
* @group Diagnostics
|
|
1117
|
+
*/
|
|
1118
|
+
interface ParseResult {
|
|
1119
|
+
/** The parsed syntax tree. */
|
|
1120
|
+
ast: SyntaxTree;
|
|
1121
|
+
/** Diagnostics emitted during parsing (empty when the input is clean). */
|
|
1122
|
+
diagnostics: Diagnostic[];
|
|
1123
|
+
}
|
|
1124
|
+
/**
|
|
1045
1125
|
* Sentinel prefix for style slot placeholders in {@link SyntaxTree.styles}.
|
|
1046
1126
|
*
|
|
1047
1127
|
* When the resolver encounters an unresolved `[[iftags]]` block containing
|
|
@@ -1160,4 +1240,4 @@ declare const DEFAULT_SETTINGS: WikitextSettings;
|
|
|
1160
1240
|
* @group Core
|
|
1161
1241
|
*/
|
|
1162
1242
|
type Version = "wikidot";
|
|
1163
|
-
export { text, paragraph, listItemSubList, listItemElements, list, link, lineBreak, italics, isStringContainerType, isParagraphSafe, isHeaderType, isContainerTypeParagraphSafe, isAlignType, horizontalRule, heading, createSettings, createPosition, createPoint, container, bold, WikitextSettings, WikitextMode, Version, VariableMap, UserData, TocEntry, TableRow, TableOfContentsData, TableData, TableCell, TabData, SyntaxTree, StringContainerType, STYLE_SLOT_PREFIX, Position, Point, PageRef, Module, MathInlineData, MathData, ListType, ListItem, ListData, LinkType, LinkLocation, LinkLabel, LinkData, IncludeData, ImageSource, ImageData, IframeData, IfTagsData, IfExprData, IfCondData, HtmlData, HeadingLevel, Heading, HeaderType, FootnoteBlockData, FloatAlignment, ExprData, EmbedBlockData, Embed, ElementOf, ElementName, ElementDataMap, ElementData, Element, DefinitionListItem, DateItem, DateData, DEFAULT_SETTINGS, ContainerType, ContainerData, ColorData, CollapsibleData, CodeBlockData, ClearFloat, BibliographyCiteData, BibliographyBlockData, AttributeMap, AnchorTarget, AnchorData, Alignment, AlignType };
|
|
1243
|
+
export { text, paragraph, listItemSubList, listItemElements, list, link, lineBreak, italics, isStringContainerType, isParagraphSafe, isHeaderType, isContainerTypeParagraphSafe, isAlignType, horizontalRule, heading, createSettings, createPosition, createPoint, container, bold, WikitextSettings, WikitextMode, Version, VariableMap, UserData, TocEntry, TableRow, TableOfContentsData, TableData, TableCell, TabData, SyntaxTree, StringContainerType, STYLE_SLOT_PREFIX, Position, Point, ParseResult, PageRef, Module, MathInlineData, MathData, ListType, ListItem, ListData, LinkType, LinkLocation, LinkLabel, LinkData, IncludeData, ImageSource, ImageData, IframeData, IfTagsData, IfExprData, IfCondData, HtmlData, HeadingLevel, Heading, HeaderType, FootnoteBlockData, FloatAlignment, ExprData, EmbedBlockData, Embed, ElementOf, ElementName, ElementDataMap, ElementData, Element, DiagnosticSeverity, Diagnostic, DefinitionListItem, DateItem, DateData, DEFAULT_SETTINGS, ContainerType, ContainerData, ColorData, CollapsibleData, CodeBlockData, ClearFloat, BibliographyCiteData, BibliographyBlockData, AttributeMap, AnchorTarget, AnchorData, Alignment, AlignType };
|
package/dist/index.d.ts
CHANGED
|
@@ -1042,6 +1042,86 @@ declare function isContainerTypeParagraphSafe(type: ContainerType): boolean;
|
|
|
1042
1042
|
*/
|
|
1043
1043
|
declare function isParagraphSafe(element: Element): boolean;
|
|
1044
1044
|
/**
|
|
1045
|
+
* Severity level of a diagnostic.
|
|
1046
|
+
*
|
|
1047
|
+
* - `"error"` — the markup is structurally broken (e.g. inline `[[div]]`
|
|
1048
|
+
* without a newline after `]]`).
|
|
1049
|
+
* - `"warning"` — the markup is likely unintentional but the parser can
|
|
1050
|
+
* recover (e.g. a missing `[[/div]]` close tag).
|
|
1051
|
+
* - `"info"` — informational hints (e.g. deprecated syntax).
|
|
1052
|
+
*
|
|
1053
|
+
* @since 2.0.0
|
|
1054
|
+
* @group Diagnostics
|
|
1055
|
+
*/
|
|
1056
|
+
type DiagnosticSeverity = "error" | "warning" | "info";
|
|
1057
|
+
/**
|
|
1058
|
+
* A single diagnostic emitted during parsing.
|
|
1059
|
+
*
|
|
1060
|
+
* Each diagnostic pinpoints a source location via {@link Position} and
|
|
1061
|
+
* carries a machine-readable {@link Diagnostic.code | code} string for
|
|
1062
|
+
* programmatic filtering (e.g. `"unclosed-block"`, `"inline-block-element"`).
|
|
1063
|
+
*
|
|
1064
|
+
* @example
|
|
1065
|
+
* ```ts
|
|
1066
|
+
* import { parse } from "@wdprlib/parser";
|
|
1067
|
+
*
|
|
1068
|
+
* const { ast, diagnostics } = parse("[[div]]\nHello");
|
|
1069
|
+
* for (const d of diagnostics) {
|
|
1070
|
+
* console.log(`[${d.severity}] ${d.message} (line ${d.position.start.line})`);
|
|
1071
|
+
* }
|
|
1072
|
+
* ```
|
|
1073
|
+
*
|
|
1074
|
+
* @since 2.0.0
|
|
1075
|
+
* @group Diagnostics
|
|
1076
|
+
*/
|
|
1077
|
+
interface Diagnostic {
|
|
1078
|
+
/** How severe the issue is. */
|
|
1079
|
+
severity: DiagnosticSeverity;
|
|
1080
|
+
/**
|
|
1081
|
+
* Machine-readable identifier for the diagnostic kind.
|
|
1082
|
+
*
|
|
1083
|
+
* Current codes:
|
|
1084
|
+
* - `"unclosed-block"` — a block element has no matching close tag.
|
|
1085
|
+
* - `"inline-block-element"` — a block element (e.g. `[[div]]`) is used
|
|
1086
|
+
* inline without the required trailing newline.
|
|
1087
|
+
*/
|
|
1088
|
+
code: string;
|
|
1089
|
+
/** Human-readable description of the issue. */
|
|
1090
|
+
message: string;
|
|
1091
|
+
/** Source range where the issue was detected. */
|
|
1092
|
+
position: Position;
|
|
1093
|
+
/**
|
|
1094
|
+
* An optional related source range that provides additional context
|
|
1095
|
+
* (e.g. the opening tag position when reporting a missing close tag).
|
|
1096
|
+
*/
|
|
1097
|
+
relatedPosition?: Position;
|
|
1098
|
+
}
|
|
1099
|
+
/**
|
|
1100
|
+
* The result of parsing a Wikidot markup string.
|
|
1101
|
+
*
|
|
1102
|
+
* Contains both the parsed AST and any diagnostics emitted during parsing.
|
|
1103
|
+
* The AST is always produced, even when diagnostics are present — the parser
|
|
1104
|
+
* is lenient and recovers from errors.
|
|
1105
|
+
*
|
|
1106
|
+
* @example
|
|
1107
|
+
* ```ts
|
|
1108
|
+
* import { parse } from "@wdprlib/parser";
|
|
1109
|
+
*
|
|
1110
|
+
* const result = parse("**bold** and //italic//");
|
|
1111
|
+
* console.log(result.ast.elements); // AST nodes
|
|
1112
|
+
* console.log(result.diagnostics); // [] (no issues)
|
|
1113
|
+
* ```
|
|
1114
|
+
*
|
|
1115
|
+
* @since 2.0.0
|
|
1116
|
+
* @group Diagnostics
|
|
1117
|
+
*/
|
|
1118
|
+
interface ParseResult {
|
|
1119
|
+
/** The parsed syntax tree. */
|
|
1120
|
+
ast: SyntaxTree;
|
|
1121
|
+
/** Diagnostics emitted during parsing (empty when the input is clean). */
|
|
1122
|
+
diagnostics: Diagnostic[];
|
|
1123
|
+
}
|
|
1124
|
+
/**
|
|
1045
1125
|
* Sentinel prefix for style slot placeholders in {@link SyntaxTree.styles}.
|
|
1046
1126
|
*
|
|
1047
1127
|
* When the resolver encounters an unresolved `[[iftags]]` block containing
|
|
@@ -1160,4 +1240,4 @@ declare const DEFAULT_SETTINGS: WikitextSettings;
|
|
|
1160
1240
|
* @group Core
|
|
1161
1241
|
*/
|
|
1162
1242
|
type Version = "wikidot";
|
|
1163
|
-
export { text, paragraph, listItemSubList, listItemElements, list, link, lineBreak, italics, isStringContainerType, isParagraphSafe, isHeaderType, isContainerTypeParagraphSafe, isAlignType, horizontalRule, heading, createSettings, createPosition, createPoint, container, bold, WikitextSettings, WikitextMode, Version, VariableMap, UserData, TocEntry, TableRow, TableOfContentsData, TableData, TableCell, TabData, SyntaxTree, StringContainerType, STYLE_SLOT_PREFIX, Position, Point, PageRef, Module, MathInlineData, MathData, ListType, ListItem, ListData, LinkType, LinkLocation, LinkLabel, LinkData, IncludeData, ImageSource, ImageData, IframeData, IfTagsData, IfExprData, IfCondData, HtmlData, HeadingLevel, Heading, HeaderType, FootnoteBlockData, FloatAlignment, ExprData, EmbedBlockData, Embed, ElementOf, ElementName, ElementDataMap, ElementData, Element, DefinitionListItem, DateItem, DateData, DEFAULT_SETTINGS, ContainerType, ContainerData, ColorData, CollapsibleData, CodeBlockData, ClearFloat, BibliographyCiteData, BibliographyBlockData, AttributeMap, AnchorTarget, AnchorData, Alignment, AlignType };
|
|
1243
|
+
export { text, paragraph, listItemSubList, listItemElements, list, link, lineBreak, italics, isStringContainerType, isParagraphSafe, isHeaderType, isContainerTypeParagraphSafe, isAlignType, horizontalRule, heading, createSettings, createPosition, createPoint, container, bold, WikitextSettings, WikitextMode, Version, VariableMap, UserData, TocEntry, TableRow, TableOfContentsData, TableData, TableCell, TabData, SyntaxTree, StringContainerType, STYLE_SLOT_PREFIX, Position, Point, ParseResult, PageRef, Module, MathInlineData, MathData, ListType, ListItem, ListData, LinkType, LinkLocation, LinkLabel, LinkData, IncludeData, ImageSource, ImageData, IframeData, IfTagsData, IfExprData, IfCondData, HtmlData, HeadingLevel, Heading, HeaderType, FootnoteBlockData, FloatAlignment, ExprData, EmbedBlockData, Embed, ElementOf, ElementName, ElementDataMap, ElementData, Element, DiagnosticSeverity, Diagnostic, DefinitionListItem, DateItem, DateData, DEFAULT_SETTINGS, ContainerType, ContainerData, ColorData, CollapsibleData, CodeBlockData, ClearFloat, BibliographyCiteData, BibliographyBlockData, AttributeMap, AnchorTarget, AnchorData, Alignment, AlignType };
|