@wdprlib/parser 5.2.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 +2211 -1182
- package/dist/index.d.cts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +2211 -1182
- 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/module/listpages/resolution/items.ts +2 -2
- package/src/parser/rules/block/module/listpages/resolution/pager.ts +43 -0
- package/src/parser/rules/block/module/listpages/resolution/wrapper.ts +6 -1
- package/src/parser/rules/block/module/listpages/resolve.ts +1 -1
- package/src/parser/rules/block/module/listpages/types/external-data.ts +13 -0
- package/src/parser/rules/block/module/listpages/url-resolution/params.ts +5 -4
- package/src/parser/rules/block/module/resolution/data-maps.ts +75 -3
- package/src/parser/rules/block/module/resolution/resolve-async.ts +12 -3
- 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/pipeline/process.ts +8 -1
- 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
|
@@ -2,6 +2,7 @@ import type { Element } from "@wdprlib/ast";
|
|
|
2
2
|
|
|
3
3
|
type PreservedLineBreak = Extract<Element, { element: "line-break" }> & {
|
|
4
4
|
_preservedTrailingBreak?: boolean;
|
|
5
|
+
_preservedLeadingBreak?: boolean;
|
|
5
6
|
};
|
|
6
7
|
|
|
7
8
|
export function createPreservedTrailingLineBreak(): Element {
|
|
@@ -9,3 +10,15 @@ export function createPreservedTrailingLineBreak(): Element {
|
|
|
9
10
|
lineBreak._preservedTrailingBreak = true;
|
|
10
11
|
return lineBreak;
|
|
11
12
|
}
|
|
13
|
+
|
|
14
|
+
export function createPreservedLeadingLineBreak(): Element {
|
|
15
|
+
const lineBreak: PreservedLineBreak = { element: "line-break", _preservedLeadingBreak: true };
|
|
16
|
+
return lineBreak;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function isPreservedLeadingLineBreak(element: Element | undefined): boolean {
|
|
20
|
+
return (
|
|
21
|
+
element?.element === "line-break" &&
|
|
22
|
+
(element as PreservedLineBreak)._preservedLeadingBreak === true
|
|
23
|
+
);
|
|
24
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Token } from "../../../../lexer";
|
|
2
|
+
|
|
3
|
+
const unclosedRanges = new WeakMap<readonly Token[], { start: number; end: number }>();
|
|
4
|
+
|
|
5
|
+
/** Raw directives end at the first ]], even inside a quoted value. */
|
|
6
|
+
export function findRawTagClose(
|
|
7
|
+
tokens: readonly Token[],
|
|
8
|
+
start: number,
|
|
9
|
+
end: number,
|
|
10
|
+
): number | null {
|
|
11
|
+
const unclosed = unclosedRanges.get(tokens);
|
|
12
|
+
if (unclosed && start >= unclosed.start && end <= unclosed.end) return null;
|
|
13
|
+
for (let close = start; close < end; close++) {
|
|
14
|
+
if (tokens[close]?.type === "BLOCK_CLOSE") return close;
|
|
15
|
+
if (!tokens[close] || tokens[close]?.type === "EOF") break;
|
|
16
|
+
}
|
|
17
|
+
unclosedRanges.set(tokens, { start, end });
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Element } from "@wdprlib/ast";
|
|
2
|
+
import { decodeHTML } from "entities";
|
|
2
3
|
import type { ParseContext, RuleResult } from "../../types";
|
|
3
4
|
import { currentToken, hasClosingMarkerBeforeNewline } from "../../types";
|
|
4
5
|
import { rawElement, textElement } from "./result";
|
|
@@ -36,5 +37,5 @@ export function parseAngleRaw(ctx: ParseContext): RuleResult<Element> {
|
|
|
36
37
|
consumed++;
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
return rawElement(value, consumed);
|
|
40
|
+
return rawElement(decodeHTML(value), consumed);
|
|
40
41
|
}
|
|
@@ -1,15 +1,35 @@
|
|
|
1
1
|
import type { Token } from "../../../../lexer";
|
|
2
2
|
|
|
3
|
+
// A failed angle-raw search also rules out later openers within the same immutable token range.
|
|
4
|
+
const unclosedAngleRanges = new WeakMap<
|
|
5
|
+
readonly Token[],
|
|
6
|
+
{ start: number; end: number; lineEnd: boolean }
|
|
7
|
+
>();
|
|
8
|
+
|
|
3
9
|
/** Exclusive end of a complete single-line raw region, or the original position. */
|
|
4
10
|
export function rawRegionEnd(tokens: readonly Token[], start: number, end: number): number {
|
|
5
11
|
const type = tokens[start]?.type;
|
|
6
12
|
const close =
|
|
7
13
|
type === "RAW_OPEN" ? "RAW_OPEN" : type === "RAW_BLOCK_OPEN" ? "RAW_BLOCK_CLOSE" : null;
|
|
8
14
|
if (!close) return start;
|
|
15
|
+
const cached = type === "RAW_BLOCK_OPEN" ? unclosedAngleRanges.get(tokens) : undefined;
|
|
16
|
+
if (
|
|
17
|
+
cached &&
|
|
18
|
+
start >= cached.start &&
|
|
19
|
+
start < cached.end &&
|
|
20
|
+
(cached.lineEnd || end <= cached.end)
|
|
21
|
+
) {
|
|
22
|
+
return start;
|
|
23
|
+
}
|
|
9
24
|
for (let pos = start + 1; pos < end; pos++) {
|
|
10
|
-
if (tokens[pos]?.type === "NEWLINE" || tokens[pos]?.type === "EOF")
|
|
25
|
+
if (tokens[pos]?.type === "NEWLINE" || tokens[pos]?.type === "EOF") {
|
|
26
|
+
if (type === "RAW_BLOCK_OPEN")
|
|
27
|
+
unclosedAngleRanges.set(tokens, { start, end: pos, lineEnd: true });
|
|
28
|
+
return start;
|
|
29
|
+
}
|
|
11
30
|
if (tokens[pos]?.type === close) return pos + 1;
|
|
12
31
|
}
|
|
32
|
+
if (type === "RAW_BLOCK_OPEN") unclosedAngleRanges.set(tokens, { start, end, lineEnd: false });
|
|
13
33
|
return start;
|
|
14
34
|
}
|
|
15
35
|
|
|
@@ -32,7 +32,7 @@ export function parseSizeContent(ctx: ParseContext, startPos: number): SizeConte
|
|
|
32
32
|
const inlineCtx: ParseContext = { ...ctx, pos };
|
|
33
33
|
const inlineResult = parseInlineUntil(inlineCtx, "BLOCK_END_OPEN");
|
|
34
34
|
if (inlineResult.elements.length > 0) {
|
|
35
|
-
|
|
35
|
+
for (const element of inlineResult.elements) children.push(element);
|
|
36
36
|
pos += inlineResult.consumed;
|
|
37
37
|
consumed += inlineResult.consumed;
|
|
38
38
|
} else {
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import type { ParseContext } from "../../types";
|
|
2
2
|
|
|
3
3
|
const VALID_SIZE_UNITS = ["px", "em", "rem", "ex", "%", "cm", "mm", "in", "pc"];
|
|
4
|
+
const VALID_SIZE_KEYWORDS = [
|
|
5
|
+
"smaller",
|
|
6
|
+
"larger",
|
|
7
|
+
"xx-small",
|
|
8
|
+
"x-small",
|
|
9
|
+
"small",
|
|
10
|
+
"large",
|
|
11
|
+
"x-large",
|
|
12
|
+
"xx-large",
|
|
13
|
+
];
|
|
4
14
|
|
|
5
15
|
export function parseSizeValue(
|
|
6
16
|
ctx: ParseContext,
|
|
@@ -40,6 +50,7 @@ export function parseSizeValue(
|
|
|
40
50
|
}
|
|
41
51
|
|
|
42
52
|
function isValidSizeValue(size: string): boolean {
|
|
53
|
+
if (VALID_SIZE_KEYWORDS.includes(size)) return true;
|
|
43
54
|
const unitPattern = VALID_SIZE_UNITS.join("|");
|
|
44
55
|
return new RegExp(`^(\\d+(?:\\.\\d+)?)(${unitPattern})$`, "i").test(size);
|
|
45
56
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { InlineRule } from "../../types";
|
|
2
|
+
import { parseSocialSyntax } from "./syntax";
|
|
3
|
+
|
|
4
|
+
export const socialRule: InlineRule = {
|
|
5
|
+
name: "social",
|
|
6
|
+
startTokens: ["BLOCK_OPEN"],
|
|
7
|
+
parse(ctx) {
|
|
8
|
+
const result = parseSocialSyntax(ctx, ctx.pos, ctx.scope.inlineEnd ?? ctx.tokens.length);
|
|
9
|
+
return result
|
|
10
|
+
? {
|
|
11
|
+
success: true,
|
|
12
|
+
consumed: result.end - ctx.pos,
|
|
13
|
+
elements: [{ element: "social", data: result.data }],
|
|
14
|
+
}
|
|
15
|
+
: { success: false };
|
|
16
|
+
},
|
|
17
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { SocialData } from "@wdprlib/ast";
|
|
2
|
+
import type { Token } from "../../../../lexer";
|
|
3
|
+
import type { ParseContext } from "../../types";
|
|
4
|
+
import { findRawTagClose } from "../parsing/raw-tag";
|
|
5
|
+
|
|
6
|
+
const invalidBodies = new WeakMap<readonly Token[], { start: number; bracket: number }>();
|
|
7
|
+
|
|
8
|
+
export function parseSocialSyntax(
|
|
9
|
+
ctx: ParseContext,
|
|
10
|
+
start: number,
|
|
11
|
+
end: number,
|
|
12
|
+
): { data: SocialData; end: number } | null {
|
|
13
|
+
const tokens = ctx.tokens;
|
|
14
|
+
if (tokens[start]?.type !== "BLOCK_OPEN" || tokens[start + 1]?.value.toLowerCase() !== "social")
|
|
15
|
+
return null;
|
|
16
|
+
const bodyStart = start + 2;
|
|
17
|
+
if (tokens[bodyStart]?.type !== "BLOCK_CLOSE" && !/^\s+$/.test(tokens[bodyStart]?.value ?? ""))
|
|
18
|
+
return null;
|
|
19
|
+
const invalid = invalidBodies.get(tokens);
|
|
20
|
+
if (invalid && bodyStart >= invalid.start && bodyStart <= invalid.bracket) return null;
|
|
21
|
+
const close = findRawTagClose(tokens, bodyStart, end);
|
|
22
|
+
if (close === null) return null;
|
|
23
|
+
for (let pos = bodyStart; pos < close; pos++) {
|
|
24
|
+
if (tokens[pos]!.value.includes("]")) {
|
|
25
|
+
invalidBodies.set(tokens, { start: bodyStart, bracket: pos });
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const body = tokens
|
|
30
|
+
.slice(bodyStart, close)
|
|
31
|
+
.map((token) => token.value)
|
|
32
|
+
.join("");
|
|
33
|
+
const sites = body.trim()
|
|
34
|
+
? body
|
|
35
|
+
.split(",")
|
|
36
|
+
.map((site) => site.trim().toLowerCase())
|
|
37
|
+
.filter(Boolean)
|
|
38
|
+
: null;
|
|
39
|
+
return { data: { sites }, end: close + 1 };
|
|
40
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { stripAutomaticLineBreak } from "../parsing/automatic-line-break";
|
|
1
2
|
import { rawRegionEnd } from "../raw/end";
|
|
2
3
|
import type { Element } from "@wdprlib/ast";
|
|
3
4
|
import type { ParseContext } from "../../types";
|
|
@@ -118,7 +119,8 @@ function parseOneSpanChild(
|
|
|
118
119
|
for (const rule of getCandidateInlineRules(inlineRules, token.type)) {
|
|
119
120
|
const result = rule.parse(inlineCtx);
|
|
120
121
|
if (result.success) {
|
|
121
|
-
targetChildren
|
|
122
|
+
stripAutomaticLineBreak(targetChildren, result.stripLeadingLineBreak);
|
|
123
|
+
for (const element of result.elements) targetChildren.push(element);
|
|
122
124
|
return { consumed: result.consumed };
|
|
123
125
|
}
|
|
124
126
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createAutomaticLineBreak } from "../parsing/automatic-line-break";
|
|
1
2
|
import type { Element } from "@wdprlib/ast";
|
|
2
3
|
import type { ParseContext } from "../../types";
|
|
3
4
|
|
|
@@ -38,7 +39,7 @@ export function consumeSpanNewline(
|
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
const targetChildren = paragraphStrip && afterBlankLine ? escapedChildren : children;
|
|
41
|
-
targetChildren.push(
|
|
42
|
+
targetChildren.push(createAutomaticLineBreak(ctx.tokens[pos]!));
|
|
42
43
|
let consumed = 1;
|
|
43
44
|
let nextPos = pos + 1;
|
|
44
45
|
while (ctx.tokens[nextPos]?.type === "WHITESPACE" && ctx.tokens[nextPos]?.lineStart) {
|
|
@@ -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
|
+
}
|
package/src/pipeline/process.ts
CHANGED
|
@@ -82,6 +82,12 @@ export async function processWikitext<TPage extends WikitextPageContext>(
|
|
|
82
82
|
const dataProvider = createModuleDataProvider(options, callbackContext);
|
|
83
83
|
const parseFragment = parseSource;
|
|
84
84
|
let ast = initial.ast;
|
|
85
|
+
const paginationState = { nextUnprefixed: 1 };
|
|
86
|
+
const requestedPath = options.page.urlPath;
|
|
87
|
+
const urlPath =
|
|
88
|
+
!requestedPath || /^\/(?:[?#]|$)/.test(requestedPath)
|
|
89
|
+
? `/${options.page.fullName}${requestedPath?.slice(1) ?? ""}`
|
|
90
|
+
: requestedPath;
|
|
85
91
|
|
|
86
92
|
for (let pass = 0; pass < DEFAULT_MODULE_MAX_PASSES; pass++) {
|
|
87
93
|
const extraction = extractDataRequirements(ast);
|
|
@@ -94,7 +100,8 @@ export async function processWikitext<TPage extends WikitextPageContext>(
|
|
|
94
100
|
compiledListPagesTemplates: extraction.compiledListPagesTemplates,
|
|
95
101
|
compiledListUsersTemplates: extraction.compiledListUsersTemplates,
|
|
96
102
|
requirements: extraction.requirements,
|
|
97
|
-
urlPath
|
|
103
|
+
urlPath,
|
|
104
|
+
paginationState,
|
|
98
105
|
pageTags: options.page.tags,
|
|
99
106
|
});
|
|
100
107
|
ast = resolved.ast;
|
|
@@ -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
|
-
}
|