@temelj/mdx 0.15.0 → 0.16.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 +2 -0
- package/dist/compiler.mjs +2 -22
- package/dist/compiler.mjs.map +1 -1
- package/dist/frontmatter-decode.d.mts +15 -0
- package/dist/frontmatter-decode.d.mts.map +1 -0
- package/dist/frontmatter-decode.mjs +187 -0
- package/dist/frontmatter-decode.mjs.map +1 -0
- package/dist/frontmatter-schema.d.mts +8 -0
- package/dist/frontmatter-schema.d.mts.map +1 -0
- package/dist/frontmatter-schema.mjs +28 -0
- package/dist/frontmatter-schema.mjs.map +1 -0
- package/dist/frontmatter.d.mts +35 -10
- package/dist/frontmatter.d.mts.map +1 -1
- package/dist/frontmatter.mjs +97 -175
- package/dist/frontmatter.mjs.map +1 -1
- package/dist/mod.d.mts +2 -1
- package/dist/mod.mjs +3 -2
- package/dist/parser/materialize.mjs +1 -1
- package/dist/parser/materialize.mjs.map +1 -1
- package/dist/source-text.d.mts +2 -2
- package/dist/source-text.d.mts.map +1 -1
- package/dist/source-text.mjs +9 -5
- package/dist/source-text.mjs.map +1 -1
- package/package.json +2 -2
package/dist/frontmatter.mjs
CHANGED
|
@@ -1,187 +1,109 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { DiagnosticBag } from "./diagnostics.mjs";
|
|
2
|
+
import { LimitError, ParseError } from "./errors.mjs";
|
|
3
|
+
import { frontmatterSchemaValue } from "./frontmatter-schema.mjs";
|
|
4
|
+
import { SourceFile, sourceText } from "./source.mjs";
|
|
5
|
+
import { decodeFrontmatter } from "./frontmatter-decode.mjs";
|
|
6
|
+
import { resolveParserLimits } from "./parser/config.mjs";
|
|
7
|
+
import { isPromise } from "@temelj/value";
|
|
8
|
+
import { StandardSchemaAsyncValidationError } from "@temelj/standard-schema";
|
|
4
9
|
//#region src/frontmatter.ts
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
function decodeYaml(options) {
|
|
11
|
-
let document;
|
|
12
|
-
try {
|
|
13
|
-
document = parseDocument(options.source, {
|
|
14
|
-
customTags: [],
|
|
15
|
-
intAsBigInt: true,
|
|
16
|
-
logLevel: "silent",
|
|
17
|
-
prettyErrors: false,
|
|
18
|
-
resolveKnownTags: false,
|
|
19
|
-
schema: "core",
|
|
20
|
-
strict: true,
|
|
21
|
-
stringKeys: true,
|
|
22
|
-
uniqueKeys: true,
|
|
23
|
-
version: "1.2"
|
|
24
|
-
});
|
|
25
|
-
} catch (cause) {
|
|
26
|
-
addParserFailure(options, cause);
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
for (const warning of document.warnings) options.diagnostics.add({
|
|
30
|
-
code: yamlCode(warning.code),
|
|
31
|
-
message: warning.message,
|
|
32
|
-
severity: "warning",
|
|
33
|
-
span: relativeSpan(options.span, warning.pos[0], warning.pos[1])
|
|
34
|
-
});
|
|
35
|
-
for (const error of document.errors) options.diagnostics.add({
|
|
36
|
-
code: yamlCode(error.code),
|
|
37
|
-
message: error.message,
|
|
38
|
-
severity: "error",
|
|
39
|
-
span: relativeSpan(options.span, error.pos[0], error.pos[1])
|
|
40
|
-
});
|
|
41
|
-
if (document.errors.length > 0) return;
|
|
42
|
-
let parsed;
|
|
43
|
-
try {
|
|
44
|
-
parsed = document.contents === null ? {} : document.toJS({ maxAliasCount: maximumYamlAliases });
|
|
45
|
-
} catch (cause) {
|
|
46
|
-
addParserFailure(options, cause);
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
return convertRoot(parsed, options);
|
|
50
|
-
}
|
|
51
|
-
function decodeToml(options) {
|
|
52
|
-
let parsed;
|
|
53
|
-
try {
|
|
54
|
-
parsed = parse(options.source, {
|
|
55
|
-
integersAsBigInt: "asNeeded",
|
|
56
|
-
maxDepth: maximumTomlDepth
|
|
57
|
-
});
|
|
58
|
-
} catch (cause) {
|
|
59
|
-
if (cause instanceof TomlError) {
|
|
60
|
-
const offset = lineColumnOffset(options.source, cause.line, cause.column);
|
|
61
|
-
options.diagnostics.add({
|
|
62
|
-
code: "mdx.frontmatter.toml",
|
|
63
|
-
message: cause.message,
|
|
64
|
-
severity: "error",
|
|
65
|
-
span: relativeSpan(options.span, offset, offset + 1)
|
|
66
|
-
});
|
|
67
|
-
} else addParserFailure(options, cause);
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
return convertRoot(parsed, options);
|
|
71
|
-
}
|
|
72
|
-
function convertRoot(value, options) {
|
|
73
|
-
if (!isPlainObject(value)) {
|
|
74
|
-
options.diagnostics.add({
|
|
75
|
-
code: "mdx.frontmatter.root",
|
|
76
|
-
message: "FrontmatterNode must contain a mapping at its root",
|
|
77
|
-
severity: "error",
|
|
78
|
-
span: options.span
|
|
79
|
-
});
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
return convertObject(value, options, "$", /* @__PURE__ */ new WeakSet());
|
|
83
|
-
}
|
|
84
|
-
function convertValue(value, options, path, active) {
|
|
85
|
-
if (value === null || isBoolean(value) || isNumber(value) || isString(value)) return value;
|
|
86
|
-
if (isBigInt(value)) return value >= BigInt(Number.MIN_SAFE_INTEGER) && value <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(value) : value;
|
|
87
|
-
if (value instanceof TomlDate) return convertTemporal(value);
|
|
88
|
-
if (Array.isArray(value)) {
|
|
89
|
-
if (active.has(value)) return invalidValue(options, path, "cyclic alias");
|
|
90
|
-
active.add(value);
|
|
91
|
-
const converted = [];
|
|
92
|
-
for (const [index, item] of value.entries()) {
|
|
93
|
-
const result = convertValue(item, options, `${path}[${index}]`, active);
|
|
94
|
-
if (result === void 0) return;
|
|
95
|
-
converted.push(result);
|
|
96
|
-
}
|
|
97
|
-
active.delete(value);
|
|
98
|
-
Object.freeze(converted);
|
|
99
|
-
return converted;
|
|
100
|
-
}
|
|
101
|
-
if (isPlainObject(value)) return convertObject(value, options, path, active);
|
|
102
|
-
return invalidValue(options, path, describeValue(value));
|
|
103
|
-
}
|
|
104
|
-
function convertObject(value, options, path, active) {
|
|
105
|
-
if (active.has(value)) return invalidValue(options, path, "cyclic alias");
|
|
106
|
-
active.add(value);
|
|
107
|
-
const converted = {};
|
|
108
|
-
for (const [key, item] of Object.entries(value)) {
|
|
109
|
-
const result = convertValue(item, options, propertyPath(path, key), active);
|
|
110
|
-
if (result === void 0) return;
|
|
111
|
-
Object.defineProperty(converted, key, {
|
|
112
|
-
configurable: false,
|
|
113
|
-
enumerable: true,
|
|
114
|
-
value: result,
|
|
115
|
-
writable: false
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
active.delete(value);
|
|
119
|
-
Object.freeze(converted);
|
|
120
|
-
return converted;
|
|
121
|
-
}
|
|
122
|
-
function convertTemporal(value) {
|
|
123
|
-
const type = value.isDateTime() ? value.isLocal() ? "local-date-time" : "offset-date-time" : value.isDate() ? "local-date" : "local-time";
|
|
10
|
+
async function parseFrontmatter(input, options = {}) {
|
|
11
|
+
const { result, origin } = readFrontmatter(input, options);
|
|
12
|
+
if (options.frontmatterSchema === void 0) return result;
|
|
13
|
+
const validated = await options.frontmatterSchema["~standard"].validate(result.frontmatter);
|
|
124
14
|
return Object.freeze({
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
value: value.toISOString()
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
function invalidValue(options, path, description) {
|
|
131
|
-
options.diagnostics.add({
|
|
132
|
-
code: "mdx.frontmatter.value",
|
|
133
|
-
message: `Unsupported frontmatter value at ${path}: ${description}`,
|
|
134
|
-
severity: "error",
|
|
135
|
-
span: options.span
|
|
15
|
+
...result,
|
|
16
|
+
frontmatter: frontmatterSchemaValue(validated, result.file, origin)
|
|
136
17
|
});
|
|
137
18
|
}
|
|
138
|
-
function
|
|
139
|
-
const
|
|
140
|
-
options.
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
severity: "error",
|
|
144
|
-
span: options.span
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
function yamlCode(code) {
|
|
148
|
-
return code === "RESOURCE_EXHAUSTION" ? "mdx.frontmatter.resource" : "mdx.frontmatter.yaml";
|
|
149
|
-
}
|
|
150
|
-
function relativeSpan(span, start, end) {
|
|
151
|
-
const length = span.end - span.start;
|
|
152
|
-
const relativeStart = Math.max(0, Math.min(start, length));
|
|
153
|
-
const relativeEnd = Math.max(relativeStart, Math.min(end, length));
|
|
19
|
+
function parseFrontmatterSync(input, options = {}) {
|
|
20
|
+
const { result, origin } = readFrontmatter(input, options);
|
|
21
|
+
if (options.frontmatterSchema === void 0) return result;
|
|
22
|
+
const validated = options.frontmatterSchema["~standard"].validate(result.frontmatter);
|
|
23
|
+
if (isPromise(validated)) StandardSchemaAsyncValidationError.unsupported();
|
|
154
24
|
return Object.freeze({
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
end: span.start + relativeEnd
|
|
25
|
+
...result,
|
|
26
|
+
frontmatter: frontmatterSchemaValue(validated, result.file, origin)
|
|
158
27
|
});
|
|
159
28
|
}
|
|
160
|
-
function
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
if (
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
29
|
+
function readFrontmatter(input, options) {
|
|
30
|
+
const file = input instanceof SourceFile ? input : new SourceFile(input);
|
|
31
|
+
const { maximumSourceLength } = resolveParserLimits(options.limits);
|
|
32
|
+
if (file.length > maximumSourceLength) throw LimitError.exceeded(file, "maximumSourceLength", maximumSourceLength, void 0, file.length);
|
|
33
|
+
const source = sourceText(file);
|
|
34
|
+
const opening = readLine(source, 0);
|
|
35
|
+
const fence = source.slice(0, opening.contentEnd).trim();
|
|
36
|
+
const format = fence === "---" ? "yaml" : fence === "+++" ? "toml" : void 0;
|
|
37
|
+
if (format !== void 0 && (options.format === void 0 || options.format === "auto" || options.format === format)) {
|
|
38
|
+
const valueStart = opening.end;
|
|
39
|
+
for (let start = valueStart; start < source.length;) {
|
|
40
|
+
const line = readLine(source, start);
|
|
41
|
+
if (source.slice(start, line.contentEnd).trim() === fence) {
|
|
42
|
+
let valueEnd = start;
|
|
43
|
+
if (valueEnd > valueStart && source.char(valueEnd - 1) === "\n") valueEnd--;
|
|
44
|
+
if (valueEnd > valueStart && source.char(valueEnd - 1) === "\r") valueEnd--;
|
|
45
|
+
const diagnostics = new DiagnosticBag();
|
|
46
|
+
const frontmatter = decodeFrontmatter({
|
|
47
|
+
diagnostics,
|
|
48
|
+
format,
|
|
49
|
+
source: source.slice(valueStart, valueEnd),
|
|
50
|
+
span: {
|
|
51
|
+
file,
|
|
52
|
+
start: valueStart,
|
|
53
|
+
end: valueEnd
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
if (frontmatter === void 0) {
|
|
57
|
+
const [first, ...rest] = diagnostics.snapshot().filter((diagnostic) => diagnostic.severity === "error");
|
|
58
|
+
if (first === void 0) throw new Error("Invalid frontmatter did not produce an error diagnostic");
|
|
59
|
+
throw ParseError.invalidSyntax(file, [first, ...rest]);
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
result: Object.freeze({
|
|
63
|
+
file,
|
|
64
|
+
frontmatter,
|
|
65
|
+
format,
|
|
66
|
+
diagnostics: diagnostics.snapshot()
|
|
67
|
+
}),
|
|
68
|
+
origin: {
|
|
69
|
+
start: source.char(0) === "" ? 1 : 0,
|
|
70
|
+
end: line.end
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
start = line.end;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
result: Object.freeze({
|
|
79
|
+
file,
|
|
80
|
+
frontmatter: Object.freeze({}),
|
|
81
|
+
format: void 0,
|
|
82
|
+
diagnostics: Object.freeze([])
|
|
83
|
+
}),
|
|
84
|
+
origin: void 0
|
|
85
|
+
};
|
|
175
86
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
87
|
+
/** Reads one physical line without indexing or normalizing the rest of the document. */
|
|
88
|
+
function readLine(source, start) {
|
|
89
|
+
let end = start;
|
|
90
|
+
while (end < source.length) {
|
|
91
|
+
const character = source.char(end);
|
|
92
|
+
if (character === "\n" || character === "\r") {
|
|
93
|
+
const endingLength = character === "\r" && source.char(end + 1) === "\n" ? 2 : 1;
|
|
94
|
+
return {
|
|
95
|
+
contentEnd: end,
|
|
96
|
+
end: end + endingLength
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
end++;
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
contentEnd: end,
|
|
103
|
+
end
|
|
104
|
+
};
|
|
183
105
|
}
|
|
184
106
|
//#endregion
|
|
185
|
-
export {
|
|
107
|
+
export { parseFrontmatter, parseFrontmatterSync };
|
|
186
108
|
|
|
187
109
|
//# sourceMappingURL=frontmatter.mjs.map
|
package/dist/frontmatter.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frontmatter.mjs","names":["parseToml"],"sources":["../src/frontmatter.ts"],"sourcesContent":["import {\n isBoolean,\n isNumber,\n isString,\n isBigInt,\n isFunction,\n isSymbol,\n isObject,\n isPlainObject,\n} from \"@temelj/value\";\nimport { parse as parseToml, TomlDate, TomlError } from \"smol-toml\";\nimport { parseDocument } from \"yaml\";\n\nimport type { DiagnosticReporter } from \"./diagnostics.ts\";\nimport type { FrontmatterObject, FrontmatterTemporal, FrontmatterValue } from \"./model.ts\";\nimport type { SourceSpan } from \"./source.ts\";\nimport type { FrontmatterFormat } from \"./syntax-options.ts\";\n\ninterface DecodeOptions {\n readonly diagnostics: DiagnosticReporter;\n readonly format: FrontmatterFormat;\n readonly source: string;\n readonly span: SourceSpan;\n}\n\nconst maximumYamlAliases = 100;\n\nconst maximumTomlDepth = 256;\n\nexport function decodeFrontmatter(options: DecodeOptions): FrontmatterObject | undefined {\n return options.format === \"yaml\" ? decodeYaml(options) : decodeToml(options);\n}\n\nfunction decodeYaml(options: DecodeOptions): FrontmatterObject | undefined {\n let document: ReturnType<typeof parseDocument>;\n\n try {\n document = parseDocument(options.source, {\n customTags: [],\n intAsBigInt: true,\n logLevel: \"silent\",\n prettyErrors: false,\n resolveKnownTags: false,\n schema: \"core\",\n strict: true,\n stringKeys: true,\n uniqueKeys: true,\n version: \"1.2\",\n });\n } catch (cause) {\n addParserFailure(options, cause);\n\n return undefined;\n }\n\n for (const warning of document.warnings) {\n options.diagnostics.add({\n code: yamlCode(warning.code),\n message: warning.message,\n severity: \"warning\",\n span: relativeSpan(options.span, warning.pos[0], warning.pos[1]),\n });\n }\n\n for (const error of document.errors) {\n options.diagnostics.add({\n code: yamlCode(error.code),\n message: error.message,\n severity: \"error\",\n span: relativeSpan(options.span, error.pos[0], error.pos[1]),\n });\n }\n\n if (document.errors.length > 0) {\n return undefined;\n }\n\n let parsed: unknown;\n\n try {\n parsed = document.contents === null ? {} : document.toJS({ maxAliasCount: maximumYamlAliases });\n } catch (cause) {\n addParserFailure(options, cause);\n\n return undefined;\n }\n\n return convertRoot(parsed, options);\n}\n\nfunction decodeToml(options: DecodeOptions): FrontmatterObject | undefined {\n let parsed: unknown;\n\n try {\n parsed = parseToml(options.source, {\n integersAsBigInt: \"asNeeded\",\n maxDepth: maximumTomlDepth,\n });\n } catch (cause) {\n if (cause instanceof TomlError) {\n const offset = lineColumnOffset(options.source, cause.line, cause.column);\n options.diagnostics.add({\n code: \"mdx.frontmatter.toml\",\n message: cause.message,\n severity: \"error\",\n span: relativeSpan(options.span, offset, offset + 1),\n });\n } else {\n addParserFailure(options, cause);\n }\n\n return undefined;\n }\n\n return convertRoot(parsed, options);\n}\n\n// oxlint-disable-next-line anti-slop/no-unknown-parameters -- YAML/TOML root input is validated here.\nfunction convertRoot(value: unknown, options: DecodeOptions): FrontmatterObject | undefined {\n if (!isPlainObject(value)) {\n options.diagnostics.add({\n code: \"mdx.frontmatter.root\",\n message: \"FrontmatterNode must contain a mapping at its root\",\n severity: \"error\",\n span: options.span,\n });\n\n return undefined;\n }\n\n return convertObject(value, options, \"$\", new WeakSet<object>());\n}\n\nfunction convertValue(\n // oxlint-disable-next-line anti-slop/no-unknown-parameters -- Recursively validates parser values before producing FrontmatterValue.\n value: unknown,\n options: DecodeOptions,\n path: string,\n active: WeakSet<object>,\n): FrontmatterValue | undefined {\n if (value === null || isBoolean(value) || isNumber(value) || isString(value)) {\n return value;\n }\n\n if (isBigInt(value)) {\n return value >= BigInt(Number.MIN_SAFE_INTEGER) && value <= BigInt(Number.MAX_SAFE_INTEGER)\n ? Number(value)\n : value;\n }\n\n if (value instanceof TomlDate) {\n return convertTemporal(value);\n }\n\n if (Array.isArray(value)) {\n if (active.has(value)) {\n return invalidValue(options, path, \"cyclic alias\");\n }\n\n active.add(value);\n const converted: FrontmatterValue[] = [];\n\n for (const [index, item] of value.entries()) {\n const result = convertValue(item, options, `${path}[${index}]`, active);\n\n if (result === undefined) {\n return undefined;\n }\n\n converted.push(result);\n }\n\n active.delete(value);\n Object.freeze(converted);\n\n return converted;\n }\n\n if (isPlainObject(value)) {\n return convertObject(value, options, path, active);\n }\n\n return invalidValue(options, path, describeValue(value));\n}\n\nfunction convertObject(\n // oxlint-disable-next-line anti-slop/no-object-parameters -- YAML/TOML mapping boundary; every entry is converted to FrontmatterValue below.\n value: object,\n options: DecodeOptions,\n path: string,\n active: WeakSet<object>,\n): FrontmatterObject | undefined {\n if (active.has(value)) {\n return invalidValue(options, path, \"cyclic alias\");\n }\n\n active.add(value);\n const converted: Record<string, FrontmatterValue> = {};\n\n for (const [key, item] of Object.entries(value)) {\n const itemPath = propertyPath(path, key);\n const result = convertValue(item, options, itemPath, active);\n\n if (result === undefined) {\n return undefined;\n }\n\n Object.defineProperty(converted, key, {\n configurable: false,\n enumerable: true,\n value: result,\n writable: false,\n });\n }\n\n active.delete(value);\n Object.freeze(converted);\n\n return converted;\n}\n\nfunction convertTemporal(value: TomlDate): FrontmatterTemporal {\n const type = value.isDateTime()\n ? value.isLocal()\n ? \"local-date-time\"\n : \"offset-date-time\"\n : value.isDate()\n ? \"local-date\"\n : \"local-time\";\n\n return Object.freeze({ kind: \"temporal\", type, value: value.toISOString() });\n}\n\nfunction invalidValue(options: DecodeOptions, path: string, description: string): undefined {\n options.diagnostics.add({\n code: \"mdx.frontmatter.value\",\n message: `Unsupported frontmatter value at ${path}: ${description}`,\n severity: \"error\",\n span: options.span,\n });\n\n return undefined;\n}\n\nfunction addParserFailure(options: DecodeOptions, cause: unknown): void {\n const message = cause instanceof Error ? cause.message : String(cause);\n options.diagnostics.add({\n code: `mdx.frontmatter.${options.format}`,\n message,\n severity: \"error\",\n span: options.span,\n });\n}\n\nfunction yamlCode(code: string): string {\n return code === \"RESOURCE_EXHAUSTION\" ? \"mdx.frontmatter.resource\" : \"mdx.frontmatter.yaml\";\n}\n\nfunction relativeSpan(span: SourceSpan, start: number, end: number): SourceSpan {\n const length = span.end - span.start;\n const relativeStart = Math.max(0, Math.min(start, length));\n const relativeEnd = Math.max(relativeStart, Math.min(end, length));\n\n return Object.freeze({\n file: span.file,\n start: span.start + relativeStart,\n end: span.start + relativeEnd,\n });\n}\n\nfunction lineColumnOffset(source: string, line: number, column: number): number {\n const lineStart = lineStartOffsets(source)[Math.max(0, line - 1)] ?? source.length;\n\n return Math.min(source.length, lineStart + Math.max(0, column - 1));\n}\n\nfunction propertyPath(path: string, key: string): string {\n return /^[A-Za-z_$][\\w$]*$/u.test(key) ? `${path}.${key}` : `${path}[${JSON.stringify(key)}]`;\n}\n\n// oxlint-disable-next-line anti-slop/no-unknown-parameters -- Describes a rejected value at the YAML/TOML validation boundary.\nfunction describeValue(value: unknown): string {\n if (value === undefined) {\n return \"undefined\";\n }\n\n if (isFunction(value)) {\n return \"function\";\n }\n\n if (isSymbol(value)) {\n return \"symbol\";\n }\n\n if (value instanceof Map) {\n return \"Map\";\n }\n\n if (value instanceof Set) {\n return \"Set\";\n }\n\n if (value instanceof Date) {\n return \"Date\";\n }\n\n return isObject(value) ? (value.constructor?.name ?? \"object\") : String(value);\n}\n\nfunction lineStartOffsets(source: string): readonly number[] {\n const offsets = [0];\n\n for (let index = 0; index < source.length; index++) {\n if (source[index] === \"\\r\") {\n if (source[index + 1] === \"\\n\") {\n index++;\n }\n\n offsets.push(index + 1);\n } else if (source[index] === \"\\n\") {\n offsets.push(index + 1);\n }\n }\n\n return offsets;\n}\n"],"mappings":";;;;AAyBA,MAAM,qBAAqB;AAE3B,MAAM,mBAAmB;AAEzB,SAAgB,kBAAkB,SAAuD;CACvF,OAAO,QAAQ,WAAW,SAAS,WAAW,OAAO,IAAI,WAAW,OAAO;AAC7E;AAEA,SAAS,WAAW,SAAuD;CACzE,IAAI;CAEJ,IAAI;EACF,WAAW,cAAc,QAAQ,QAAQ;GACvC,YAAY,CAAC;GACb,aAAa;GACb,UAAU;GACV,cAAc;GACd,kBAAkB;GAClB,QAAQ;GACR,QAAQ;GACR,YAAY;GACZ,YAAY;GACZ,SAAS;EACX,CAAC;CACH,SAAS,OAAO;EACd,iBAAiB,SAAS,KAAK;EAE/B;CACF;CAEA,KAAK,MAAM,WAAW,SAAS,UAC7B,QAAQ,YAAY,IAAI;EACtB,MAAM,SAAS,QAAQ,IAAI;EAC3B,SAAS,QAAQ;EACjB,UAAU;EACV,MAAM,aAAa,QAAQ,MAAM,QAAQ,IAAI,IAAI,QAAQ,IAAI,EAAE;CACjE,CAAC;CAGH,KAAK,MAAM,SAAS,SAAS,QAC3B,QAAQ,YAAY,IAAI;EACtB,MAAM,SAAS,MAAM,IAAI;EACzB,SAAS,MAAM;EACf,UAAU;EACV,MAAM,aAAa,QAAQ,MAAM,MAAM,IAAI,IAAI,MAAM,IAAI,EAAE;CAC7D,CAAC;CAGH,IAAI,SAAS,OAAO,SAAS,GAC3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OAAO;CAGT,OAAO,SAAS,KAAK,IAAK,MAAM,aAAa,QAAQ,WAAY,OAAO,KAAK;AAC/E;AAEA,SAAS,iBAAiB,QAAmC;CAC3D,MAAM,UAAU,CAAC,CAAC;CAElB,KAAK,IAAI,QAAQ,GAAG,QAAQ,OAAO,QAAQ,SACzC,IAAI,OAAO,WAAW,MAAM;EAC1B,IAAI,OAAO,QAAQ,OAAO,MACxB;EAGF,QAAQ,KAAK,QAAQ,CAAC;CACxB,OAAO,IAAI,OAAO,WAAW,MAC3B,QAAQ,KAAK,QAAQ,CAAC;CAI1B,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"frontmatter.mjs","names":[],"sources":["../src/frontmatter.ts"],"sourcesContent":["import type { Schema, SchemaOutput } from \"@temelj/standard-schema\";\n\nimport { StandardSchemaAsyncValidationError } from \"@temelj/standard-schema\";\nimport { isPromise } from \"@temelj/value\";\n\nimport type { Diagnostic } from \"./diagnostics.ts\";\nimport type { FrontmatterObject } from \"./model.ts\";\nimport type { ParserLimits } from \"./parser/config.ts\";\nimport type { SourceRange } from \"./ranges.ts\";\nimport type { SourceText } from \"./source-text.ts\";\nimport type { FrontmatterFormat, FrontmatterMode } from \"./syntax-options.ts\";\n\nimport { DiagnosticBag } from \"./diagnostics.ts\";\nimport { LimitError, ParseError } from \"./errors.ts\";\nimport { decodeFrontmatter } from \"./frontmatter-decode.ts\";\nimport { frontmatterSchemaValue } from \"./frontmatter-schema.ts\";\nimport { resolveParserLimits } from \"./parser/config.ts\";\nimport { SourceFile, sourceText } from \"./source.ts\";\n\nexport interface FrontmatterParseOptions {\n /** Formats to recognize. Defaults to both YAML and TOML. */\n readonly format?: FrontmatterMode;\n /** Limits the entire input length in UTF-16 code units, without scanning its body. */\n readonly limits?: Pick<ParserLimits, \"maximumSourceLength\">;\n}\n\nexport interface FrontmatterParseSchemaOptions<\n TSchema extends Schema,\n> extends FrontmatterParseOptions {\n readonly frontmatterSchema: TSchema;\n}\n\nexport interface FrontmatterParseResult<T = FrontmatterObject> {\n readonly file: SourceFile;\n readonly frontmatter: T;\n /** Undefined when no complete, enabled frontmatter block was found. */\n readonly format: FrontmatterFormat | undefined;\n readonly diagnostics: readonly Diagnostic[];\n}\n\n/**\n * Reads only the opening frontmatter block and optionally validates its metadata.\n * @throws {ParseError} Invalid YAML or TOML.\n * @throws {FrontmatterError} Schema validation fails.\n * @throws {LimitError | ConfigurationError} Invalid or exceeded source-length limit.\n */\nexport function parseFrontmatter<TSchema extends Schema>(\n input: string | SourceFile,\n options: FrontmatterParseSchemaOptions<TSchema>,\n): Promise<FrontmatterParseResult<SchemaOutput<TSchema>>>;\nexport function parseFrontmatter(\n input: string | SourceFile,\n options?: FrontmatterParseOptions,\n): Promise<FrontmatterParseResult>;\nexport async function parseFrontmatter(\n input: string | SourceFile,\n options: FrontmatterParseOptions & { readonly frontmatterSchema?: Schema } = {},\n): Promise<FrontmatterParseResult<unknown>> {\n const { result, origin } = readFrontmatter(input, options);\n\n if (options.frontmatterSchema === undefined) {\n return result;\n }\n\n const validated = await options.frontmatterSchema[\"~standard\"].validate(result.frontmatter);\n\n return Object.freeze({\n ...result,\n frontmatter: frontmatterSchemaValue(validated, result.file, origin),\n });\n}\n\n/**\n * Reads frontmatter synchronously, including synchronous schema validation.\n * @throws {StandardSchemaAsyncValidationError} The schema returns a promise.\n * @throws {ParseError | FrontmatterError | LimitError | ConfigurationError} Parsing fails.\n */\nexport function parseFrontmatterSync<TSchema extends Schema>(\n input: string | SourceFile,\n options: FrontmatterParseSchemaOptions<TSchema>,\n): FrontmatterParseResult<SchemaOutput<TSchema>>;\nexport function parseFrontmatterSync(\n input: string | SourceFile,\n options?: FrontmatterParseOptions,\n): FrontmatterParseResult;\nexport function parseFrontmatterSync(\n input: string | SourceFile,\n options: FrontmatterParseOptions & { readonly frontmatterSchema?: Schema } = {},\n): FrontmatterParseResult<unknown> {\n const { result, origin } = readFrontmatter(input, options);\n\n if (options.frontmatterSchema === undefined) {\n return result;\n }\n\n const validated = options.frontmatterSchema[\"~standard\"].validate(result.frontmatter);\n\n if (isPromise(validated)) {\n StandardSchemaAsyncValidationError.unsupported();\n }\n\n return Object.freeze({\n ...result,\n frontmatter: frontmatterSchemaValue(validated, result.file, origin),\n });\n}\n\ninterface ReadFrontmatterResult {\n readonly result: FrontmatterParseResult;\n readonly origin: SourceRange | undefined;\n}\n\nfunction readFrontmatter(\n input: string | SourceFile,\n options: FrontmatterParseOptions,\n): ReadFrontmatterResult {\n const file = input instanceof SourceFile ? input : new SourceFile(input);\n const { maximumSourceLength } = resolveParserLimits(options.limits);\n\n if (file.length > maximumSourceLength) {\n throw LimitError.exceeded(\n file,\n \"maximumSourceLength\",\n maximumSourceLength,\n undefined,\n file.length,\n );\n }\n\n const source = sourceText(file);\n const opening = readLine(source, 0);\n const fence = source.slice(0, opening.contentEnd).trim();\n const format = fence === \"---\" ? \"yaml\" : fence === \"+++\" ? \"toml\" : undefined;\n\n if (\n format !== undefined &&\n (options.format === undefined || options.format === \"auto\" || options.format === format)\n ) {\n const valueStart = opening.end;\n\n for (let start = valueStart; start < source.length;) {\n const line = readLine(source, start);\n\n if (source.slice(start, line.contentEnd).trim() === fence) {\n let valueEnd = start;\n\n if (valueEnd > valueStart && source.char(valueEnd - 1) === \"\\n\") {\n valueEnd--;\n }\n\n if (valueEnd > valueStart && source.char(valueEnd - 1) === \"\\r\") {\n valueEnd--;\n }\n\n const diagnostics = new DiagnosticBag();\n\n const frontmatter = decodeFrontmatter({\n diagnostics,\n format,\n source: source.slice(valueStart, valueEnd),\n span: { file, start: valueStart, end: valueEnd },\n });\n\n if (frontmatter === undefined) {\n const [first, ...rest] = diagnostics\n .snapshot()\n .filter((diagnostic) => diagnostic.severity === \"error\");\n\n if (first === undefined) {\n throw new Error(\"Invalid frontmatter did not produce an error diagnostic\");\n }\n\n throw ParseError.invalidSyntax(file, [first, ...rest]);\n }\n\n return {\n result: Object.freeze({ file, frontmatter, format, diagnostics: diagnostics.snapshot() }),\n origin: { start: source.char(0) === \"\\uFEFF\" ? 1 : 0, end: line.end },\n };\n }\n\n start = line.end;\n }\n }\n\n return {\n result: Object.freeze({\n file,\n frontmatter: Object.freeze({}),\n format: undefined,\n diagnostics: Object.freeze([]),\n }),\n origin: undefined,\n };\n}\n\ninterface FrontmatterLine {\n readonly contentEnd: number;\n readonly end: number;\n}\n\n/** Reads one physical line without indexing or normalizing the rest of the document. */\nfunction readLine(source: SourceText, start: number): FrontmatterLine {\n let end = start;\n\n while (end < source.length) {\n const character = source.char(end);\n\n if (character === \"\\n\" || character === \"\\r\") {\n const endingLength = character === \"\\r\" && source.char(end + 1) === \"\\n\" ? 2 : 1;\n\n return { contentEnd: end, end: end + endingLength };\n }\n\n end++;\n }\n\n return { contentEnd: end, end };\n}\n"],"mappings":";;;;;;;;;AAsDA,eAAsB,iBACpB,OACA,UAA6E,CAAC,GACpC;CAC1C,MAAM,EAAE,QAAQ,WAAW,gBAAgB,OAAO,OAAO;CAEzD,IAAI,QAAQ,sBAAsB,KAAA,GAChC,OAAO;CAGT,MAAM,YAAY,MAAM,QAAQ,kBAAkB,YAAY,CAAC,SAAS,OAAO,WAAW;CAE1F,OAAO,OAAO,OAAO;EACnB,GAAG;EACH,aAAa,uBAAuB,WAAW,OAAO,MAAM,MAAM;CACpE,CAAC;AACH;AAeA,SAAgB,qBACd,OACA,UAA6E,CAAC,GAC7C;CACjC,MAAM,EAAE,QAAQ,WAAW,gBAAgB,OAAO,OAAO;CAEzD,IAAI,QAAQ,sBAAsB,KAAA,GAChC,OAAO;CAGT,MAAM,YAAY,QAAQ,kBAAkB,YAAY,CAAC,SAAS,OAAO,WAAW;CAEpF,IAAI,UAAU,SAAS,GACrB,mCAAmC,YAAY;CAGjD,OAAO,OAAO,OAAO;EACnB,GAAG;EACH,aAAa,uBAAuB,WAAW,OAAO,MAAM,MAAM;CACpE,CAAC;AACH;AAOA,SAAS,gBACP,OACA,SACuB;CACvB,MAAM,OAAO,iBAAiB,aAAa,QAAQ,IAAI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;MAAQ,aAAa,YAAY,SAAS;KAAE,CAAC;KACxF,QAAQ;MAAE,OAAO,OAAO,KAAK,CAAC,MAAM,MAAW,IAAI;MAAG,KAAK,KAAK;KAAI;IACtE;GACF;GAEA,QAAQ,KAAK;EACf;CACF;CAEA,OAAO;EACL,QAAQ,OAAO,OAAO;GACpB;GACA,aAAa,OAAO,OAAO,CAAC,CAAC;GAC7B,QAAQ,KAAA;GACR,aAAa,OAAO,OAAO,CAAC,CAAC;EAC/B,CAAC;EACD,QAAQ,KAAA;CACV;AACF;;AAQA,SAAS,SAAS,QAAoB,OAAgC;CACpE,IAAI,MAAM;CAEV,OAAO,MAAM,OAAO,QAAQ;EAC1B,MAAM,YAAY,OAAO,KAAK,GAAG;EAEjC,IAAI,cAAc,QAAQ,cAAc,MAAM;GAC5C,MAAM,eAAe,cAAc,QAAQ,OAAO,KAAK,MAAM,CAAC,MAAM,OAAO,IAAI;GAE/E,OAAO;IAAE,YAAY;IAAK,KAAK,MAAM;GAAa;EACpD;EAEA;CACF;CAEA,OAAO;EAAE,YAAY;EAAK;CAAI;AAChC"}
|
package/dist/mod.d.mts
CHANGED
|
@@ -13,6 +13,7 @@ import { CompileArtifact, CompileOptions, CompileOutputFormat, CompileResult, Co
|
|
|
13
13
|
import { CompilationInvariant, CompilationIssue, CompileError, CompileLimit, ConfigurationError, ConfigurationIssue, FrontmatterError, FrontmatterIssue, InputError, InputIssue, LimitError, MdxError, ParseError, TransformError, TransformIssue, TransformTarget } from "./errors.mjs";
|
|
14
14
|
import { FormatOptions } from "./format-context.mjs";
|
|
15
15
|
import { formatMdx } from "./format.mjs";
|
|
16
|
+
import { FrontmatterParseOptions, FrontmatterParseResult, FrontmatterParseSchemaOptions, parseFrontmatter, parseFrontmatterSync } from "./frontmatter.mjs";
|
|
16
17
|
import { HtmlFormatOptions, formatHtml } from "./html-format.mjs";
|
|
17
18
|
import { BlockId, CompletedBlock, MdxEdit, MdxPreview, MdxStreamChange, MdxStreamCompletion, MdxStreamLimits, MdxStreamOptions, MdxStreamSnapshot, PreviewBlock, StreamBlock, StreamDependencies } from "./stream-types.mjs";
|
|
18
19
|
import { MdxStream } from "./stream.mjs";
|
|
@@ -22,4 +23,4 @@ import { TreeCursor } from "./tree.mjs";
|
|
|
22
23
|
import { HtmlRewriteHandlers, MdxRewriteHandlers, rewriteHtml, rewriteMdx, selectHtml, selectMdx, walkHtml, walkMdx } from "./traversal.mjs";
|
|
23
24
|
import { ProcessInput, ProcessOptions, ProcessResult, Processor, ProcessorOptions } from "./processor.mjs";
|
|
24
25
|
import { MdxBlockEvent, MdxEventDiagnostic, StreamBlockEventsOptions, applyBlockEvent, blockEvent, completionEvent, previewDocument, streamBlockEvents } from "./stream-events.mjs";
|
|
25
|
-
export { type BlockExpressionNode, type BlockId, type BlockQuoteNode, type CodeBlockNode, type CompilationInvariant, type CompilationIssue, type CompileArtifact, CompileError, type CompileLimit, type CompileOptions, type CompileOutputFormat, type CompileResult, type CompileSchemaOptions, type CompiledComponents, type CompletedBlock, ConfigurationError, type ConfigurationIssue, type ContainerDirectiveNode, type DefinitionNode, type DeleteNode, type Diagnostic, type DiagnosticFormatOptions, type DiagnosticReporter, type DiagnosticSeverity, type DirectiveAttribute, type DirectiveLabelNode, type DisplayMathNode, type DocumentIndex, type DocumentNode, type EmphasisNode, type EsmNode, type FlowContent, type FootnoteDefinitionNode, type FootnoteReferenceNode, type FormatOptions, FrontmatterError, type FrontmatterFormat, type FrontmatterIssue, type FrontmatterMode, type FrontmatterNode, type FrontmatterObject, type FrontmatterTemporal, type FrontmatterTemporalType, type FrontmatterValue, type FunctionBodyCompileArtifact, type HardBreakNode, type HeadingDepth, type HeadingNode, type HtmlAttributeList, type HtmlAttributeValue, type HtmlAttributes, type HtmlCodeBlockNode, type HtmlCommentNode, type HtmlDoctypeNode, type HtmlElementNode, type HtmlExpressionNode, type HtmlFootnoteReferenceNode, type HtmlFootnoteSectionNode, type HtmlFormatOptions, type HtmlJsxNode, type HtmlKind, type HtmlMathNode, type HtmlNode, type HtmlNodeForKind, type HtmlPendingConstruct, type HtmlPendingNode, type HtmlRawNode, type HtmlRenderOptions, type HtmlRewriteHandlers, type HtmlRootNode, type HtmlSemanticNode, HtmlStreamRenderer, type HtmlTextNode, type HtmlUnresolvedReferenceNode, type ImageNode, type ImageReferenceNode, type InlineCodeNode, type InlineExpressionNode, type InlineMathNode, InputError, type InputIssue, type JsxAttribute, type JsxAttributeLike, type JsxAttributeValue, type JsxAttributeValueExpression, type JsxFlowElementNode, type JsxSpreadAttribute, type JsxTextElementNode, type LeafDirectiveNode, LimitError, type LinkNode, type LinkReferenceNode, type ListItemNode, type ListNode, type MathFormat, type MathMode, type MathRenderStyle, type MdxBlockEvent, type MdxEdit, MdxError, type MdxEventDiagnostic, type MdxKind, type MdxNode, type MdxNodeForKind, type MdxPreview, type MdxRewriteHandlers, MdxStream, type MdxStreamChange, type MdxStreamCompletion, type MdxStreamLimits, type MdxStreamOptions, type MdxStreamSnapshot, type MdxTransportValue, type ParagraphNode, ParseError, type ParseOptions, type ParseResult, type ParserLimit, type ParserLimits, type PhrasingContent, type PreviewBlock, type ProcessInput, type ProcessOptions, type ProcessResult, Processor, type ProcessorOptions, type ProgramCompileArtifact, type RawHtmlBlockNode, type RawHtmlInlineNode, type ReferenceKind, type RelatedInformation, SourceBuffer, SourceFile, type SourceFileInput, type SourceLocation, type SourceMap, type SourceRange, type SourceSpan, type StreamBlock, type StreamBlockEventsOptions, type StreamDependencies, type StrongNode, type SyntaxOptions, type TableAlignment, type TableCellNode, type TableNode, type TableRowNode, type TextDirectiveNode, type TextNode, type ThematicBreakNode, TransformError, type TransformIssue, type TransformTarget, TreeCursor, applyBlockEvent, blockEvent, compile, completionEvent, defaultParserLimits, documentFrontmatter, formatDiagnostic, formatHtml, formatMdx, hasErrorDiagnostics, htmlChildren, htmlClassNames, htmlFallback, htmlText, indexDocument, isFlowContent, isHtmlAttributeList, isPhrasingContent, lowerHtml, mdxChildren, nodeText, normalizeIdentifier, parse, pendingFallback, previewDocument, rewriteHtml, rewriteMdx, selectHtml, selectMdx, streamBlockEvents, walkHtml, walkMdx };
|
|
26
|
+
export { type BlockExpressionNode, type BlockId, type BlockQuoteNode, type CodeBlockNode, type CompilationInvariant, type CompilationIssue, type CompileArtifact, CompileError, type CompileLimit, type CompileOptions, type CompileOutputFormat, type CompileResult, type CompileSchemaOptions, type CompiledComponents, type CompletedBlock, ConfigurationError, type ConfigurationIssue, type ContainerDirectiveNode, type DefinitionNode, type DeleteNode, type Diagnostic, type DiagnosticFormatOptions, type DiagnosticReporter, type DiagnosticSeverity, type DirectiveAttribute, type DirectiveLabelNode, type DisplayMathNode, type DocumentIndex, type DocumentNode, type EmphasisNode, type EsmNode, type FlowContent, type FootnoteDefinitionNode, type FootnoteReferenceNode, type FormatOptions, FrontmatterError, type FrontmatterFormat, type FrontmatterIssue, type FrontmatterMode, type FrontmatterNode, type FrontmatterObject, FrontmatterParseOptions, FrontmatterParseResult, FrontmatterParseSchemaOptions, type FrontmatterTemporal, type FrontmatterTemporalType, type FrontmatterValue, type FunctionBodyCompileArtifact, type HardBreakNode, type HeadingDepth, type HeadingNode, type HtmlAttributeList, type HtmlAttributeValue, type HtmlAttributes, type HtmlCodeBlockNode, type HtmlCommentNode, type HtmlDoctypeNode, type HtmlElementNode, type HtmlExpressionNode, type HtmlFootnoteReferenceNode, type HtmlFootnoteSectionNode, type HtmlFormatOptions, type HtmlJsxNode, type HtmlKind, type HtmlMathNode, type HtmlNode, type HtmlNodeForKind, type HtmlPendingConstruct, type HtmlPendingNode, type HtmlRawNode, type HtmlRenderOptions, type HtmlRewriteHandlers, type HtmlRootNode, type HtmlSemanticNode, HtmlStreamRenderer, type HtmlTextNode, type HtmlUnresolvedReferenceNode, type ImageNode, type ImageReferenceNode, type InlineCodeNode, type InlineExpressionNode, type InlineMathNode, InputError, type InputIssue, type JsxAttribute, type JsxAttributeLike, type JsxAttributeValue, type JsxAttributeValueExpression, type JsxFlowElementNode, type JsxSpreadAttribute, type JsxTextElementNode, type LeafDirectiveNode, LimitError, type LinkNode, type LinkReferenceNode, type ListItemNode, type ListNode, type MathFormat, type MathMode, type MathRenderStyle, type MdxBlockEvent, type MdxEdit, MdxError, type MdxEventDiagnostic, type MdxKind, type MdxNode, type MdxNodeForKind, type MdxPreview, type MdxRewriteHandlers, MdxStream, type MdxStreamChange, type MdxStreamCompletion, type MdxStreamLimits, type MdxStreamOptions, type MdxStreamSnapshot, type MdxTransportValue, type ParagraphNode, ParseError, type ParseOptions, type ParseResult, type ParserLimit, type ParserLimits, type PhrasingContent, type PreviewBlock, type ProcessInput, type ProcessOptions, type ProcessResult, Processor, type ProcessorOptions, type ProgramCompileArtifact, type RawHtmlBlockNode, type RawHtmlInlineNode, type ReferenceKind, type RelatedInformation, SourceBuffer, SourceFile, type SourceFileInput, type SourceLocation, type SourceMap, type SourceRange, type SourceSpan, type StreamBlock, type StreamBlockEventsOptions, type StreamDependencies, type StrongNode, type SyntaxOptions, type TableAlignment, type TableCellNode, type TableNode, type TableRowNode, type TextDirectiveNode, type TextNode, type ThematicBreakNode, TransformError, type TransformIssue, type TransformTarget, TreeCursor, applyBlockEvent, blockEvent, compile, completionEvent, defaultParserLimits, documentFrontmatter, formatDiagnostic, formatHtml, formatMdx, hasErrorDiagnostics, htmlChildren, htmlClassNames, htmlFallback, htmlText, indexDocument, isFlowContent, isHtmlAttributeList, isPhrasingContent, lowerHtml, mdxChildren, nodeText, normalizeIdentifier, parse, parseFrontmatter, parseFrontmatterSync, pendingFallback, previewDocument, rewriteHtml, rewriteMdx, selectHtml, selectMdx, streamBlockEvents, walkHtml, walkMdx };
|
package/dist/mod.mjs
CHANGED
|
@@ -7,8 +7,9 @@ import { formatMdx } from "./format.mjs";
|
|
|
7
7
|
import { SourceBuffer, SourceFile } from "./source.mjs";
|
|
8
8
|
import { lowerHtml } from "./html-lower.mjs";
|
|
9
9
|
import { compile } from "./compiler.mjs";
|
|
10
|
-
import { formatHtml } from "./html-format.mjs";
|
|
11
10
|
import { defaultParserLimits } from "./parser/config.mjs";
|
|
11
|
+
import { parseFrontmatter, parseFrontmatterSync } from "./frontmatter.mjs";
|
|
12
|
+
import { formatHtml } from "./html-format.mjs";
|
|
12
13
|
import { TreeCursor } from "./tree.mjs";
|
|
13
14
|
import { rewriteHtml, rewriteMdx, selectHtml, selectMdx, walkHtml, walkMdx } from "./traversal.mjs";
|
|
14
15
|
import { MdxStream } from "./stream.mjs";
|
|
@@ -16,4 +17,4 @@ import { applyBlockEvent, blockEvent, completionEvent, previewDocument, streamBl
|
|
|
16
17
|
import { HtmlStreamRenderer } from "./html-stream.mjs";
|
|
17
18
|
import { parse } from "./parser.mjs";
|
|
18
19
|
import { Processor } from "./processor.mjs";
|
|
19
|
-
export { CompileError, ConfigurationError, FrontmatterError, HtmlStreamRenderer, InputError, LimitError, MdxError, MdxStream, ParseError, Processor, SourceBuffer, SourceFile, TransformError, TreeCursor, applyBlockEvent, blockEvent, compile, completionEvent, defaultParserLimits, documentFrontmatter, formatDiagnostic, formatHtml, formatMdx, hasErrorDiagnostics, htmlChildren, htmlClassNames, htmlFallback, htmlText, indexDocument, isFlowContent, isHtmlAttributeList, isPhrasingContent, lowerHtml, mdxChildren, nodeText, normalizeIdentifier, parse, pendingFallback, previewDocument, rewriteHtml, rewriteMdx, selectHtml, selectMdx, streamBlockEvents, walkHtml, walkMdx };
|
|
20
|
+
export { CompileError, ConfigurationError, FrontmatterError, HtmlStreamRenderer, InputError, LimitError, MdxError, MdxStream, ParseError, Processor, SourceBuffer, SourceFile, TransformError, TreeCursor, applyBlockEvent, blockEvent, compile, completionEvent, defaultParserLimits, documentFrontmatter, formatDiagnostic, formatHtml, formatMdx, hasErrorDiagnostics, htmlChildren, htmlClassNames, htmlFallback, htmlText, indexDocument, isFlowContent, isHtmlAttributeList, isPhrasingContent, lowerHtml, mdxChildren, nodeText, normalizeIdentifier, parse, parseFrontmatter, parseFrontmatterSync, pendingFallback, previewDocument, rewriteHtml, rewriteMdx, selectHtml, selectMdx, streamBlockEvents, walkHtml, walkMdx };
|
|
@@ -2,7 +2,7 @@ import { DiagnosticBag, createDiagnostic } from "../diagnostics.mjs";
|
|
|
2
2
|
import { normalizeIdentifier } from "../identifier.mjs";
|
|
3
3
|
import { nodeText } from "../model.mjs";
|
|
4
4
|
import { sourceText } from "../source.mjs";
|
|
5
|
-
import { decodeFrontmatter } from "../frontmatter.mjs";
|
|
5
|
+
import { decodeFrontmatter } from "../frontmatter-decode.mjs";
|
|
6
6
|
import { parseFlowRange } from "./block-parser.mjs";
|
|
7
7
|
import { InlineInput } from "./inline-input.mjs";
|
|
8
8
|
import { parseInline } from "./inline-parser.mjs";
|