@wdprlib/parser 5.3.0 → 5.4.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 +2074 -1137
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2074 -1137
- package/package.json +3 -2
- package/src/build-info.generated.ts +2 -2
- package/src/lexer/lexer.ts +34 -5
- package/src/lexer/quoted-string.ts +4 -4
- package/src/lexer/syntax-actions.ts +6 -1
- package/src/lexer/text-actions.ts +15 -1
- package/src/lexer/url-schemes.ts +78 -0
- package/src/parser/constants.ts +4 -0
- package/src/parser/parse/block.ts +1 -1
- package/src/parser/postprocess/divAdjacentParagraph.ts +23 -21
- package/src/parser/postprocess/spanStrip/merge.ts +8 -2
- package/src/parser/preprocess/typography.ts +25 -3
- package/src/parser/preprocess/utils/raw-regions.ts +59 -14
- package/src/parser/preprocess/whitespace/index.ts +8 -1
- package/src/parser/rules/block/bibliography/entry-content.ts +1 -1
- package/src/parser/rules/block/block-list/bare-content.ts +3 -1
- package/src/parser/rules/block/block-list/bare-paragraph.ts +7 -2
- package/src/parser/rules/block/block-list/item-content.ts +7 -3
- package/src/parser/rules/block/block-list/li-content.ts +8 -3
- package/src/parser/rules/block/block-list/li-item.ts +1 -1
- package/src/parser/rules/block/blockquote/build.ts +1 -1
- package/src/parser/rules/block/code/boundary.ts +76 -0
- package/src/parser/rules/block/code/content.ts +11 -40
- package/src/parser/rules/block/code/index.ts +8 -31
- package/src/parser/rules/block/code/open.ts +46 -0
- package/src/parser/rules/block/definition-list/item-key.ts +1 -1
- package/src/parser/rules/block/definition-list/item-value.ts +1 -1
- package/src/parser/rules/block/div/failed.ts +2 -0
- package/src/parser/rules/block/index.ts +3 -0
- package/src/parser/rules/block/list/line.ts +6 -3
- package/src/parser/rules/block/math/boundary.ts +104 -0
- package/src/parser/rules/block/math/index.ts +17 -57
- package/src/parser/rules/block/note/boundary.ts +88 -0
- package/src/parser/rules/block/note/index.ts +37 -0
- package/src/parser/rules/block/paragraph/index.ts +12 -4
- package/src/parser/rules/block/paragraph/normalize.ts +6 -1
- package/src/parser/rules/block/parsing/block-item.ts +1 -1
- package/src/parser/rules/block/parsing/content.ts +1 -1
- package/src/parser/rules/block/parsing/inline-content.ts +6 -3
- package/src/parser/rules/block/table/pipe/cell.ts +3 -1
- package/src/parser/rules/block/table-block/cell-content/index.ts +1 -1
- package/src/parser/rules/block/table-block/cell-content/segments.ts +5 -2
- package/src/parser/rules/block/table-block/cell-newline.ts +2 -1
- package/src/parser/rules/contracts/rule.ts +4 -2
- package/src/parser/rules/contracts/scope.ts +2 -0
- package/src/parser/rules/inline/anchor/child.ts +8 -2
- package/src/parser/rules/inline/anchor/content.ts +3 -1
- package/src/parser/rules/inline/anchor/index.ts +4 -1
- package/src/parser/rules/inline/anchor/newline.ts +2 -1
- package/src/parser/rules/inline/autolink.ts +153 -0
- package/src/parser/rules/inline/button/attributes.ts +17 -0
- package/src/parser/rules/inline/button/index.ts +17 -0
- package/src/parser/rules/inline/button/syntax.ts +56 -0
- package/src/parser/rules/inline/date/index.ts +17 -0
- package/src/parser/rules/inline/date/syntax.ts +46 -0
- package/src/parser/rules/inline/email/candidates.ts +134 -0
- package/src/parser/rules/inline/email/index.ts +36 -0
- package/src/parser/rules/inline/email/scan.ts +76 -0
- package/src/parser/rules/inline/expr/branch.ts +3 -1
- package/src/parser/rules/inline/footnote/boundary.ts +56 -0
- package/src/parser/rules/inline/footnote/content.ts +29 -41
- package/src/parser/rules/inline/footnote/elements.ts +9 -34
- package/src/parser/rules/inline/footnote/index.ts +4 -1
- package/src/parser/rules/inline/formatting/close.ts +12 -0
- package/src/parser/rules/inline/index.ts +14 -0
- package/src/parser/rules/inline/line-break/newline.ts +8 -1
- package/src/parser/rules/inline/link-bracket/direct-url.ts +11 -3
- package/src/parser/rules/inline/link-bracket/parsed.ts +9 -4
- package/src/parser/rules/inline/link-bracket/parts.ts +14 -36
- package/src/parser/rules/inline/link-bracket/special-target.ts +9 -0
- package/src/parser/rules/inline/link-single.ts +9 -7
- package/src/parser/rules/inline/link-triple/index.ts +1 -0
- package/src/parser/rules/inline/link-triple/label.ts +7 -1
- package/src/parser/rules/inline/parsing/automatic-line-break.ts +35 -0
- package/src/parser/rules/inline/parsing/block-boundary.ts +2 -0
- package/src/parser/rules/inline/parsing/block-start-predicates.ts +10 -0
- package/src/parser/rules/inline/parsing/inline-content.ts +36 -6
- package/src/parser/rules/inline/parsing/plain-text.ts +7 -2
- package/src/parser/rules/inline/parsing/preserved-line-break.ts +13 -0
- package/src/parser/rules/inline/parsing/raw-tag.ts +19 -0
- package/src/parser/rules/inline/raw/angle.ts +2 -1
- package/src/parser/rules/inline/raw/end.ts +21 -1
- package/src/parser/rules/inline/size/content.ts +1 -1
- package/src/parser/rules/inline/size/value.ts +11 -0
- package/src/parser/rules/inline/social/index.ts +17 -0
- package/src/parser/rules/inline/social/syntax.ts +40 -0
- package/src/parser/rules/inline/span/content.ts +3 -1
- package/src/parser/rules/inline/span/newline.ts +2 -1
- package/src/parser/rules/opaque-probe.ts +58 -0
- package/src/parser/rules/block/math/content.ts +0 -54
- package/src/parser/rules/block/math/name.ts +0 -35
- package/src/parser/rules/inline/footnote/child.ts +0 -22
- package/src/parser/rules/inline/footnote/newline.ts +0 -27
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { BlockRule, InlineRule, ParseContext } from "./types";
|
|
2
|
+
import { findCodeOpen } from "./block/code/open";
|
|
3
|
+
import { findCodeBodyBounds } from "./block/code/boundary";
|
|
4
|
+
import { findMathOpen, findMathBodyBounds } from "./block/math/boundary";
|
|
5
|
+
|
|
6
|
+
/** Probe opaque syntax without registering its code, footnotes or diagnostics. */
|
|
7
|
+
export function createOpaqueProbe(ctx: ParseContext): ParseContext {
|
|
8
|
+
return {
|
|
9
|
+
...ctx,
|
|
10
|
+
diagnostics: [],
|
|
11
|
+
footnotes: [],
|
|
12
|
+
tocEntries: [],
|
|
13
|
+
codeBlocks: [],
|
|
14
|
+
htmlBlocks: [],
|
|
15
|
+
bibcites: [],
|
|
16
|
+
scope: {
|
|
17
|
+
...ctx.scope,
|
|
18
|
+
inlineEnd: undefined,
|
|
19
|
+
tableFormatting: undefined,
|
|
20
|
+
blockCloseCondition: () => true,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function opaqueRuleEnd(
|
|
26
|
+
probe: ParseContext,
|
|
27
|
+
pos: number,
|
|
28
|
+
rules: readonly (BlockRule | InlineRule)[],
|
|
29
|
+
requireClosed: boolean = false,
|
|
30
|
+
): number {
|
|
31
|
+
const token = probe.tokens[pos];
|
|
32
|
+
if (!token) return pos;
|
|
33
|
+
probe.pos = pos;
|
|
34
|
+
for (const rule of rules) {
|
|
35
|
+
if (!rule.startTokens.includes(token.type)) continue;
|
|
36
|
+
if (rule.name === "code") {
|
|
37
|
+
const open = findCodeOpen(probe.tokens, pos);
|
|
38
|
+
if (!open) continue;
|
|
39
|
+
if (open.closingSwallowed) {
|
|
40
|
+
if (!requireClosed) return open.bodyStart;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
const bounds = findCodeBodyBounds(probe.tokens, open.bodyStart);
|
|
44
|
+
if (!requireClosed || bounds.foundClose) return bounds.end;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (rule.name === "math") {
|
|
48
|
+
const open = findMathOpen(probe.tokens, pos);
|
|
49
|
+
if (!open) continue;
|
|
50
|
+
const bounds = findMathBodyBounds(probe.tokens, open.bodyStart);
|
|
51
|
+
if (bounds.hasContent && (!requireClosed || bounds.foundClose)) return bounds.end;
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const result = rule.parse(probe);
|
|
55
|
+
if (result.success) return pos + result.consumed;
|
|
56
|
+
}
|
|
57
|
+
return pos;
|
|
58
|
+
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type { ParseContext } from "../../types";
|
|
2
|
-
import { parseBlockName } from "../utils";
|
|
3
|
-
|
|
4
|
-
export interface MathContentResult {
|
|
5
|
-
latexSource: string;
|
|
6
|
-
consumed: number;
|
|
7
|
-
foundClose: boolean;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function collectMathContent(ctx: ParseContext, startPos: number): MathContentResult {
|
|
11
|
-
let latexSource = "";
|
|
12
|
-
let pos = startPos;
|
|
13
|
-
let consumed = 0;
|
|
14
|
-
let foundClose = false;
|
|
15
|
-
|
|
16
|
-
while (pos < ctx.tokens.length) {
|
|
17
|
-
const token = ctx.tokens[pos];
|
|
18
|
-
if (!token) break;
|
|
19
|
-
|
|
20
|
-
if (token.type === "BLOCK_END_OPEN") {
|
|
21
|
-
const closeNameResult = parseBlockName(ctx, pos + 1);
|
|
22
|
-
if (closeNameResult?.name === "math") {
|
|
23
|
-
foundClose = true;
|
|
24
|
-
break;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
latexSource += token.type === "BACKSLASH_BREAK" ? "\\\n" : token.value;
|
|
29
|
-
pos++;
|
|
30
|
-
consumed++;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return { latexSource, consumed, foundClose };
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function consumeMathClose(ctx: ParseContext, startPos: number): number {
|
|
37
|
-
let pos = startPos + 1;
|
|
38
|
-
let consumed = 1;
|
|
39
|
-
|
|
40
|
-
const closeNameResult = parseBlockName(ctx, pos);
|
|
41
|
-
if (closeNameResult) {
|
|
42
|
-
pos += closeNameResult.consumed;
|
|
43
|
-
consumed += closeNameResult.consumed;
|
|
44
|
-
}
|
|
45
|
-
if (ctx.tokens[pos]?.type === "BLOCK_CLOSE") {
|
|
46
|
-
pos++;
|
|
47
|
-
consumed++;
|
|
48
|
-
}
|
|
49
|
-
if (ctx.tokens[pos]?.type === "NEWLINE") {
|
|
50
|
-
consumed++;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return consumed;
|
|
54
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { ParseContext } from "../../types";
|
|
2
|
-
|
|
3
|
-
export interface MathNameResult {
|
|
4
|
-
name: string | null;
|
|
5
|
-
consumed: number;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function parseMathName(ctx: ParseContext, startPos: number): MathNameResult {
|
|
9
|
-
let pos = startPos;
|
|
10
|
-
let consumed = 0;
|
|
11
|
-
let name = "";
|
|
12
|
-
|
|
13
|
-
const first = ctx.tokens[pos];
|
|
14
|
-
if (first?.type !== "IDENTIFIER" && first?.type !== "TEXT") {
|
|
15
|
-
return { name: null, consumed: 0 };
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
while (pos < ctx.tokens.length) {
|
|
19
|
-
const token = ctx.tokens[pos];
|
|
20
|
-
if (
|
|
21
|
-
!token ||
|
|
22
|
-
token.type === "BLOCK_CLOSE" ||
|
|
23
|
-
token.type === "WHITESPACE" ||
|
|
24
|
-
token.type === "NEWLINE"
|
|
25
|
-
) {
|
|
26
|
-
break;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
name += token.value;
|
|
30
|
-
pos++;
|
|
31
|
-
consumed++;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return { name: name === "" ? null : name, consumed };
|
|
35
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { Element } from "@wdprlib/ast";
|
|
2
|
-
import type { ParseContext } from "../../types";
|
|
3
|
-
import { parseInlineUntil } from "../utils";
|
|
4
|
-
|
|
5
|
-
export interface FootnoteChildResult {
|
|
6
|
-
elements: Element[];
|
|
7
|
-
consumed: number;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function parseFootnoteChild(ctx: ParseContext, pos: number): FootnoteChildResult {
|
|
11
|
-
const token = ctx.tokens[pos];
|
|
12
|
-
if (!token) {
|
|
13
|
-
return { elements: [], consumed: 0 };
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const inlineResult = parseInlineUntil({ ...ctx, pos }, "BLOCK_END_OPEN");
|
|
17
|
-
if (inlineResult.elements.length > 0) {
|
|
18
|
-
return { elements: inlineResult.elements, consumed: inlineResult.consumed };
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return { elements: [{ element: "text", data: token.value }], consumed: 1 };
|
|
22
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { ParseContext } from "../../types";
|
|
2
|
-
|
|
3
|
-
export interface FootnoteNewlineResult {
|
|
4
|
-
consumed: number;
|
|
5
|
-
paragraphBreak: boolean;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function consumeFootnoteNewline(ctx: ParseContext, pos: number): FootnoteNewlineResult {
|
|
9
|
-
let nextPos = pos + 1;
|
|
10
|
-
let consumed = 1;
|
|
11
|
-
|
|
12
|
-
while (ctx.tokens[nextPos]?.type === "WHITESPACE") {
|
|
13
|
-
nextPos++;
|
|
14
|
-
consumed++;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
if (ctx.tokens[nextPos]?.type !== "NEWLINE") {
|
|
18
|
-
return { consumed, paragraphBreak: false };
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
while (ctx.tokens[nextPos]?.type === "NEWLINE") {
|
|
22
|
-
nextPos++;
|
|
23
|
-
consumed++;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return { consumed, paragraphBreak: true };
|
|
27
|
-
}
|