@driftsys/markspec 0.2.0 → 0.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/README.md +32 -8
- package/esm/compiler/inverses.d.ts +22 -0
- package/esm/compiler/inverses.d.ts.map +1 -0
- package/esm/compiler/inverses.js +147 -0
- package/esm/compiler/link_target.d.ts +19 -0
- package/esm/compiler/link_target.d.ts.map +1 -0
- package/esm/compiler/link_target.js +66 -0
- package/esm/compiler/mod.d.ts +7 -1
- package/esm/compiler/mod.d.ts.map +1 -1
- package/esm/compiler/mod.js +61 -14
- package/esm/compiler/schema.d.ts.map +1 -1
- package/esm/compiler/schema.js +20 -1
- package/esm/config/markspec.d.ts +51 -0
- package/esm/config/markspec.d.ts.map +1 -0
- package/esm/config/markspec.js +216 -0
- package/esm/config/mod.d.ts +4 -0
- package/esm/config/mod.d.ts.map +1 -1
- package/esm/config/mod.js +27 -16
- package/esm/formatter/mod.d.ts +19 -4
- package/esm/formatter/mod.d.ts.map +1 -1
- package/esm/formatter/mod.js +139 -29
- package/esm/mod.d.ts +11 -7
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +6 -3
- package/esm/model/attributes.d.ts +47 -0
- package/esm/model/attributes.d.ts.map +1 -0
- package/esm/model/attributes.js +97 -0
- package/esm/model/mod.d.ts +257 -26
- package/esm/model/mod.d.ts.map +1 -1
- package/esm/model/mod.js +28 -1
- package/esm/model/palette.d.ts +18 -0
- package/esm/model/palette.d.ts.map +1 -0
- package/esm/model/palette.js +23 -0
- package/esm/model/profile.d.ts +189 -0
- package/esm/model/profile.d.ts.map +1 -0
- package/esm/model/profile.js +31 -0
- package/esm/parser/attributes.d.ts +13 -1
- package/esm/parser/attributes.d.ts.map +1 -1
- package/esm/parser/attributes.js +47 -0
- package/esm/parser/frontmatter.d.ts +53 -0
- package/esm/parser/frontmatter.d.ts.map +1 -0
- package/esm/parser/frontmatter.js +185 -0
- package/esm/parser/grammars.js +11 -2
- package/esm/parser/markdown.d.ts +21 -7
- package/esm/parser/markdown.d.ts.map +1 -1
- package/esm/parser/markdown.js +101 -40
- package/esm/parser/mod.d.ts +26 -10
- package/esm/parser/mod.d.ts.map +1 -1
- package/esm/parser/mod.js +40 -10
- package/esm/parser/source.d.ts +12 -8
- package/esm/parser/source.d.ts.map +1 -1
- package/esm/parser/source.js +21 -14
- package/esm/profile/cache.d.ts +29 -0
- package/esm/profile/cache.d.ts.map +1 -0
- package/esm/profile/cache.js +45 -0
- package/esm/profile/chain.d.ts +42 -0
- package/esm/profile/chain.d.ts.map +1 -0
- package/esm/profile/chain.js +193 -0
- package/esm/profile/colors.d.ts +26 -0
- package/esm/profile/colors.d.ts.map +1 -0
- package/esm/profile/colors.js +46 -0
- package/esm/profile/git-cache.d.ts +73 -0
- package/esm/profile/git-cache.d.ts.map +1 -0
- package/esm/profile/git-cache.js +96 -0
- package/esm/profile/load.d.ts +28 -0
- package/esm/profile/load.d.ts.map +1 -0
- package/esm/profile/load.js +50 -0
- package/esm/profile/manifest.d.ts +21 -0
- package/esm/profile/manifest.d.ts.map +1 -0
- package/esm/profile/manifest.js +815 -0
- package/esm/profile/merge.d.ts +26 -0
- package/esm/profile/merge.d.ts.map +1 -0
- package/esm/profile/merge.js +518 -0
- package/esm/profile/mod.d.ts +24 -0
- package/esm/profile/mod.d.ts.map +1 -0
- package/esm/profile/mod.js +15 -0
- package/esm/profile/npm.d.ts +51 -0
- package/esm/profile/npm.d.ts.map +1 -0
- package/esm/profile/npm.js +186 -0
- package/esm/profile/resolver.d.ts +60 -0
- package/esm/profile/resolver.d.ts.map +1 -0
- package/esm/profile/resolver.js +132 -0
- package/esm/reporter/mod.js +14 -27
- package/esm/validator/attributes.d.ts +43 -0
- package/esm/validator/attributes.d.ts.map +1 -0
- package/esm/validator/attributes.js +169 -0
- package/esm/validator/mod.d.ts +27 -6
- package/esm/validator/mod.d.ts.map +1 -1
- package/esm/validator/mod.js +132 -124
- package/esm/validator/normalize.d.ts +21 -0
- package/esm/validator/normalize.d.ts.map +1 -0
- package/esm/validator/normalize.js +58 -0
- package/esm/validator/pattern.d.ts +23 -0
- package/esm/validator/pattern.d.ts.map +1 -0
- package/esm/validator/pattern.js +44 -0
- package/esm/validator/pipeline.d.ts +30 -0
- package/esm/validator/pipeline.d.ts.map +1 -0
- package/esm/validator/pipeline.js +115 -0
- package/esm/validator/traceability.d.ts +48 -0
- package/esm/validator/traceability.d.ts.map +1 -0
- package/esm/validator/traceability.js +141 -0
- package/esm/validator/types.d.ts +48 -0
- package/esm/validator/types.d.ts.map +1 -0
- package/esm/validator/types.js +140 -0
- package/esm/validator/value_types.d.ts +20 -0
- package/esm/validator/value_types.d.ts.map +1 -0
- package/esm/validator/value_types.js +126 -0
- package/package.json +1 -1
- package/script/compiler/inverses.d.ts +22 -0
- package/script/compiler/inverses.d.ts.map +1 -0
- package/script/compiler/inverses.js +150 -0
- package/script/compiler/link_target.d.ts +19 -0
- package/script/compiler/link_target.d.ts.map +1 -0
- package/script/compiler/link_target.js +69 -0
- package/script/compiler/mod.d.ts +7 -1
- package/script/compiler/mod.d.ts.map +1 -1
- package/script/compiler/mod.js +62 -14
- package/script/compiler/schema.d.ts.map +1 -1
- package/script/compiler/schema.js +20 -1
- package/script/config/markspec.d.ts +51 -0
- package/script/config/markspec.d.ts.map +1 -0
- package/script/config/markspec.js +222 -0
- package/script/config/mod.d.ts +4 -0
- package/script/config/mod.d.ts.map +1 -1
- package/script/config/mod.js +28 -16
- package/script/formatter/mod.d.ts +19 -4
- package/script/formatter/mod.d.ts.map +1 -1
- package/script/formatter/mod.js +140 -29
- package/script/mod.d.ts +11 -7
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +50 -19
- package/script/model/attributes.d.ts +47 -0
- package/script/model/attributes.d.ts.map +1 -0
- package/script/model/attributes.js +101 -0
- package/script/model/mod.d.ts +257 -26
- package/script/model/mod.d.ts.map +1 -1
- package/script/model/mod.js +37 -2
- package/script/model/palette.d.ts +18 -0
- package/script/model/palette.d.ts.map +1 -0
- package/script/model/palette.js +26 -0
- package/script/model/profile.d.ts +189 -0
- package/script/model/profile.d.ts.map +1 -0
- package/script/model/profile.js +34 -0
- package/script/parser/attributes.d.ts +13 -1
- package/script/parser/attributes.d.ts.map +1 -1
- package/script/parser/attributes.js +48 -0
- package/script/parser/frontmatter.d.ts +53 -0
- package/script/parser/frontmatter.d.ts.map +1 -0
- package/script/parser/frontmatter.js +188 -0
- package/script/parser/grammars.js +11 -2
- package/script/parser/markdown.d.ts +21 -7
- package/script/parser/markdown.d.ts.map +1 -1
- package/script/parser/markdown.js +100 -39
- package/script/parser/mod.d.ts +26 -10
- package/script/parser/mod.d.ts.map +1 -1
- package/script/parser/mod.js +42 -11
- package/script/parser/source.d.ts +12 -8
- package/script/parser/source.d.ts.map +1 -1
- package/script/parser/source.js +21 -14
- package/script/profile/cache.d.ts +29 -0
- package/script/profile/cache.d.ts.map +1 -0
- package/script/profile/cache.js +48 -0
- package/script/profile/chain.d.ts +42 -0
- package/script/profile/chain.d.ts.map +1 -0
- package/script/profile/chain.js +229 -0
- package/script/profile/colors.d.ts +26 -0
- package/script/profile/colors.d.ts.map +1 -0
- package/script/profile/colors.js +49 -0
- package/script/profile/git-cache.d.ts +73 -0
- package/script/profile/git-cache.d.ts.map +1 -0
- package/script/profile/git-cache.js +104 -0
- package/script/profile/load.d.ts +28 -0
- package/script/profile/load.d.ts.map +1 -0
- package/script/profile/load.js +53 -0
- package/script/profile/manifest.d.ts +21 -0
- package/script/profile/manifest.d.ts.map +1 -0
- package/script/profile/manifest.js +818 -0
- package/script/profile/merge.d.ts +26 -0
- package/script/profile/merge.d.ts.map +1 -0
- package/script/profile/merge.js +521 -0
- package/script/profile/mod.d.ts +24 -0
- package/script/profile/mod.d.ts.map +1 -0
- package/script/profile/mod.js +33 -0
- package/script/profile/npm.d.ts +51 -0
- package/script/profile/npm.d.ts.map +1 -0
- package/script/profile/npm.js +191 -0
- package/script/profile/resolver.d.ts +60 -0
- package/script/profile/resolver.d.ts.map +1 -0
- package/script/profile/resolver.js +136 -0
- package/script/reporter/mod.js +14 -27
- package/script/validator/attributes.d.ts +43 -0
- package/script/validator/attributes.d.ts.map +1 -0
- package/script/validator/attributes.js +173 -0
- package/script/validator/mod.d.ts +27 -6
- package/script/validator/mod.d.ts.map +1 -1
- package/script/validator/mod.js +145 -123
- package/script/validator/normalize.d.ts +21 -0
- package/script/validator/normalize.d.ts.map +1 -0
- package/script/validator/normalize.js +61 -0
- package/script/validator/pattern.d.ts +23 -0
- package/script/validator/pattern.d.ts.map +1 -0
- package/script/validator/pattern.js +47 -0
- package/script/validator/pipeline.d.ts +30 -0
- package/script/validator/pipeline.d.ts.map +1 -0
- package/script/validator/pipeline.js +118 -0
- package/script/validator/traceability.d.ts +48 -0
- package/script/validator/traceability.d.ts.map +1 -0
- package/script/validator/traceability.js +146 -0
- package/script/validator/types.d.ts +48 -0
- package/script/validator/types.d.ts.map +1 -0
- package/script/validator/types.js +144 -0
- package/script/validator/value_types.d.ts +20 -0
- package/script/validator/value_types.d.ts.map +1 -0
- package/script/validator/value_types.js +129 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module parser/frontmatter
|
|
4
|
+
*
|
|
5
|
+
* YAML front-matter parser per ADR-007.
|
|
6
|
+
*
|
|
7
|
+
* Extracts a `---`-delimited YAML block at the top of a Markdown file,
|
|
8
|
+
* classifies keys into core / `metadata` / allowlisted ecosystem, and rejects
|
|
9
|
+
* forbidden keys (MSL-D001). Returns a {@linkcode DocumentAttributes} record
|
|
10
|
+
* and the markdown content with the front matter stripped.
|
|
11
|
+
*
|
|
12
|
+
* Full validation of core-key value types is deferred to the validator
|
|
13
|
+
* (Phase 3); this module handles extraction and key-category classification.
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.extractFrontMatter = extractFrontMatter;
|
|
17
|
+
const yaml_1 = require("@std/yaml");
|
|
18
|
+
/**
|
|
19
|
+
* YAML front-matter delimiter — `---` at start of file, closing `---`, then
|
|
20
|
+
* any number of trailing newlines so the stripped markdown begins cleanly.
|
|
21
|
+
* Empty YAML body (`---\n---\n`) is accepted.
|
|
22
|
+
*/
|
|
23
|
+
const FRONT_MATTER_RE = /^---\r?\n([\s\S]*?)(?:\r?\n)?---\r?\n?(?:\r?\n)*/;
|
|
24
|
+
/**
|
|
25
|
+
* Core document-level attribute keys per ADR-007. Kebab-case by convention.
|
|
26
|
+
*/
|
|
27
|
+
const CORE_KEYS = new Set([
|
|
28
|
+
"document-id",
|
|
29
|
+
"document-type",
|
|
30
|
+
"labels",
|
|
31
|
+
"deprecated",
|
|
32
|
+
"external-id",
|
|
33
|
+
"supersedes",
|
|
34
|
+
"references",
|
|
35
|
+
"metadata",
|
|
36
|
+
]);
|
|
37
|
+
/**
|
|
38
|
+
* Keys forbidden in front matter per ADR-007 — already expressed natively in
|
|
39
|
+
* Markdown (H1, body, images) or in git history (authors, dates).
|
|
40
|
+
*/
|
|
41
|
+
const FORBIDDEN_KEYS = new Set([
|
|
42
|
+
"title",
|
|
43
|
+
"description",
|
|
44
|
+
"toc",
|
|
45
|
+
"authors",
|
|
46
|
+
"author",
|
|
47
|
+
"date",
|
|
48
|
+
"created",
|
|
49
|
+
"modified",
|
|
50
|
+
"cover",
|
|
51
|
+
"images",
|
|
52
|
+
"sections",
|
|
53
|
+
]);
|
|
54
|
+
/**
|
|
55
|
+
* Extract YAML front matter from a Markdown source, validate its keys, and
|
|
56
|
+
* return structured attributes plus the stripped markdown.
|
|
57
|
+
*
|
|
58
|
+
* No front matter → {@linkcode FrontMatterResult.hadFrontMatter} is `false`
|
|
59
|
+
* and attributes are empty.
|
|
60
|
+
*
|
|
61
|
+
* @param markdown - Full source text, including any leading front matter.
|
|
62
|
+
* @param options - Key allowlists and file path for diagnostics.
|
|
63
|
+
*/
|
|
64
|
+
function extractFrontMatter(markdown, options) {
|
|
65
|
+
const file = options?.file ?? "<unknown>";
|
|
66
|
+
const match = FRONT_MATTER_RE.exec(markdown);
|
|
67
|
+
if (!match) {
|
|
68
|
+
return {
|
|
69
|
+
attributes: {},
|
|
70
|
+
diagnostics: [],
|
|
71
|
+
markdown,
|
|
72
|
+
hadFrontMatter: false,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
const yamlBody = match[1];
|
|
76
|
+
const remaining = markdown.slice(match[0].length);
|
|
77
|
+
const diagnostics = [];
|
|
78
|
+
let raw;
|
|
79
|
+
try {
|
|
80
|
+
raw = (0, yaml_1.parse)(yamlBody);
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
diagnostics.push({
|
|
84
|
+
code: "MSL-D001",
|
|
85
|
+
severity: "error",
|
|
86
|
+
message: `front matter: invalid YAML — ${err instanceof Error ? err.message : String(err)}`,
|
|
87
|
+
location: { file, line: 1, column: 1 },
|
|
88
|
+
});
|
|
89
|
+
return {
|
|
90
|
+
attributes: {},
|
|
91
|
+
diagnostics,
|
|
92
|
+
markdown: remaining,
|
|
93
|
+
hadFrontMatter: true,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
if (raw == null) {
|
|
97
|
+
return {
|
|
98
|
+
attributes: {},
|
|
99
|
+
diagnostics,
|
|
100
|
+
markdown: remaining,
|
|
101
|
+
hadFrontMatter: true,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
if (typeof raw !== "object" || Array.isArray(raw)) {
|
|
105
|
+
diagnostics.push({
|
|
106
|
+
code: "MSL-D001",
|
|
107
|
+
severity: "error",
|
|
108
|
+
message: "front matter must be a YAML mapping",
|
|
109
|
+
location: { file, line: 1, column: 1 },
|
|
110
|
+
});
|
|
111
|
+
return {
|
|
112
|
+
attributes: {},
|
|
113
|
+
diagnostics,
|
|
114
|
+
markdown: remaining,
|
|
115
|
+
hadFrontMatter: true,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
const entries = raw;
|
|
119
|
+
const profileKeys = new Set(options?.profileKeys ?? []);
|
|
120
|
+
const allowedKeys = new Set(options?.allowedKeys ?? []);
|
|
121
|
+
const core = {};
|
|
122
|
+
const extra = {};
|
|
123
|
+
let metadata;
|
|
124
|
+
for (const [key, value] of Object.entries(entries)) {
|
|
125
|
+
if (FORBIDDEN_KEYS.has(key)) {
|
|
126
|
+
diagnostics.push({
|
|
127
|
+
code: "MSL-D001",
|
|
128
|
+
severity: "error",
|
|
129
|
+
message: `front matter key '${key}' is forbidden — express it in Markdown or git history instead`,
|
|
130
|
+
location: { file, line: 1, column: 1 },
|
|
131
|
+
});
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (key === "metadata") {
|
|
135
|
+
if (value == null || typeof value !== "object" || Array.isArray(value)) {
|
|
136
|
+
diagnostics.push({
|
|
137
|
+
code: "MSL-D001",
|
|
138
|
+
severity: "error",
|
|
139
|
+
message: "front matter 'metadata' must be a mapping",
|
|
140
|
+
location: { file, line: 1, column: 1 },
|
|
141
|
+
});
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
metadata = value;
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
// Transitional: status: was removed in favor of Labels: DRAFT / deprecated:
|
|
148
|
+
if (key === "status") {
|
|
149
|
+
diagnostics.push({
|
|
150
|
+
code: "MSL-D002",
|
|
151
|
+
severity: "warning",
|
|
152
|
+
message: `front-matter key 'status' is no longer recognized; ` +
|
|
153
|
+
`use 'Labels: DRAFT' for draft state or 'deprecated: "<reason>"' for retirement`,
|
|
154
|
+
location: { file, line: 1, column: 1 },
|
|
155
|
+
});
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (CORE_KEYS.has(key)) {
|
|
159
|
+
core[key] = value;
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (profileKeys.has(key) || allowedKeys.has(key)) {
|
|
163
|
+
extra[key] = value;
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
diagnostics.push({
|
|
167
|
+
code: "MSL-D001",
|
|
168
|
+
severity: "error",
|
|
169
|
+
message: `unknown front matter key '${key}' — must be core, profile-declared, 'metadata', or allowlisted in .markspec.yaml`,
|
|
170
|
+
location: { file, line: 1, column: 1 },
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
const attributes = {};
|
|
174
|
+
const mutable = attributes;
|
|
175
|
+
for (const [key, value] of Object.entries(core)) {
|
|
176
|
+
mutable[key] = value;
|
|
177
|
+
}
|
|
178
|
+
if (metadata !== undefined)
|
|
179
|
+
mutable.metadata = metadata;
|
|
180
|
+
if (Object.keys(extra).length > 0)
|
|
181
|
+
mutable.extra = extra;
|
|
182
|
+
return {
|
|
183
|
+
attributes,
|
|
184
|
+
diagnostics,
|
|
185
|
+
markdown: remaining,
|
|
186
|
+
hadFrontMatter: true,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
@@ -63,6 +63,15 @@ async function doLoad(grammarName) {
|
|
|
63
63
|
await web_tree_sitter_1.default.init();
|
|
64
64
|
initialized = true;
|
|
65
65
|
}
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
// The compiled binary embeds grammars as .wasm.bin to bypass Deno's
|
|
67
|
+
// WASM-import resolver (see scripts/compile_binary.ts). Prefer the
|
|
68
|
+
// mirror when present; fall back to .wasm in dev mode.
|
|
69
|
+
const binPath = (0, path_1.join)(GRAMMARS_DIR, `${grammarName}.wasm.bin`);
|
|
70
|
+
try {
|
|
71
|
+
await Deno.stat(binPath);
|
|
72
|
+
return web_tree_sitter_1.default.Language.load(binPath);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return web_tree_sitter_1.default.Language.load((0, path_1.join)(GRAMMARS_DIR, `${grammarName}.wasm`));
|
|
76
|
+
}
|
|
68
77
|
}
|
|
@@ -2,24 +2,38 @@
|
|
|
2
2
|
* @module parser/markdown
|
|
3
3
|
*
|
|
4
4
|
* CommonMark + MarkSpec extension parser. Walks the mdast AST to detect
|
|
5
|
-
* `- [
|
|
5
|
+
* `- [DISPLAY_ID] Title` entry blocks and extract structured attributes.
|
|
6
6
|
*/
|
|
7
|
-
import type { Entry } from "../model/mod.js";
|
|
7
|
+
import type { Diagnostic, Entry } from "../model/mod.js";
|
|
8
8
|
/** Options for {@linkcode parseMarkdown}. */
|
|
9
9
|
export interface ParseMarkdownOptions {
|
|
10
10
|
/** File path used in source locations. */
|
|
11
11
|
readonly file?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Is this a references document? If undefined, auto-detect from file path.
|
|
14
|
+
* When true, `[slug]` items without an `Id:` attribute are still admitted
|
|
15
|
+
* as referenced-entry candidates (the validator flags the missing `Id:`).
|
|
16
|
+
*/
|
|
17
|
+
readonly isReferencesDoc?: boolean;
|
|
18
|
+
}
|
|
19
|
+
/** Result returned by {@linkcode parseMarkdown}. */
|
|
20
|
+
export interface ParseMarkdownResult {
|
|
21
|
+
/** Parsed entries found in the Markdown source. */
|
|
22
|
+
readonly entries: Entry[];
|
|
23
|
+
/** Parse-level diagnostics (e.g., deprecation warnings). */
|
|
24
|
+
readonly diagnostics: Diagnostic[];
|
|
12
25
|
}
|
|
13
26
|
/**
|
|
14
27
|
* Parse a Markdown string and return all MarkSpec entries found.
|
|
15
28
|
*
|
|
16
|
-
* Walks the mdast AST to detect `- [DISPLAY_ID] Title` list items
|
|
17
|
-
*
|
|
18
|
-
*
|
|
29
|
+
* Walks the mdast AST to detect `- [DISPLAY_ID] Title` list items with
|
|
30
|
+
* indented body content. Extracts display ID, title, body, and trailing
|
|
31
|
+
* attribute blocks. Entry shape (identified or referenced) is decided by
|
|
32
|
+
* the `Id:` attribute's value format.
|
|
19
33
|
*
|
|
20
34
|
* @param markdown - Markdown source text
|
|
21
35
|
* @param options - Parse options (file path for source locations)
|
|
22
|
-
* @returns
|
|
36
|
+
* @returns Parsed entries and any parse-level diagnostics
|
|
23
37
|
*/
|
|
24
|
-
export declare function parseMarkdown(markdown: string, options?: ParseMarkdownOptions):
|
|
38
|
+
export declare function parseMarkdown(markdown: string, options?: ParseMarkdownOptions): ParseMarkdownResult;
|
|
25
39
|
//# sourceMappingURL=markdown.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/parser/markdown.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/parser/markdown.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAa,UAAU,EAAE,KAAK,EAAc,MAAM,iBAAiB,CAAC;AAShF,6CAA6C;AAC7C,MAAM,WAAW,oBAAoB;IACnC,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB;;;;OAIG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,OAAO,CAAC;CACpC;AA4BD,oDAAoD;AACpD,MAAM,WAAW,mBAAmB;IAClC,mDAAmD;IACnD,QAAQ,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;IAC1B,4DAA4D;IAC5D,QAAQ,CAAC,WAAW,EAAE,UAAU,EAAE,CAAC;CACpC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,mBAAmB,CAsCrB"}
|
|
@@ -3,41 +3,53 @@
|
|
|
3
3
|
* @module parser/markdown
|
|
4
4
|
*
|
|
5
5
|
* CommonMark + MarkSpec extension parser. Walks the mdast AST to detect
|
|
6
|
-
* `- [
|
|
6
|
+
* `- [DISPLAY_ID] Title` entry blocks and extract structured attributes.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.parseMarkdown = parseMarkdown;
|
|
10
|
+
const mod_js_1 = require("../model/mod.js");
|
|
10
11
|
const attributes_js_1 = require("./attributes.js");
|
|
11
12
|
const remark_js_1 = require("./remark.js");
|
|
12
13
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
* Reference entry display ID pattern: letters, digits, hyphens.
|
|
14
|
+
* Slug pattern for referenced-entry display IDs.
|
|
15
|
+
*
|
|
16
|
+
* Pandoc/BibTeX cite-key convention, restricted to a portable character set
|
|
17
|
+
* (`.`, `/`, `_`, `-` accepted inside; must start with a letter and end
|
|
18
|
+
* with an alphanumeric).
|
|
19
19
|
*/
|
|
20
|
-
const
|
|
20
|
+
const SLUG_RE = /^[A-Za-z]([A-Za-z0-9._/-]*[A-Za-z0-9])?$/;
|
|
21
|
+
/** Match `[...]` at the start of a list item paragraph. Captures: [1] = display ID, [2] = title. */
|
|
22
|
+
const ENTRY_START_RE = /^\[([^\]]+)\]\s*(.*)$/;
|
|
21
23
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
+
* Find the `Id:` attribute on an entry. Returns undefined when absent. If
|
|
25
|
+
* more than one `Id:` is present, returns the first — the validator flags
|
|
26
|
+
* this as MSL-R003.
|
|
24
27
|
*/
|
|
25
|
-
|
|
28
|
+
function findIdentityAttribute(attributes) {
|
|
29
|
+
for (const attr of attributes) {
|
|
30
|
+
if (attr.key === mod_js_1.IDENTITY_KEY)
|
|
31
|
+
return attr;
|
|
32
|
+
}
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
26
35
|
/**
|
|
27
36
|
* Parse a Markdown string and return all MarkSpec entries found.
|
|
28
37
|
*
|
|
29
|
-
* Walks the mdast AST to detect `- [DISPLAY_ID] Title` list items
|
|
30
|
-
*
|
|
31
|
-
*
|
|
38
|
+
* Walks the mdast AST to detect `- [DISPLAY_ID] Title` list items with
|
|
39
|
+
* indented body content. Extracts display ID, title, body, and trailing
|
|
40
|
+
* attribute blocks. Entry shape (identified or referenced) is decided by
|
|
41
|
+
* the `Id:` attribute's value format.
|
|
32
42
|
*
|
|
33
43
|
* @param markdown - Markdown source text
|
|
34
44
|
* @param options - Parse options (file path for source locations)
|
|
35
|
-
* @returns
|
|
45
|
+
* @returns Parsed entries and any parse-level diagnostics
|
|
36
46
|
*/
|
|
37
47
|
function parseMarkdown(markdown, options) {
|
|
38
48
|
const file = options?.file ?? "<unknown>";
|
|
49
|
+
const isReferencesDoc = detectReferencesDocument(file, options?.isReferencesDoc);
|
|
39
50
|
const tree = remark_js_1.processor.parse(markdown);
|
|
40
51
|
const entries = [];
|
|
52
|
+
const diagnostics = [];
|
|
41
53
|
// Collect link definition identifiers for shortcut reference exclusion.
|
|
42
54
|
const definitions = new Set(tree.children
|
|
43
55
|
.filter((n) => n.type === "definition")
|
|
@@ -50,18 +62,31 @@ function parseMarkdown(markdown, options) {
|
|
|
50
62
|
if (list.ordered)
|
|
51
63
|
continue;
|
|
52
64
|
for (const item of list.children) {
|
|
53
|
-
const entry = extractEntry(item, markdown, file, definitions);
|
|
65
|
+
const entry = extractEntry(item, markdown, file, definitions, isReferencesDoc, diagnostics);
|
|
54
66
|
if (entry)
|
|
55
67
|
entries.push(entry);
|
|
56
68
|
}
|
|
57
69
|
}
|
|
58
|
-
return entries;
|
|
70
|
+
return { entries, diagnostics };
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Detect if a file is a references document.
|
|
74
|
+
* References context enables recognition of reference entries (slugs).
|
|
75
|
+
* @param file - File path
|
|
76
|
+
* @param explicit - Explicit override (undefined = auto-detect)
|
|
77
|
+
*/
|
|
78
|
+
function detectReferencesDocument(file, explicit) {
|
|
79
|
+
if (explicit !== undefined)
|
|
80
|
+
return explicit;
|
|
81
|
+
const basename = file.split("/").pop() ?? "";
|
|
82
|
+
return basename === "references.md" || file.includes("/references/");
|
|
59
83
|
}
|
|
60
84
|
/**
|
|
61
85
|
* Attempt to extract a MarkSpec entry from a list item.
|
|
62
86
|
* Returns undefined if the list item is not an entry block.
|
|
87
|
+
* Diagnostics (e.g., deprecation warnings) are pushed into the accumulator.
|
|
63
88
|
*/
|
|
64
|
-
function extractEntry(item, markdown, file, definitions) {
|
|
89
|
+
function extractEntry(item, markdown, file, definitions, isReferencesDoc, diagnostics) {
|
|
65
90
|
// Task list items (remark-gfm sets checked to true/false) are not entries.
|
|
66
91
|
if (item.checked != null)
|
|
67
92
|
return undefined;
|
|
@@ -114,28 +139,61 @@ function extractEntry(item, markdown, file, definitions) {
|
|
|
114
139
|
}
|
|
115
140
|
if (!displayId)
|
|
116
141
|
return undefined;
|
|
117
|
-
//
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
//
|
|
122
|
-
// If there's only one child (the title paragraph) and no further content,
|
|
123
|
-
// it's not an entry block.
|
|
124
|
-
if (item.children.length < 2)
|
|
125
|
-
return undefined;
|
|
126
|
-
// Extract entry type from typed display IDs
|
|
127
|
-
const typedMatch = TYPED_ID_RE.exec(displayId);
|
|
128
|
-
const entryType = typedMatch
|
|
129
|
-
? typedMatch[1]
|
|
130
|
-
: undefined;
|
|
131
|
-
// Extract body content from remaining children
|
|
142
|
+
// Strip optional leading `@` on referenced-entry display IDs for Pandoc
|
|
143
|
+
// citation compatibility. Canonical slug never contains `@`.
|
|
144
|
+
if (displayId.startsWith("@"))
|
|
145
|
+
displayId = displayId.slice(1);
|
|
146
|
+
// Extract body content and attributes.
|
|
132
147
|
const bodyContent = extractBodyContent(item, markdown);
|
|
133
|
-
// Split body and attributes
|
|
134
148
|
const [body, attrLines] = (0, attributes_js_1.splitBodyAndAttributes)(bodyContent);
|
|
135
149
|
const attributes = (0, attributes_js_1.parseAttributes)(attrLines);
|
|
136
|
-
//
|
|
137
|
-
|
|
138
|
-
|
|
150
|
+
// Detect legacy paragraph + trailing-backslash attribute form and warn.
|
|
151
|
+
if (attributes.length > 0 &&
|
|
152
|
+
attrLines.some((line) => line.trimEnd().endsWith("\\"))) {
|
|
153
|
+
const entryLine = item.position?.start.line ?? 1;
|
|
154
|
+
diagnostics.push({
|
|
155
|
+
code: "MSL-DEPRECATED-ATTR-001",
|
|
156
|
+
severity: "warning",
|
|
157
|
+
message: "legacy attribute block (paragraph with trailing `\\`) is deprecated; " +
|
|
158
|
+
"run `markspec format` to convert to the canonical indented code block",
|
|
159
|
+
location: { file, line: entryLine, column: 1 },
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
// Discriminate shape by the `Id:` attribute's value format.
|
|
163
|
+
let shape;
|
|
164
|
+
let id;
|
|
165
|
+
const identityAttr = findIdentityAttribute(attributes);
|
|
166
|
+
if (identityAttr) {
|
|
167
|
+
id = identityAttr.value;
|
|
168
|
+
shape = (0, mod_js_1.shapeFromIdValue)(identityAttr.value);
|
|
169
|
+
if (shape === undefined) {
|
|
170
|
+
// `Id:` is neither a ULID nor a scheme-qualified URI. Accept as an
|
|
171
|
+
// identified entry so the validator can surface MSL-R004; missing
|
|
172
|
+
// shape on a parsed entry is not useful downstream.
|
|
173
|
+
shape = "identified";
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
// No `Id:`. Fall back on display-ID shape + document context to decide
|
|
178
|
+
// whether to admit the entry at all.
|
|
179
|
+
if (isReferencesDoc && SLUG_RE.test(displayId)) {
|
|
180
|
+
shape = "referenced";
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
// No identity attribute and no references-doc context — admit as
|
|
184
|
+
// identified so the validator can surface the missing-`Id:` error.
|
|
185
|
+
shape = "identified";
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
// Inferred type from display-ID prefix — left to the profile layer. For
|
|
189
|
+
// now the core records no type; downstream profile-aware code populates
|
|
190
|
+
// this field when a profile is loaded.
|
|
191
|
+
const type = undefined;
|
|
192
|
+
// Body requirement: identified entries require a body; referenced entries
|
|
193
|
+
// may omit it. If there's only one child (the title paragraph), admit
|
|
194
|
+
// only referenced entries.
|
|
195
|
+
if (shape !== "referenced" && item.children.length < 2)
|
|
196
|
+
return undefined;
|
|
139
197
|
// Source location
|
|
140
198
|
const line = item.position?.start.line ?? 1;
|
|
141
199
|
const column = item.position?.start.column ?? 1;
|
|
@@ -143,11 +201,14 @@ function extractEntry(item, markdown, file, definitions) {
|
|
|
143
201
|
displayId,
|
|
144
202
|
title: title ?? "",
|
|
145
203
|
body,
|
|
146
|
-
attributes,
|
|
204
|
+
rawAttributes: attributes,
|
|
205
|
+
typedAttributes: (0, attributes_js_1.collateAttributes)(attributes),
|
|
147
206
|
id,
|
|
148
|
-
|
|
207
|
+
type,
|
|
208
|
+
shape,
|
|
149
209
|
location: { file, line, column },
|
|
150
210
|
source: "markdown",
|
|
211
|
+
properties: { file: { path: file, line, column } },
|
|
151
212
|
};
|
|
152
213
|
}
|
|
153
214
|
/**
|
package/script/parser/mod.d.ts
CHANGED
|
@@ -9,15 +9,17 @@
|
|
|
9
9
|
* - directives: HTML comment directive extraction
|
|
10
10
|
* - source: doc comment extraction from Rust, Kotlin, C, C++, Java
|
|
11
11
|
*/
|
|
12
|
-
import type { Caption, Entry } from "../model/mod.js";
|
|
12
|
+
import type { Caption, Diagnostic, Document, Entry } from "../model/mod.js";
|
|
13
13
|
import { type DetectCaptionsOptions } from "./captions.js";
|
|
14
14
|
export type { DetectCaptionsOptions } from "./captions.js";
|
|
15
15
|
export { detectDirectives } from "./directives.js";
|
|
16
16
|
export type { DetectDirectivesOptions } from "./directives.js";
|
|
17
|
+
export { extractFrontMatter } from "./frontmatter.js";
|
|
18
|
+
export type { ExtractFrontMatterOptions, FrontMatterResult, } from "./frontmatter.js";
|
|
17
19
|
export { detectInlineRefs } from "./references.js";
|
|
18
20
|
export type { DetectInlineRefsOptions } from "./references.js";
|
|
19
21
|
export { parseSource } from "./source.js";
|
|
20
|
-
export type { ParseSourceOptions } from "./source.js";
|
|
22
|
+
export type { ParseSourceOptions, ParseSourceResult } from "./source.js";
|
|
21
23
|
export { isSupportedExtension, loadGrammar } from "./grammars.js";
|
|
22
24
|
/** Options for {@linkcode parse}. */
|
|
23
25
|
export interface ParseOptions {
|
|
@@ -32,20 +34,34 @@ export interface ParseOptions {
|
|
|
32
34
|
* @returns Array of parsed entries
|
|
33
35
|
*/
|
|
34
36
|
export declare function parse(markdown: string, options?: ParseOptions): Entry[];
|
|
37
|
+
/** Result of parsing a file (entries + optional document + diagnostics). */
|
|
38
|
+
export interface ParseFileResult {
|
|
39
|
+
/** Parsed entries. */
|
|
40
|
+
readonly entries: Entry[];
|
|
41
|
+
/**
|
|
42
|
+
* Document-level metadata parsed from YAML front matter. `undefined` for
|
|
43
|
+
* source files (Rust/Kotlin/C/...) and for Markdown files without front
|
|
44
|
+
* matter; present otherwise so downstream consumers can resolve
|
|
45
|
+
* `{{document.*}}` inline references.
|
|
46
|
+
*/
|
|
47
|
+
readonly document?: Document;
|
|
48
|
+
/**
|
|
49
|
+
* Parse-level diagnostics (forbidden front-matter keys, malformed YAML).
|
|
50
|
+
* Merged into the compile result's diagnostics.
|
|
51
|
+
*/
|
|
52
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
53
|
+
}
|
|
35
54
|
/**
|
|
36
|
-
* Parse a file and return
|
|
55
|
+
* Parse a file and return entries, annotation links, and (for Markdown
|
|
56
|
+
* files) a Document with front-matter attributes.
|
|
37
57
|
*
|
|
38
58
|
* Source files (`.rs`, `.java`, `.c`, `.cpp`, etc.) are parsed with
|
|
39
|
-
* tree-sitter to extract doc comment entries
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* @param content - File content
|
|
43
|
-
* @param options - Must include `file` path for extension detection
|
|
44
|
-
* @returns Array of parsed entries
|
|
59
|
+
* tree-sitter to extract doc comment entries; no front matter is
|
|
60
|
+
* recognized on source files.
|
|
45
61
|
*/
|
|
46
62
|
export declare function parseFile(content: string, options: {
|
|
47
63
|
readonly file: string;
|
|
48
|
-
}): Promise<
|
|
64
|
+
}): Promise<ParseFileResult>;
|
|
49
65
|
/**
|
|
50
66
|
* Detect table and figure captions in a Markdown string.
|
|
51
67
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/parser/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/parser/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAK5E,OAAO,EAEL,KAAK,qBAAqB,EAC3B,MAAM,eAAe,CAAC;AAEvB,YAAY,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,YAAY,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAE/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,YAAY,EACV,yBAAyB,EACzB,iBAAiB,GAClB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,YAAY,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAE/D,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,YAAY,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEzE,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAElE,qCAAqC;AACrC,MAAM,WAAW,YAAY;IAC3B,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;GAMG;AACH,wBAAgB,KAAK,CACnB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,YAAY,GACrB,KAAK,EAAE,CAET;AAED,4EAA4E;AAC5E,MAAM,WAAW,eAAe;IAC9B,sBAAsB;IACtB,QAAQ,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;IAC1B;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAC7B;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAYD;;;;;;;GAOG;AACH,wBAAsB,SAAS,CAC7B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACjC,OAAO,CAAC,eAAe,CAAC,CAiC1B;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,EAAE,CAEX"}
|
package/script/parser/mod.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* - source: doc comment extraction from Rust, Kotlin, C, C++, Java
|
|
12
12
|
*/
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.loadGrammar = exports.isSupportedExtension = exports.parseSource = exports.detectInlineRefs = exports.detectDirectives = void 0;
|
|
14
|
+
exports.loadGrammar = exports.isSupportedExtension = exports.parseSource = exports.detectInlineRefs = exports.extractFrontMatter = exports.detectDirectives = void 0;
|
|
15
15
|
exports.parse = parse;
|
|
16
16
|
exports.parseFile = parseFile;
|
|
17
17
|
exports.detectCaptions = detectCaptions;
|
|
@@ -19,9 +19,12 @@ const path_1 = require("@std/path");
|
|
|
19
19
|
const markdown_js_1 = require("./markdown.js");
|
|
20
20
|
const grammars_js_1 = require("./grammars.js");
|
|
21
21
|
const source_js_1 = require("./source.js");
|
|
22
|
+
const frontmatter_js_1 = require("./frontmatter.js");
|
|
22
23
|
const captions_js_1 = require("./captions.js");
|
|
23
24
|
var directives_js_1 = require("./directives.js");
|
|
24
25
|
Object.defineProperty(exports, "detectDirectives", { enumerable: true, get: function () { return directives_js_1.detectDirectives; } });
|
|
26
|
+
var frontmatter_js_2 = require("./frontmatter.js");
|
|
27
|
+
Object.defineProperty(exports, "extractFrontMatter", { enumerable: true, get: function () { return frontmatter_js_2.extractFrontMatter; } });
|
|
25
28
|
var references_js_1 = require("./references.js");
|
|
26
29
|
Object.defineProperty(exports, "detectInlineRefs", { enumerable: true, get: function () { return references_js_1.detectInlineRefs; } });
|
|
27
30
|
var source_js_2 = require("./source.js");
|
|
@@ -37,26 +40,54 @@ Object.defineProperty(exports, "loadGrammar", { enumerable: true, get: function
|
|
|
37
40
|
* @returns Array of parsed entries
|
|
38
41
|
*/
|
|
39
42
|
function parse(markdown, options) {
|
|
40
|
-
return (0, markdown_js_1.parseMarkdown)(markdown, options);
|
|
43
|
+
return (0, markdown_js_1.parseMarkdown)(markdown, options).entries;
|
|
41
44
|
}
|
|
42
45
|
/**
|
|
43
|
-
*
|
|
46
|
+
* Detect if a file is a references document.
|
|
47
|
+
* References context enables recognition of reference entries (slugs).
|
|
48
|
+
* @param file - File path
|
|
49
|
+
*/
|
|
50
|
+
function isReferencesDocument(file) {
|
|
51
|
+
const basename = file.split("/").pop() ?? "";
|
|
52
|
+
return basename === "references.md" || file.includes("/references/");
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Parse a file and return entries, annotation links, and (for Markdown
|
|
56
|
+
* files) a Document with front-matter attributes.
|
|
44
57
|
*
|
|
45
58
|
* Source files (`.rs`, `.java`, `.c`, `.cpp`, etc.) are parsed with
|
|
46
|
-
* tree-sitter to extract doc comment entries
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* @param content - File content
|
|
50
|
-
* @param options - Must include `file` path for extension detection
|
|
51
|
-
* @returns Array of parsed entries
|
|
59
|
+
* tree-sitter to extract doc comment entries; no front matter is
|
|
60
|
+
* recognized on source files.
|
|
52
61
|
*/
|
|
53
62
|
async function parseFile(content, options) {
|
|
54
63
|
const ext = (0, path_1.extname)(options.file);
|
|
55
64
|
if ((0, grammars_js_1.isSupportedExtension)(ext)) {
|
|
56
65
|
const language = await (0, grammars_js_1.loadGrammar)(ext);
|
|
57
|
-
|
|
66
|
+
const result = (0, source_js_1.parseSource)(content, {
|
|
67
|
+
file: options.file,
|
|
68
|
+
language,
|
|
69
|
+
});
|
|
70
|
+
return { entries: result.entries, diagnostics: [] };
|
|
58
71
|
}
|
|
59
|
-
|
|
72
|
+
const fm = (0, frontmatter_js_1.extractFrontMatter)(content, { file: options.file });
|
|
73
|
+
const body = fm.hadFrontMatter ? fm.markdown : content;
|
|
74
|
+
const isReferencesDoc = isReferencesDocument(options.file);
|
|
75
|
+
const { entries, diagnostics: parseDiagnostics } = (0, markdown_js_1.parseMarkdown)(body, {
|
|
76
|
+
file: options.file,
|
|
77
|
+
isReferencesDoc,
|
|
78
|
+
});
|
|
79
|
+
const document = fm.hadFrontMatter
|
|
80
|
+
? {
|
|
81
|
+
file: options.file,
|
|
82
|
+
attributes: fm.attributes,
|
|
83
|
+
properties: {},
|
|
84
|
+
}
|
|
85
|
+
: undefined;
|
|
86
|
+
return {
|
|
87
|
+
entries,
|
|
88
|
+
document,
|
|
89
|
+
diagnostics: [...fm.diagnostics, ...parseDiagnostics],
|
|
90
|
+
};
|
|
60
91
|
}
|
|
61
92
|
/**
|
|
62
93
|
* Detect table and figure captions in a Markdown string.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module parser/source
|
|
3
3
|
*
|
|
4
|
-
* Source-code doc-comment parser. Extracts MarkSpec
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Source-code doc-comment parser. Extracts MarkSpec entry blocks from doc
|
|
5
|
+
* comments in Rust, Kotlin, C, C++, and Java source files. Delegates parsed
|
|
6
|
+
* content to the markdown parser for entry extraction.
|
|
7
7
|
*/
|
|
8
8
|
import Parser from "web-tree-sitter";
|
|
9
9
|
import type { Entry } from "../model/mod.js";
|
|
@@ -14,16 +14,20 @@ export interface ParseSourceOptions {
|
|
|
14
14
|
/** Pre-loaded tree-sitter language grammar. */
|
|
15
15
|
readonly language: Parser.Language;
|
|
16
16
|
}
|
|
17
|
+
/** Result of parsing a source file. */
|
|
18
|
+
export interface ParseSourceResult {
|
|
19
|
+
/** Entries found in doc comment blocks. */
|
|
20
|
+
readonly entries: Entry[];
|
|
21
|
+
}
|
|
17
22
|
/**
|
|
18
|
-
* Parse a source file and return
|
|
23
|
+
* Parse a source file and return entries extracted from doc comments.
|
|
19
24
|
*
|
|
20
25
|
* Uses tree-sitter to parse the source, walks the AST to find doc comment
|
|
21
|
-
* nodes, strips comment prefixes, and delegates to the markdown parser
|
|
22
|
-
*
|
|
26
|
+
* nodes, strips comment prefixes, and delegates to the markdown parser for
|
|
27
|
+
* entry extraction. Doc comments that don't contain entry blocks are ignored.
|
|
23
28
|
*
|
|
24
29
|
* @param content - Source file text
|
|
25
30
|
* @param options - Parse options (language grammar, file path)
|
|
26
|
-
* @returns Array of parsed entries with `source: "doc-comment"`
|
|
27
31
|
*/
|
|
28
|
-
export declare function parseSource(content: string, options: ParseSourceOptions):
|
|
32
|
+
export declare function parseSource(content: string, options: ParseSourceOptions): ParseSourceResult;
|
|
29
33
|
//# sourceMappingURL=source.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../../src/parser/source.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAG7C,2CAA2C;AAC3C,MAAM,WAAW,kBAAkB;IACjC,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,+CAA+C;IAC/C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC;CACpC;AAYD
|
|
1
|
+
{"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../../src/parser/source.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAG7C,2CAA2C;AAC3C,MAAM,WAAW,kBAAkB;IACjC,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,+CAA+C;IAC/C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC;CACpC;AAED,uCAAuC;AACvC,MAAM,WAAW,iBAAiB;IAChC,2CAA2C;IAC3C,QAAQ,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;CAC3B;AAYD;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,kBAAkB,GAC1B,iBAAiB,CAsCnB"}
|