@openuji/speculator 0.5.3 → 0.5.4
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.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/parse/__tests__/html-in-markdown.test.d.ts +2 -0
- package/dist/parse/__tests__/html-in-markdown.test.d.ts.map +1 -0
- package/dist/parse/__tests__/html-in-markdown.test.js +83 -0
- package/dist/parse/__tests__/html-in-markdown.test.js.map +1 -0
- package/dist/parse/__tests__/pipeline.test.js +1 -8
- package/dist/parse/__tests__/pipeline.test.js.map +1 -1
- package/dist/parse/__tests__/shorthands.test.d.ts +5 -0
- package/dist/parse/__tests__/shorthands.test.d.ts.map +1 -0
- package/dist/parse/__tests__/shorthands.test.js +96 -0
- package/dist/parse/__tests__/shorthands.test.js.map +1 -0
- package/dist/parse/assembler.d.ts.map +1 -1
- package/dist/parse/assembler.js +18 -0
- package/dist/parse/assembler.js.map +1 -1
- package/dist/parse/html/InlinesHtmlParser.d.ts.map +1 -1
- package/dist/parse/html/InlinesHtmlParser.js +11 -1
- package/dist/parse/html/InlinesHtmlParser.js.map +1 -1
- package/dist/parse/html/parser.d.ts +1 -12
- package/dist/parse/html/parser.d.ts.map +1 -1
- package/dist/parse/html/parser.js +15 -47
- package/dist/parse/html/parser.js.map +1 -1
- package/dist/parse/index.d.ts +1 -1
- package/dist/parse/index.d.ts.map +1 -1
- package/dist/parse/index.js.map +1 -1
- package/dist/parse/markdown/HtmlBlockMarkdownParser.d.ts +13 -0
- package/dist/parse/markdown/HtmlBlockMarkdownParser.d.ts.map +1 -0
- package/dist/parse/markdown/HtmlBlockMarkdownParser.js +61 -0
- package/dist/parse/markdown/HtmlBlockMarkdownParser.js.map +1 -0
- package/dist/parse/markdown/HtmlInlinesMarkdownParser.d.ts +12 -0
- package/dist/parse/markdown/HtmlInlinesMarkdownParser.d.ts.map +1 -0
- package/dist/parse/markdown/HtmlInlinesMarkdownParser.js +187 -0
- package/dist/parse/markdown/HtmlInlinesMarkdownParser.js.map +1 -0
- package/dist/parse/markdown/HtmlParagraphMarkdownParser.d.ts +15 -0
- package/dist/parse/markdown/HtmlParagraphMarkdownParser.d.ts.map +1 -0
- package/dist/parse/markdown/HtmlParagraphMarkdownParser.js +67 -0
- package/dist/parse/markdown/HtmlParagraphMarkdownParser.js.map +1 -0
- package/dist/parse/markdown/ShorthandsMarkdownParser.d.ts +29 -0
- package/dist/parse/markdown/ShorthandsMarkdownParser.d.ts.map +1 -0
- package/dist/parse/markdown/ShorthandsMarkdownParser.js +200 -0
- package/dist/parse/markdown/ShorthandsMarkdownParser.js.map +1 -0
- package/dist/parse/markdown/parser.d.ts +3 -14
- package/dist/parse/markdown/parser.d.ts.map +1 -1
- package/dist/parse/markdown/parser.js +72 -47
- package/dist/parse/markdown/parser.js.map +1 -1
- package/dist/parse/parsers.d.ts +3 -0
- package/dist/parse/parsers.d.ts.map +1 -1
- package/dist/parse/parsers.js +10 -0
- package/dist/parse/parsers.js.map +1 -1
- package/dist/parse/pipeline.d.ts.map +1 -1
- package/dist/parse/pipeline.js +8 -20
- package/dist/parse/pipeline.js.map +1 -1
- package/dist/parse/registry.d.ts +50 -91
- package/dist/parse/registry.d.ts.map +1 -1
- package/dist/parse/registry.js +39 -58
- package/dist/parse/registry.js.map +1 -1
- package/dist/parse/types.d.ts +1 -23
- package/dist/parse/types.d.ts.map +1 -1
- package/dist/parse/types.js.map +1 -1
- package/dist/parse/utils/hast-utils.d.ts +30 -0
- package/dist/parse/utils/hast-utils.d.ts.map +1 -0
- package/dist/parse/utils/hast-utils.js +94 -0
- package/dist/parse/utils/hast-utils.js.map +1 -0
- package/dist/pipeline/runner.d.ts.map +1 -1
- package/dist/pipeline/runner.js +16 -12
- package/dist/pipeline/runner.js.map +1 -1
- package/dist/postprocess/index.d.ts +1 -1
- package/dist/postprocess/index.d.ts.map +1 -1
- package/dist/postprocess/index.js +3 -3
- package/dist/postprocess/index.js.map +1 -1
- package/dist/postprocess/plugins/citation-resolve.d.ts +8 -0
- package/dist/postprocess/plugins/citation-resolve.d.ts.map +1 -0
- package/dist/postprocess/plugins/citation-resolve.js +33 -0
- package/dist/postprocess/plugins/citation-resolve.js.map +1 -0
- package/dist/preprocess/__tests__/pipeline.test.js +33 -45
- package/dist/preprocess/__tests__/pipeline.test.js.map +1 -1
- package/dist/preprocess/__tests__/resolver.test.js +38 -40
- package/dist/preprocess/__tests__/resolver.test.js.map +1 -1
- package/dist/preprocess/config/__tests__/rules.test.d.ts +2 -0
- package/dist/preprocess/config/__tests__/rules.test.d.ts.map +1 -0
- package/dist/preprocess/config/__tests__/rules.test.js +212 -0
- package/dist/preprocess/config/__tests__/rules.test.js.map +1 -0
- package/dist/preprocess/config/doc-config.js +1 -1
- package/dist/preprocess/config/doc-config.js.map +1 -1
- package/dist/preprocess/config/index.d.ts +3 -4
- package/dist/preprocess/config/index.d.ts.map +1 -1
- package/dist/preprocess/config/index.js +2 -2
- package/dist/preprocess/config/index.js.map +1 -1
- package/dist/preprocess/config/loader.d.ts +12 -48
- package/dist/preprocess/config/loader.d.ts.map +1 -1
- package/dist/preprocess/config/loader.js +23 -13
- package/dist/preprocess/config/loader.js.map +1 -1
- package/dist/preprocess/config/normalize.d.ts +11 -6
- package/dist/preprocess/config/normalize.d.ts.map +1 -1
- package/dist/preprocess/config/normalize.js +58 -8
- package/dist/preprocess/config/normalize.js.map +1 -1
- package/dist/preprocess/config/types.d.ts +57 -22
- package/dist/preprocess/config/types.d.ts.map +1 -1
- package/dist/preprocess/include/index.d.ts +1 -1
- package/dist/preprocess/include/index.d.ts.map +1 -1
- package/dist/preprocess/include/index.js +1 -1
- package/dist/preprocess/include/index.js.map +1 -1
- package/dist/preprocess/include/resolver.d.ts +14 -8
- package/dist/preprocess/include/resolver.d.ts.map +1 -1
- package/dist/preprocess/include/resolver.js +27 -18
- package/dist/preprocess/include/resolver.js.map +1 -1
- package/dist/preprocess/index.d.ts +6 -6
- package/dist/preprocess/index.d.ts.map +1 -1
- package/dist/preprocess/index.js +4 -4
- package/dist/preprocess/index.js.map +1 -1
- package/dist/preprocess/pipeline.d.ts +19 -16
- package/dist/preprocess/pipeline.d.ts.map +1 -1
- package/dist/preprocess/pipeline.js +43 -45
- package/dist/preprocess/pipeline.js.map +1 -1
- package/dist/preprocess/types.d.ts +21 -46
- package/dist/preprocess/types.d.ts.map +1 -1
- package/dist/preprocess/types.js +0 -6
- package/dist/preprocess/types.js.map +1 -1
- package/dist/types/ast.generated.d.ts +21 -2
- package/dist/types/ast.generated.d.ts.map +1 -1
- package/dist/types/ast.generated.js +1 -1
- package/dist/types/ast.generated.js.map +1 -1
- package/package.json +1 -1
- package/schema/spec-ast.schema.json +40 -0
package/dist/parse/registry.d.ts
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Parse Handler Registry
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* Parser modules handle specific hast/mdast nodes and emit SpecAST nodes.
|
|
4
|
+
* Manages the registration and lookup of HTML and Markdown parser modules.
|
|
6
5
|
*/
|
|
7
|
-
import type { Element
|
|
6
|
+
import type { Element } from 'hast';
|
|
8
7
|
import type { RootContent as MdastRootContent } from 'mdast';
|
|
8
|
+
import type { Block, Inline, Section } from '#src/types/ast.generated';
|
|
9
9
|
import type { SourceUnit } from '#src/preprocess/types';
|
|
10
|
-
|
|
11
|
-
import type { ParseDiagnostic } from '#src/parse/types';
|
|
12
|
-
/**
|
|
13
|
-
* Node with optional position information
|
|
14
|
-
*/
|
|
10
|
+
/** Node with position info from standard parsers */
|
|
15
11
|
export interface NodeWithPosition {
|
|
16
12
|
position?: {
|
|
17
13
|
start: {
|
|
@@ -19,138 +15,101 @@ export interface NodeWithPosition {
|
|
|
19
15
|
column: number;
|
|
20
16
|
offset?: number;
|
|
21
17
|
};
|
|
22
|
-
end
|
|
18
|
+
end: {
|
|
23
19
|
line: number;
|
|
24
20
|
column: number;
|
|
25
21
|
offset?: number;
|
|
26
22
|
};
|
|
27
23
|
};
|
|
28
24
|
}
|
|
29
|
-
/**
|
|
30
|
-
|
|
31
|
-
*/
|
|
32
|
-
export type HandlerResult = Section | Block | Inline | (Section | Block)[] | Inline[] | null;
|
|
33
|
-
/**
|
|
34
|
-
* Block-level handler result
|
|
35
|
-
*/
|
|
36
|
-
export type BlockHandlerResult = Section | Block | (Section | Block)[] | null;
|
|
37
|
-
/**
|
|
38
|
-
* Inline-level handler result
|
|
39
|
-
*/
|
|
25
|
+
/** Result of a block-level parse handler */
|
|
26
|
+
export type BlockHandlerResult = Block | Section | (Block | Section)[] | null;
|
|
27
|
+
/** Result of an inline-level parse handler */
|
|
40
28
|
export type InlineHandlerResult = Inline | Inline[] | null;
|
|
29
|
+
/** Generic result type for either block or inline handler */
|
|
30
|
+
export type HandlerResult = BlockHandlerResult | InlineHandlerResult;
|
|
41
31
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* This is the common interface for both HTML and Markdown parser modules.
|
|
45
|
-
* Some methods may be no-ops depending on the format.
|
|
32
|
+
* Context provided to parser modules during transformation.
|
|
46
33
|
*/
|
|
47
34
|
export interface ParseContext {
|
|
48
|
-
/**
|
|
35
|
+
/** The source unit being parsed */
|
|
49
36
|
readonly unit: SourceUnit;
|
|
50
|
-
/** Create source position
|
|
51
|
-
createSourcePos(node: NodeWithPosition):
|
|
52
|
-
/** Transform
|
|
53
|
-
transformInlineChildren(children:
|
|
54
|
-
/** Transform
|
|
55
|
-
transformBlockChildren(children:
|
|
56
|
-
/**
|
|
57
|
-
* Emit a diagnostic from the parser module.
|
|
58
|
-
* Use for warnings about invalid structure, unsupported elements, etc.
|
|
59
|
-
*/
|
|
60
|
-
emitDiagnostic(diagnostic: Omit<ParseDiagnostic, 'file'>): void;
|
|
37
|
+
/** Create a source position for the AST node */
|
|
38
|
+
createSourcePos(node: NodeWithPosition): any;
|
|
39
|
+
/** Transform an array of mdast/hast inline children */
|
|
40
|
+
transformInlineChildren(children: any[]): Inline[];
|
|
41
|
+
/** Transform an array of mdast/hast block children */
|
|
42
|
+
transformBlockChildren(children: any[]): (Section | Block)[];
|
|
61
43
|
/** Get text content of element (HTML) */
|
|
62
44
|
getTextContent(element: Element): string;
|
|
63
45
|
/** Get attribute value (HTML) */
|
|
64
46
|
getAttr(element: Element, name: string): string | undefined;
|
|
47
|
+
/** Registry being used for parsing */
|
|
48
|
+
readonly registry: ParseHandlerRegistry;
|
|
65
49
|
}
|
|
66
50
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* Parser modules are first-class modules that live in src/parse/.
|
|
70
|
-
* They handle specific HTML tags and emit SpecAST nodes.
|
|
51
|
+
* Interface for a Markdown parser module.
|
|
71
52
|
*/
|
|
72
|
-
export interface
|
|
73
|
-
/** Unique parser module name */
|
|
53
|
+
export interface MarkdownParserModule {
|
|
74
54
|
name: string;
|
|
75
|
-
/**
|
|
55
|
+
/** Node types this parser can handle (e.g., 'paragraph', 'text', 'html') */
|
|
76
56
|
handles: string[];
|
|
77
|
-
/**
|
|
78
|
-
* Order for deterministic dispatch.
|
|
79
|
-
* Lower numbers run first. Default is 10.
|
|
80
|
-
*/
|
|
57
|
+
/** Priority order (lower number = higher priority, runs earlier) */
|
|
81
58
|
order?: number;
|
|
82
|
-
/** Handle
|
|
83
|
-
handleBlock?(
|
|
84
|
-
/** Handle
|
|
85
|
-
handleInline?(
|
|
59
|
+
/** Handle block-level transformation */
|
|
60
|
+
handleBlock?(node: MdastRootContent, ctx: ParseContext): BlockHandlerResult;
|
|
61
|
+
/** Handle inline-level transformation */
|
|
62
|
+
handleInline?(node: MdastRootContent, ctx: ParseContext): InlineHandlerResult;
|
|
86
63
|
}
|
|
87
64
|
/**
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* Parser modules are first-class modules that live in src/parse/.
|
|
91
|
-
* They handle specific mdast node types and emit SpecAST nodes.
|
|
65
|
+
* Interface for an HTML parser module.
|
|
92
66
|
*/
|
|
93
|
-
export interface
|
|
94
|
-
/** Unique parser module name */
|
|
67
|
+
export interface HtmlParserModule {
|
|
95
68
|
name: string;
|
|
96
|
-
/**
|
|
69
|
+
/** Element tags this parser can handle (e.g., 'dfn', 'xref', 'a') */
|
|
97
70
|
handles: string[];
|
|
98
|
-
/**
|
|
99
|
-
* Order for deterministic dispatch.
|
|
100
|
-
* Lower numbers run first. Default is 10.
|
|
101
|
-
*/
|
|
71
|
+
/** Priority order (lower number = higher priority, runs earlier) */
|
|
102
72
|
order?: number;
|
|
103
|
-
/** Handle
|
|
104
|
-
handleBlock?(
|
|
105
|
-
/** Handle
|
|
106
|
-
handleInline?(
|
|
73
|
+
/** Handle block-level element transformation */
|
|
74
|
+
handleBlock?(element: Element, ctx: ParseContext): BlockHandlerResult;
|
|
75
|
+
/** Handle inline-level element transformation */
|
|
76
|
+
handleInline?(element: Element, ctx: ParseContext): InlineHandlerResult;
|
|
107
77
|
}
|
|
108
78
|
/**
|
|
109
|
-
* Registry for parser modules
|
|
110
|
-
*
|
|
111
|
-
* Manages parser modules for HTML tags and Markdown node types.
|
|
112
|
-
* Supports ordering for deterministic dispatch.
|
|
79
|
+
* Registry for managing HTML and Markdown parser modules.
|
|
113
80
|
*/
|
|
114
81
|
export declare class ParseHandlerRegistry {
|
|
115
|
-
private htmlBlockHandlers;
|
|
116
|
-
private htmlInlineHandlers;
|
|
117
82
|
private mdBlockHandlers;
|
|
118
83
|
private mdInlineHandlers;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
*/
|
|
122
|
-
registerHtmlParser(parser: HtmlParserModule): void;
|
|
84
|
+
private htmlBlockHandlers;
|
|
85
|
+
private htmlInlineHandlers;
|
|
123
86
|
/**
|
|
124
87
|
* Register a Markdown parser module
|
|
125
88
|
*/
|
|
126
89
|
registerMarkdownParser(parser: MarkdownParserModule): void;
|
|
127
90
|
/**
|
|
128
|
-
* Get
|
|
91
|
+
* Get block handlers for a Markdown node type
|
|
129
92
|
*/
|
|
130
|
-
|
|
93
|
+
getMdBlockHandlers(nodeType: string): MarkdownParserModule[];
|
|
131
94
|
/**
|
|
132
|
-
* Get
|
|
95
|
+
* Get inline handlers for a Markdown node type
|
|
133
96
|
*/
|
|
134
|
-
|
|
97
|
+
getMdInlineHandlers(nodeType: string): MarkdownParserModule[];
|
|
135
98
|
/**
|
|
136
|
-
*
|
|
137
|
-
*/
|
|
138
|
-
getMdBlockHandler(nodeType: string): MarkdownParserModule | undefined;
|
|
139
|
-
/**
|
|
140
|
-
* Get Markdown inline parser for a node type
|
|
99
|
+
* Register an HTML parser module
|
|
141
100
|
*/
|
|
142
|
-
|
|
101
|
+
registerHtmlParser(parser: HtmlParserModule): void;
|
|
143
102
|
/**
|
|
144
|
-
*
|
|
103
|
+
* Get block handler for an HTML tag
|
|
145
104
|
*/
|
|
146
|
-
|
|
105
|
+
getHtmlBlockHandler(tagName: string): HtmlParserModule | undefined;
|
|
147
106
|
/**
|
|
148
|
-
*
|
|
107
|
+
* Get inline handler for an HTML tag
|
|
149
108
|
*/
|
|
150
|
-
|
|
109
|
+
getHtmlInlineHandler(tagName: string): HtmlParserModule | undefined;
|
|
151
110
|
}
|
|
152
111
|
/**
|
|
153
|
-
*
|
|
112
|
+
* Default global registry used by the application.
|
|
154
113
|
*/
|
|
155
114
|
export declare const defaultRegistry: ParseHandlerRegistry;
|
|
156
115
|
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/parse/registry.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/parse/registry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,WAAW,IAAI,gBAAgB,EAAE,MAAM,OAAO,C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OAEG;IACH,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,oBAAoB,EAAE;IAI7D;;OAEG;IACH,kBAAkB,CAAC,MAAM,EAAE,gBAAgB,GAAG,IAAI;IAoBlD;;OAEG;IACH,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS;IAIlE;;OAEG;IACH,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS;CAGtE;AAED;;GAEG;AACH,eAAO,MAAM,eAAe,sBAA6B,CAAC"}
|
package/dist/parse/registry.js
CHANGED
|
@@ -1,104 +1,85 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Parse Handler Registry
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* Parser modules handle specific hast/mdast nodes and emit SpecAST nodes.
|
|
4
|
+
* Manages the registration and lookup of HTML and Markdown parser modules.
|
|
6
5
|
*/
|
|
7
6
|
// ============================================================================
|
|
8
|
-
// Registry
|
|
7
|
+
// Registry Implementation
|
|
9
8
|
// ============================================================================
|
|
10
9
|
/**
|
|
11
|
-
* Registry for parser modules
|
|
12
|
-
*
|
|
13
|
-
* Manages parser modules for HTML tags and Markdown node types.
|
|
14
|
-
* Supports ordering for deterministic dispatch.
|
|
10
|
+
* Registry for managing HTML and Markdown parser modules.
|
|
15
11
|
*/
|
|
16
12
|
export class ParseHandlerRegistry {
|
|
17
|
-
htmlBlockHandlers = new Map();
|
|
18
|
-
htmlInlineHandlers = new Map();
|
|
19
13
|
mdBlockHandlers = new Map();
|
|
20
14
|
mdInlineHandlers = new Map();
|
|
15
|
+
htmlBlockHandlers = new Map();
|
|
16
|
+
htmlInlineHandlers = new Map();
|
|
21
17
|
/**
|
|
22
|
-
* Register
|
|
18
|
+
* Register a Markdown parser module
|
|
23
19
|
*/
|
|
24
|
-
|
|
25
|
-
for (const
|
|
26
|
-
const normalizedTag = tag.toLowerCase();
|
|
27
|
-
// Check if we should override based on order
|
|
20
|
+
registerMarkdownParser(parser) {
|
|
21
|
+
for (const nodeType of parser.handles) {
|
|
28
22
|
if (parser.handleBlock) {
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
const handlers = this.mdBlockHandlers.get(nodeType) || [];
|
|
24
|
+
handlers.push(parser);
|
|
25
|
+
handlers.sort((a, b) => (a.order ?? 10) - (b.order ?? 10));
|
|
26
|
+
this.mdBlockHandlers.set(nodeType, handlers);
|
|
33
27
|
}
|
|
34
28
|
if (parser.handleInline) {
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
29
|
+
const handlers = this.mdInlineHandlers.get(nodeType) || [];
|
|
30
|
+
handlers.push(parser);
|
|
31
|
+
handlers.sort((a, b) => (a.order ?? 10) - (b.order ?? 10));
|
|
32
|
+
this.mdInlineHandlers.set(nodeType, handlers);
|
|
39
33
|
}
|
|
40
34
|
}
|
|
41
35
|
}
|
|
42
36
|
/**
|
|
43
|
-
*
|
|
37
|
+
* Get block handlers for a Markdown node type
|
|
44
38
|
*/
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
39
|
+
getMdBlockHandlers(nodeType) {
|
|
40
|
+
return this.mdBlockHandlers.get(nodeType) || [];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get inline handlers for a Markdown node type
|
|
44
|
+
*/
|
|
45
|
+
getMdInlineHandlers(nodeType) {
|
|
46
|
+
return this.mdInlineHandlers.get(nodeType) || [];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Register an HTML parser module
|
|
50
|
+
*/
|
|
51
|
+
registerHtmlParser(parser) {
|
|
52
|
+
for (const tag of parser.handles) {
|
|
53
|
+
const normalizedTag = tag.toLowerCase();
|
|
48
54
|
if (parser.handleBlock) {
|
|
49
|
-
const existing = this.
|
|
55
|
+
const existing = this.htmlBlockHandlers.get(normalizedTag);
|
|
50
56
|
if (!existing || (parser.order ?? 10) < (existing.order ?? 10)) {
|
|
51
|
-
this.
|
|
57
|
+
this.htmlBlockHandlers.set(normalizedTag, parser);
|
|
52
58
|
}
|
|
53
59
|
}
|
|
54
60
|
if (parser.handleInline) {
|
|
55
|
-
const existing = this.
|
|
61
|
+
const existing = this.htmlInlineHandlers.get(normalizedTag);
|
|
56
62
|
if (!existing || (parser.order ?? 10) < (existing.order ?? 10)) {
|
|
57
|
-
this.
|
|
63
|
+
this.htmlInlineHandlers.set(normalizedTag, parser);
|
|
58
64
|
}
|
|
59
65
|
}
|
|
60
66
|
}
|
|
61
67
|
}
|
|
62
68
|
/**
|
|
63
|
-
* Get
|
|
69
|
+
* Get block handler for an HTML tag
|
|
64
70
|
*/
|
|
65
71
|
getHtmlBlockHandler(tagName) {
|
|
66
72
|
return this.htmlBlockHandlers.get(tagName.toLowerCase());
|
|
67
73
|
}
|
|
68
74
|
/**
|
|
69
|
-
* Get
|
|
75
|
+
* Get inline handler for an HTML tag
|
|
70
76
|
*/
|
|
71
77
|
getHtmlInlineHandler(tagName) {
|
|
72
78
|
return this.htmlInlineHandlers.get(tagName.toLowerCase());
|
|
73
79
|
}
|
|
74
|
-
/**
|
|
75
|
-
* Get Markdown block parser for a node type
|
|
76
|
-
*/
|
|
77
|
-
getMdBlockHandler(nodeType) {
|
|
78
|
-
return this.mdBlockHandlers.get(nodeType);
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Get Markdown inline parser for a node type
|
|
82
|
-
*/
|
|
83
|
-
getMdInlineHandler(nodeType) {
|
|
84
|
-
return this.mdInlineHandlers.get(nodeType);
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Check if a handler exists for HTML tag
|
|
88
|
-
*/
|
|
89
|
-
hasHtmlHandler(tagName) {
|
|
90
|
-
const normalized = tagName.toLowerCase();
|
|
91
|
-
return this.htmlBlockHandlers.has(normalized) || this.htmlInlineHandlers.has(normalized);
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Check if a handler exists for Markdown node type
|
|
95
|
-
*/
|
|
96
|
-
hasMdHandler(nodeType) {
|
|
97
|
-
return this.mdBlockHandlers.has(nodeType) || this.mdInlineHandlers.has(nodeType);
|
|
98
|
-
}
|
|
99
80
|
}
|
|
100
81
|
/**
|
|
101
|
-
*
|
|
82
|
+
* Default global registry used by the application.
|
|
102
83
|
*/
|
|
103
84
|
export const defaultRegistry = new ParseHandlerRegistry();
|
|
104
85
|
//# sourceMappingURL=registry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/parse/registry.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/parse/registry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAmGH,+EAA+E;AAC/E,0BAA0B;AAC1B,+EAA+E;AAE/E;;GAEG;AACH,MAAM,OAAO,oBAAoB;IACrB,eAAe,GAAG,IAAI,GAAG,EAAkC,CAAC;IAC5D,gBAAgB,GAAG,IAAI,GAAG,EAAkC,CAAC;IAC7D,iBAAiB,GAAG,IAAI,GAAG,EAA4B,CAAC;IACxD,kBAAkB,GAAG,IAAI,GAAG,EAA4B,CAAC;IAEjE;;OAEG;IACH,sBAAsB,CAAC,MAA4B;QAC/C,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACpC,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;gBACrB,MAAM,QAAQ,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;gBAC1D,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBACtB,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,CAAC;gBAC3D,IAA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AC;oBAC7D,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;gBACtD,CAAC;YACL,CAAC;YAED,IAAI,MAAM,CAAC,YAAY,EAAE,CAAC;gBACtB,MAAM,QAAQ,GAAG,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;gBAC5D,IAAI,CAAC,QAAQ,IAAI,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,CAAC;oBAC7D,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;gBACvD,CAAC;YACL,CAAC;QACL,CAAC;IACL,CAAC;IAED;;OAEG;IACH,mBAAmB,CAAC,OAAe;QAC/B,OAAO,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IAC7D,CAAC;IAED;;OAEG;IACH,oBAAoB,CAAC,OAAe;QAChC,OAAO,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IAC9D,CAAC;CACJ;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,oBAAoB,EAAE,CAAC"}
|
package/dist/parse/types.d.ts
CHANGED
|
@@ -32,33 +32,11 @@ export interface ParsedSpec {
|
|
|
32
32
|
document: Document;
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
|
-
* Parse
|
|
36
|
-
*/
|
|
37
|
-
export type ParseDiagnosticCode = 'parse-error' | 'invalid-structure' | 'unsupported-element';
|
|
38
|
-
/**
|
|
39
|
-
* Diagnostic severity levels
|
|
40
|
-
*/
|
|
41
|
-
export type DiagnosticSeverity = 'error' | 'warning' | 'info';
|
|
42
|
-
/**
|
|
43
|
-
* Parse diagnostic message
|
|
44
|
-
*/
|
|
45
|
-
export interface ParseDiagnostic {
|
|
46
|
-
severity: DiagnosticSeverity;
|
|
47
|
-
code: ParseDiagnosticCode;
|
|
48
|
-
message: string;
|
|
49
|
-
file?: string;
|
|
50
|
-
sourcePos?: SourcePos;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Parse result with diagnostics
|
|
35
|
+
* Parse result
|
|
54
36
|
*/
|
|
55
37
|
export interface ParseResult {
|
|
56
38
|
/** Parsed spec (may be partial if errors) */
|
|
57
39
|
result?: ParsedSpec;
|
|
58
|
-
/** Diagnostics from parsing */
|
|
59
|
-
diagnostics: ParseDiagnostic[];
|
|
60
|
-
/** Quick check for errors */
|
|
61
|
-
hasErrors: boolean;
|
|
62
40
|
}
|
|
63
41
|
/**
|
|
64
42
|
* Create a source position from unit context
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/parse/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAClF,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAOpF;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACvB,iCAAiC;IACjC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAE9B;;;;;OAKG;IACH,KAAK,CAAC,IAAI,EAAE,UAAU,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC,EAAE,CAAC;CAChD;AAMD;;GAEG;AACH,MAAM,WAAW,UAAU;IACvB,oCAAoC;IACpC,MAAM,EAAE,UAAU,CAAC;IAEnB,0BAA0B;IAC1B,QAAQ,EAAE,QAAQ,CAAC;CACtB;AAMD;;GAEG;AACH,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/parse/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAClF,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAOpF;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACvB,iCAAiC;IACjC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAE9B;;;;;OAKG;IACH,KAAK,CAAC,IAAI,EAAE,UAAU,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC,EAAE,CAAC;CAChD;AAMD;;GAEG;AACH,MAAM,WAAW,UAAU;IACvB,oCAAoC;IACpC,MAAM,EAAE,UAAU,CAAC;IAEnB,0BAA0B;IAC1B,QAAQ,EAAE,QAAQ,CAAC;CACtB;AAMD;;GAEG;AACH,MAAM,WAAW,WAAW;IACxB,6CAA6C;IAC7C,MAAM,CAAC,EAAE,UAAU,CAAC;CACvB;AAMD;;GAEG;AACH,wBAAgB,eAAe,CAC3B,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GACf,SAAS,CAMX"}
|
package/dist/parse/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/parse/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/parse/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAwDH,+EAA+E;AAC/E,UAAU;AACV,+EAA+E;AAE/E;;GAEG;AACH,MAAM,UAAU,eAAe,CAC3B,IAAgB,EAChB,IAAY,EACZ,MAAc;IAEd,OAAO;QACH,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,IAAI,EAAE,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,CAAC;QAC/B,MAAM;KACT,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared HAST Utilities
|
|
3
|
+
*
|
|
4
|
+
* Common utility functions for working with hast (HTML AST) nodes,
|
|
5
|
+
* shared between HTML parsers and markdown HTML inline handling.
|
|
6
|
+
*/
|
|
7
|
+
import type { Element, RootContent as HastRootContent } from 'hast';
|
|
8
|
+
import type { ParseContext } from '#src/parse/registry';
|
|
9
|
+
import type { Inline } from '#src/types/ast.generated';
|
|
10
|
+
/**
|
|
11
|
+
* Get element attribute value from hast element.
|
|
12
|
+
* Handles various types: strings, arrays (joins with space), numbers, and booleans.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getAttr(element: Element, name: string): string | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Get text content of element recursively.
|
|
17
|
+
* Extracts all text from nested elements.
|
|
18
|
+
*/
|
|
19
|
+
export declare function getTextContent(element: Element): string;
|
|
20
|
+
/**
|
|
21
|
+
* Transform a hast node to Speculator inline(s) using HTML handlers.
|
|
22
|
+
* This is the core transformation logic shared by both paragraph and block HTML parsers.
|
|
23
|
+
*/
|
|
24
|
+
export declare function transformHastInline(node: HastRootContent, ctx: ParseContext): Inline | Inline[] | null;
|
|
25
|
+
/**
|
|
26
|
+
* Create a hast-aware ParseContext from a base (markdown) context.
|
|
27
|
+
* This allows hast nodes to be transformed using the same handler infrastructure.
|
|
28
|
+
*/
|
|
29
|
+
export declare function createHastContext(ctx: ParseContext): ParseContext;
|
|
30
|
+
//# sourceMappingURL=hast-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hast-utils.d.ts","sourceRoot":"","sources":["../../../src/parse/utils/hast-utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAoB,WAAW,IAAI,eAAe,EAAE,MAAM,MAAM,CAAC;AAEtF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAEvD;;;GAGG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAO1E;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAUvD;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,eAAe,EAAE,GAAG,EAAE,YAAY,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,CAsBtG;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,YAAY,GAAG,YAAY,CAwBjE"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared HAST Utilities
|
|
3
|
+
*
|
|
4
|
+
* Common utility functions for working with hast (HTML AST) nodes,
|
|
5
|
+
* shared between HTML parsers and markdown HTML inline handling.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Get element attribute value from hast element.
|
|
9
|
+
* Handles various types: strings, arrays (joins with space), numbers, and booleans.
|
|
10
|
+
*/
|
|
11
|
+
export function getAttr(element, name) {
|
|
12
|
+
const val = element.properties?.[name];
|
|
13
|
+
if (typeof val === 'string')
|
|
14
|
+
return val;
|
|
15
|
+
if (Array.isArray(val))
|
|
16
|
+
return val.join(' ');
|
|
17
|
+
if (typeof val === 'number')
|
|
18
|
+
return String(val);
|
|
19
|
+
if (typeof val === 'boolean' && val)
|
|
20
|
+
return name;
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Get text content of element recursively.
|
|
25
|
+
* Extracts all text from nested elements.
|
|
26
|
+
*/
|
|
27
|
+
export function getTextContent(element) {
|
|
28
|
+
let text = '';
|
|
29
|
+
for (const child of element.children) {
|
|
30
|
+
if (child.type === 'text') {
|
|
31
|
+
text += child.value;
|
|
32
|
+
}
|
|
33
|
+
else if (child.type === 'element') {
|
|
34
|
+
text += getTextContent(child);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return text;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Transform a hast node to Speculator inline(s) using HTML handlers.
|
|
41
|
+
* This is the core transformation logic shared by both paragraph and block HTML parsers.
|
|
42
|
+
*/
|
|
43
|
+
export function transformHastInline(node, ctx) {
|
|
44
|
+
if (node.type === 'text') {
|
|
45
|
+
const textValue = node.value;
|
|
46
|
+
// Delegate back to Markdown's transformInlineChildren to handle shorthands (|var|)
|
|
47
|
+
const res = ctx.transformInlineChildren([{ type: 'text', value: textValue }]);
|
|
48
|
+
return res.length === 0 ? null : res;
|
|
49
|
+
}
|
|
50
|
+
if (node.type !== 'element')
|
|
51
|
+
return null;
|
|
52
|
+
const element = node;
|
|
53
|
+
const tagName = element.tagName.toLowerCase();
|
|
54
|
+
// Look up handler in the registry provided in the context
|
|
55
|
+
const handler = ctx.registry.getHtmlInlineHandler(tagName);
|
|
56
|
+
if (handler?.handleInline) {
|
|
57
|
+
return handler.handleInline(element, ctx);
|
|
58
|
+
}
|
|
59
|
+
// Fallback: recurse into children if no handler for this tag
|
|
60
|
+
return ctx.transformInlineChildren(element.children);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Create a hast-aware ParseContext from a base (markdown) context.
|
|
64
|
+
* This allows hast nodes to be transformed using the same handler infrastructure.
|
|
65
|
+
*/
|
|
66
|
+
export function createHastContext(ctx) {
|
|
67
|
+
const originalTransform = ctx.transformInlineChildren;
|
|
68
|
+
const hastCtx = {
|
|
69
|
+
...ctx,
|
|
70
|
+
transformInlineChildren: (children) => {
|
|
71
|
+
const results = [];
|
|
72
|
+
for (const child of children) {
|
|
73
|
+
if (child.type === 'element') {
|
|
74
|
+
const res = transformHastInline(child, hastCtx);
|
|
75
|
+
if (res) {
|
|
76
|
+
if (Array.isArray(res))
|
|
77
|
+
results.push(...res);
|
|
78
|
+
else
|
|
79
|
+
results.push(res);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
// Delegate anything else (text, mdast nodes) to the original transformer
|
|
84
|
+
results.push(...originalTransform([child]));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return results;
|
|
88
|
+
},
|
|
89
|
+
getTextContent,
|
|
90
|
+
getAttr,
|
|
91
|
+
};
|
|
92
|
+
return hastCtx;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=hast-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hast-utils.js","sourceRoot":"","sources":["../../../src/parse/utils/hast-utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH;;;GAGG;AACH,MAAM,UAAU,OAAO,CAAC,OAAgB,EAAE,IAAY;IAClD,MAAM,GAAG,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,IAAI,CAAC,CAAC;IACvC,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,GAAG,CAAC;IACxC,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;QAAE,OAAO,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC7C,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;IAChD,IAAI,OAAO,GAAG,KAAK,SAAS,IAAI,GAAG;QAAE,OAAO,IAAI,CAAC;IACjD,OAAO,SAAS,CAAC;AACrB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,OAAgB;IAC3C,IAAI,IAAI,GAAG,EAAE,CAAC;IACd,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;QACnC,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YACxB,IAAI,IAAK,KAAkB,CAAC,KAAK,CAAC;QACtC,CAAC;aAAM,IAAI,KAAK,CAAC,IAAI,KA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E;QACxB,OAAO,EAAE;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,UAAU,CAAC,EAAE,MAAM,CAAA;SAAE,EAAE,CAAC;QAClD,YAAY,EAAE,YAAY,CAAC;KAC9B,GAAG,OAAO,CAAC,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../src/pipeline/runner.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAK7D,OAAO,KAAK,EACR,MAAM,EAEN,eAAe,EAElB,MAAM,YAAY,CAAC;AAiCpB;;;;;GAKG;AACH,qBAAa,kBAAkB;IAC3B,OAAO,CAAC,OAAO,CAAW;gBAEd,OAAO,GAAE,MAAM,EAAO;IAIlC;;;OAGG;IACG,GAAG,CAAC,OAAO,EAAE;QACf,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,YAAY,EAAE,YAAY,CAAC;KAC9B,GAAG,OAAO,CAAC,eAAe,CAAC;IAO5B;;OAEG;IACG,YAAY,CAAC,OAAO,EAAE;QACxB,OAAO,EAAE;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,UAAU,CAAC,EAAE,MAAM,CAAA;SAAE,EAAE,CAAC;QAClD,YAAY,EAAE,YAAY,CAAC;KAC9B,GAAG,OAAO,CAAC,eAAe,CAAC;CAsF/B"}
|
package/dist/pipeline/runner.js
CHANGED
|
@@ -62,19 +62,23 @@ export class SpeculatorPipeline {
|
|
|
62
62
|
const results = [];
|
|
63
63
|
// 1. Initial run: Preprocess + Parse
|
|
64
64
|
for (const entryConfig of options.entries) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
65
|
+
try {
|
|
66
|
+
const preprocessedSpec = await preprocess({
|
|
67
|
+
entry: entryConfig.entry,
|
|
68
|
+
configPath: entryConfig.configPath,
|
|
69
|
+
fileProvider: options.fileProvider,
|
|
70
|
+
});
|
|
71
|
+
const registry = new ParseHandlerRegistry();
|
|
72
|
+
registerCoreParsers(registry);
|
|
73
|
+
const parseResult = parseWithRegistry(preprocessedSpec, registry);
|
|
74
|
+
if (!parseResult.result)
|
|
75
|
+
continue;
|
|
76
|
+
results.push({ doc: parseResult.result.document, entry: entryConfig.entry });
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
// Preprocess errors are now thrown, skip this entry
|
|
76
80
|
continue;
|
|
77
|
-
|
|
81
|
+
}
|
|
78
82
|
}
|
|
79
83
|
if (results.length === 0) {
|
|
80
84
|
return {};
|