featherdown 0.2.0 → 0.3.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 +301 -369
- package/dist/advanced.d.ts +75 -0
- package/dist/advanced.js +4 -0
- package/dist/advanced.js.map +1 -0
- package/dist/chunk-CWUDY7YI.js +558 -0
- package/dist/chunk-CWUDY7YI.js.map +1 -0
- package/dist/chunk-DNLCIOR6.js +16 -0
- package/dist/chunk-DNLCIOR6.js.map +1 -0
- package/dist/{chunk-3D4JFT3A.js → chunk-YKLQHPRB.js} +164 -5
- package/dist/chunk-YKLQHPRB.js.map +1 -0
- package/dist/featherdownDiagnosticsError-CE9gG3W7.d.ts +19 -0
- package/dist/index.d.ts +60 -85
- package/dist/index.js +16 -299
- package/dist/index.js.map +1 -1
- package/dist/node.d.ts +37 -2
- package/dist/node.js +219 -5
- package/dist/node.js.map +1 -1
- package/dist/types-Blk9BrZ4.d.ts +250 -0
- package/package.json +26 -4
- package/styles/base.css +262 -0
- package/styles/code.css +73 -0
- package/styles/highlight.css +5 -0
- package/styles/katex.css +7 -0
- package/styles.css +4 -0
- package/dist/chunk-3D4JFT3A.js.map +0 -1
- package/dist/types-BuSz3Zo6.d.ts +0 -139
package/dist/index.d.ts
CHANGED
|
@@ -1,103 +1,45 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { H as HeadingMetadata, T as TocItem } from './types-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import
|
|
1
|
+
import { a as FeatherdownOptions, c as FeatherdownParseOptions, F as FeatherdownResult, b as RenderMarkdownOptions, R as RenderDiagnostic, d as RenderMarkdownDocumentResult } from './types-Blk9BrZ4.js';
|
|
2
|
+
export { e as FeatherdownCodeOptions, f as FeatherdownHeadingOptions, g as FeatherdownMathOptions, h as FeatherdownMetadata, i as FeatherdownPublishingOptions, H as HeadingMetadata, T as TocItem } from './types-Blk9BrZ4.js';
|
|
3
|
+
export { F as FeatherdownDiagnosticsError } from './featherdownDiagnosticsError-CE9gG3W7.js';
|
|
4
|
+
export { createMarkdownProcessor, rehypeCdnImages, rehypeChartBlocks } from './advanced.js';
|
|
5
|
+
import 'hast';
|
|
6
|
+
import 'mdast';
|
|
7
|
+
import 'unified';
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* Exports a stable library identifier used in diagnostics and smoke tests.
|
|
11
|
-
*/
|
|
12
|
-
/**
|
|
13
|
-
* Stable identifier for this library. Intended for diagnostics and smoke tests.
|
|
14
|
-
*/
|
|
15
|
-
declare function libraryId(): string;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Parse Markdown content with optional YAML front matter.
|
|
10
|
+
* Primary user-facing API for rendering Markdown with publishing metadata.
|
|
19
11
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
12
|
+
* Prefer this class over legacy helpers such as `renderMarkdownDocument` or
|
|
13
|
+
* `renderMarkdownToHtml`; those remain for compatibility.
|
|
22
14
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
type ParsedMarkdownFile = {
|
|
27
|
-
/**
|
|
28
|
-
* YAML front matter object. Empty when front matter is missing.
|
|
29
|
-
*/
|
|
30
|
-
frontMatter: Record<string, unknown>;
|
|
15
|
+
declare class Featherdown {
|
|
16
|
+
private readonly defaultOptions;
|
|
17
|
+
constructor(options?: FeatherdownOptions);
|
|
31
18
|
/**
|
|
32
|
-
* Markdown
|
|
19
|
+
* Render Markdown to HTML and document metadata. Constructor options are merged
|
|
20
|
+
* with per-call options; per-call values win. Nested option groups use a
|
|
21
|
+
* shallow one-level merge.
|
|
33
22
|
*/
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Reads optional YAML front matter and returns metadata plus Markdown body.
|
|
38
|
-
*
|
|
39
|
-
* Throws when front matter exists but is invalid YAML, or when the root value
|
|
40
|
-
* is not a mapping object.
|
|
41
|
-
*/
|
|
42
|
-
declare function parseMarkdownFile(raw: string): ParsedMarkdownFile;
|
|
23
|
+
parse(markdown: string, parseOptions?: FeatherdownParseOptions): Promise<FeatherdownResult>;
|
|
24
|
+
}
|
|
43
25
|
|
|
44
26
|
/**
|
|
45
|
-
*
|
|
46
|
-
*/
|
|
47
|
-
type DiagnosticEmitter = (d: RenderDiagnostic) => void;
|
|
48
|
-
|
|
49
|
-
type InternalOptions = RenderMarkdownOptions & {
|
|
50
|
-
emitDiagnostic?: DiagnosticEmitter;
|
|
51
|
-
preserveHeadingCustomIdMarker?: boolean;
|
|
52
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* Build the default browser-safe unified processor used by public APIs.
|
|
55
|
-
*
|
|
56
|
-
* Internal helper that wires remark/rehype plugins for math, highlighting,
|
|
57
|
-
* sanitization, heading ids, chart placeholders, and image rewriting.
|
|
58
|
-
*/
|
|
59
|
-
declare function createMarkdownProcessorInternal(options?: InternalOptions): Processor<Root, Root, Root$1>;
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Create a browser-safe unified processor configured for featherdown defaults.
|
|
63
|
-
*
|
|
64
|
-
* This entrypoint exports the lower-level processor factory so callers can run
|
|
65
|
-
* custom `.process()` flows while still using the package's sanitization and
|
|
66
|
-
* plugin pipeline.
|
|
67
|
-
*/
|
|
68
|
-
declare function createMarkdownProcessor(options?: RenderMarkdownOptions): ReturnType<typeof createMarkdownProcessorInternal>;
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Rehype plugin entrypoint for chart code fence transformations.
|
|
72
|
-
*
|
|
73
|
-
* Exports a plugin that converts supported `chart-*` fenced JSON blocks into
|
|
74
|
-
* chart mount placeholders in the output HTML tree.
|
|
75
|
-
*/
|
|
76
|
-
/**
|
|
77
|
-
* Replaces supported `chart-…` fenced JSON blocks with a mount placeholder.
|
|
78
|
-
* Invalid JSON leaves the original `<pre><code>` unchanged.
|
|
79
|
-
*/
|
|
80
|
-
declare const rehypeChartBlocks: Plugin<[], Root$1>;
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Rehype plugin entrypoint for image class and CDN URL rewriting.
|
|
27
|
+
* Utility entrypoint for package identity checks.
|
|
84
28
|
*
|
|
85
|
-
* Exports
|
|
86
|
-
* rewrite local image sources with caller-provided manifest mappings.
|
|
87
|
-
*/
|
|
88
|
-
/**
|
|
89
|
-
* Options accepted by `rehypeCdnImages`.
|
|
29
|
+
* Exports a stable library identifier used in diagnostics and smoke tests.
|
|
90
30
|
*/
|
|
91
|
-
type RehypeCdnImagesOptions = RenderMarkdownOptions;
|
|
92
31
|
/**
|
|
93
|
-
*
|
|
94
|
-
* caller-provided manifest data.
|
|
32
|
+
* Stable identifier for this library. Intended for diagnostics and smoke tests.
|
|
95
33
|
*/
|
|
96
|
-
declare
|
|
34
|
+
declare function libraryId(): string;
|
|
97
35
|
|
|
98
36
|
/**
|
|
99
37
|
* Render Markdown to sanitized HTML and collect non-fatal diagnostics.
|
|
100
38
|
*
|
|
39
|
+
* @deprecated Prefer `new Featherdown().parse(markdown)` for new code.
|
|
40
|
+
* This helper accepts `RenderMarkdownOptions` only—not full `FeatherdownOptions`.
|
|
41
|
+
* This helper remains available for compatibility.
|
|
42
|
+
*
|
|
101
43
|
* This entrypoint is useful when callers want warning metadata in addition to
|
|
102
44
|
* the final HTML string.
|
|
103
45
|
*/
|
|
@@ -109,15 +51,48 @@ declare function renderMarkdown(markdown: string, options?: RenderMarkdownOption
|
|
|
109
51
|
/**
|
|
110
52
|
* Render Markdown to sanitized HTML and extract publishing metadata from the
|
|
111
53
|
* final rendered document structure.
|
|
54
|
+
*
|
|
55
|
+
* @deprecated Prefer `new Featherdown().parse(markdown)` for new code.
|
|
56
|
+
* This helper accepts `RenderMarkdownOptions` only—not full `FeatherdownOptions`.
|
|
57
|
+
* This helper remains available for compatibility.
|
|
112
58
|
*/
|
|
113
59
|
declare function renderMarkdownDocument(markdown: string, options?: RenderMarkdownOptions): Promise<RenderMarkdownDocumentResult>;
|
|
114
60
|
|
|
115
61
|
/**
|
|
116
62
|
* Render Markdown to sanitized HTML with featherdown defaults.
|
|
117
63
|
*
|
|
64
|
+
* @deprecated Prefer `(await new Featherdown().parse(markdown)).html` for new code.
|
|
65
|
+
* This helper accepts `RenderMarkdownOptions` only—not full `FeatherdownOptions`.
|
|
66
|
+
* This helper remains available for compatibility.
|
|
67
|
+
*
|
|
118
68
|
* This is the simplest public API for callers that only need HTML output and
|
|
119
69
|
* do not need diagnostics.
|
|
120
70
|
*/
|
|
121
71
|
declare function renderMarkdownToHtml(markdown: string, options?: RenderMarkdownOptions): Promise<string>;
|
|
122
72
|
|
|
123
|
-
|
|
73
|
+
/**
|
|
74
|
+
* Parsed result from a Markdown file with optional front matter.
|
|
75
|
+
*/
|
|
76
|
+
type ParsedMarkdownFile = {
|
|
77
|
+
/**
|
|
78
|
+
* YAML front matter object. Empty when front matter is missing.
|
|
79
|
+
*/
|
|
80
|
+
frontMatter: Record<string, unknown>;
|
|
81
|
+
/**
|
|
82
|
+
* Markdown body content after the front matter fence.
|
|
83
|
+
*/
|
|
84
|
+
content: string;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Reads optional YAML front matter and returns metadata plus Markdown body.
|
|
88
|
+
*
|
|
89
|
+
* @deprecated Prefer `new Featherdown({ frontmatter: "auto" }).parse(markdown)` for new code.
|
|
90
|
+
* That path returns a full `FeatherdownResult`; this function uses a separate strict front-matter-only contract.
|
|
91
|
+
* This strict front matter utility remains available for compatibility.
|
|
92
|
+
*
|
|
93
|
+
* Throws when front matter exists but is invalid YAML, or when the root value
|
|
94
|
+
* is not a mapping object.
|
|
95
|
+
*/
|
|
96
|
+
declare function parseMarkdownFile(raw: string): ParsedMarkdownFile;
|
|
97
|
+
|
|
98
|
+
export { Featherdown, FeatherdownOptions, FeatherdownParseOptions, FeatherdownResult, RenderDiagnostic, RenderMarkdownDocumentResult, RenderMarkdownOptions, libraryId, parseMarkdownFile, renderMarkdown, renderMarkdownDocument, renderMarkdownToHtml };
|
package/dist/index.js
CHANGED
|
@@ -1,319 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import rehypeKatex from 'rehype-katex';
|
|
6
|
-
import rehypeRaw from 'rehype-raw';
|
|
7
|
-
import rehypeSanitize from 'rehype-sanitize';
|
|
8
|
-
import rehypeSlug from 'rehype-slug';
|
|
9
|
-
import rehypeStringify from 'rehype-stringify';
|
|
10
|
-
import remarkDirective from 'remark-directive';
|
|
11
|
-
import remarkGfm from 'remark-gfm';
|
|
12
|
-
import remarkMath from 'remark-math';
|
|
13
|
-
import remarkParse from 'remark-parse';
|
|
14
|
-
import remarkRehype from 'remark-rehype';
|
|
15
|
-
import { visit, SKIP, EXIT } from 'unist-util-visit';
|
|
16
|
-
import { unified } from 'unified';
|
|
17
|
-
import { toText } from 'hast-util-to-text';
|
|
1
|
+
export { createMarkdownProcessor, rehypeCdnImages, rehypeChartBlocks } from './chunk-DNLCIOR6.js';
|
|
2
|
+
import { renderMarkdownDocumentInternal, extractFrontMatterStrict } from './chunk-CWUDY7YI.js';
|
|
3
|
+
export { Featherdown, FeatherdownDiagnosticsError } from './chunk-CWUDY7YI.js';
|
|
4
|
+
import './chunk-YKLQHPRB.js';
|
|
18
5
|
|
|
19
6
|
// src/libraryId.ts
|
|
20
7
|
function libraryId() {
|
|
21
8
|
return "featherdown";
|
|
22
9
|
}
|
|
23
|
-
function parseMarkdownFile(raw) {
|
|
24
|
-
const match = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/.exec(raw);
|
|
25
|
-
if (!raw.startsWith("---") || !match) {
|
|
26
|
-
return { frontMatter: {}, content: raw };
|
|
27
|
-
}
|
|
28
|
-
const yamlSource = match[1] ?? "";
|
|
29
|
-
const content = raw.slice(match[0].length);
|
|
30
|
-
try {
|
|
31
|
-
const loaded = yaml.load(yamlSource);
|
|
32
|
-
if (loaded === void 0 || loaded === null) {
|
|
33
|
-
return { frontMatter: {}, content };
|
|
34
|
-
}
|
|
35
|
-
if (typeof loaded !== "object" || Array.isArray(loaded)) {
|
|
36
|
-
throw new Error(
|
|
37
|
-
"Front matter root must be a YAML mapping (object), not a list or scalar."
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
return { frontMatter: loaded, content };
|
|
41
|
-
} catch (e) {
|
|
42
|
-
if (e instanceof Error && e.message.startsWith("Front matter")) {
|
|
43
|
-
throw e;
|
|
44
|
-
}
|
|
45
|
-
const detail = e instanceof Error ? e.message : String(e);
|
|
46
|
-
throw new Error(`Front matter YAML could not be parsed: ${detail}`);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
var SUPPORTED_CALLOUT_TYPES = [
|
|
50
|
-
"note",
|
|
51
|
-
"tip",
|
|
52
|
-
"warning",
|
|
53
|
-
"info",
|
|
54
|
-
"success",
|
|
55
|
-
"danger",
|
|
56
|
-
"error",
|
|
57
|
-
"caution",
|
|
58
|
-
"important"
|
|
59
|
-
];
|
|
60
|
-
var DEFAULT_TITLES = {
|
|
61
|
-
note: "Note",
|
|
62
|
-
tip: "Tip",
|
|
63
|
-
warning: "Warning",
|
|
64
|
-
info: "Info",
|
|
65
|
-
success: "Success",
|
|
66
|
-
danger: "Danger",
|
|
67
|
-
error: "Error",
|
|
68
|
-
caution: "Caution",
|
|
69
|
-
important: "Important"
|
|
70
|
-
};
|
|
71
|
-
function isSupportedCalloutType(value) {
|
|
72
|
-
return SUPPORTED_CALLOUT_TYPES.includes(value);
|
|
73
|
-
}
|
|
74
|
-
function createMarkerParagraph(value) {
|
|
75
|
-
return {
|
|
76
|
-
type: "paragraph",
|
|
77
|
-
children: [{ type: "text", value }]
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
function normalizeWhitespace(value) {
|
|
81
|
-
return value.replace(/\s+/g, " ").trim();
|
|
82
|
-
}
|
|
83
|
-
function createTitleNode(title) {
|
|
84
|
-
return {
|
|
85
|
-
type: "paragraph",
|
|
86
|
-
data: {
|
|
87
|
-
hName: "div",
|
|
88
|
-
hProperties: {
|
|
89
|
-
className: ["callout-title"]
|
|
90
|
-
}
|
|
91
|
-
},
|
|
92
|
-
children: [{ type: "text", value: title }]
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
function toPlainMarkdownNodes(name, label, children) {
|
|
96
|
-
const openMarker = label ? `:::${name}[${label}]` : `:::${name}`;
|
|
97
|
-
return [createMarkerParagraph(openMarker), ...children, createMarkerParagraph(":::")];
|
|
98
|
-
}
|
|
99
|
-
function extractDirectiveLabel(children) {
|
|
100
|
-
const first = children[0];
|
|
101
|
-
if (!first || first.type !== "paragraph") {
|
|
102
|
-
return { label: null, bodyChildren: children };
|
|
103
|
-
}
|
|
104
|
-
const hasDirectiveLabelFlag = first.data?.directiveLabel === true;
|
|
105
|
-
if (!hasDirectiveLabelFlag) {
|
|
106
|
-
return { label: null, bodyChildren: children };
|
|
107
|
-
}
|
|
108
|
-
const label = first.children.map((child) => child.type === "text" ? child.value : "").join("");
|
|
109
|
-
const normalizedLabel = normalizeWhitespace(label);
|
|
110
|
-
return {
|
|
111
|
-
label: normalizedLabel || null,
|
|
112
|
-
bodyChildren: children.slice(1)
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
function remarkCallouts() {
|
|
116
|
-
return (tree) => {
|
|
117
|
-
visit(tree, "containerDirective", (node, index, parent) => {
|
|
118
|
-
if (index === void 0 || !parent) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
const directive = node;
|
|
122
|
-
const name = directive.name;
|
|
123
|
-
const { label, bodyChildren } = extractDirectiveLabel(directive.children);
|
|
124
|
-
if (isSupportedCalloutType(name)) {
|
|
125
|
-
const title = label ?? DEFAULT_TITLES[name];
|
|
126
|
-
directive.children = [createTitleNode(title), ...bodyChildren];
|
|
127
|
-
directive.data = {
|
|
128
|
-
...directive.data ?? {},
|
|
129
|
-
hName: "div",
|
|
130
|
-
hProperties: {
|
|
131
|
-
...directive.data?.hProperties ?? {},
|
|
132
|
-
className: ["callout", `callout-${name}`]
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
const replacement = toPlainMarkdownNodes(name, label, bodyChildren);
|
|
138
|
-
parent.children.splice(index, 1, ...replacement);
|
|
139
|
-
return [SKIP, index + replacement.length];
|
|
140
|
-
});
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
10
|
|
|
144
|
-
// src/
|
|
145
|
-
function
|
|
146
|
-
return (
|
|
147
|
-
visit(tree, "element", (node) => {
|
|
148
|
-
if (!/^h[1-6]$/.test(node.tagName)) {
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
delete node.properties.dataHeadingCustomId;
|
|
152
|
-
});
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
function createMarkdownProcessorInternal(options) {
|
|
156
|
-
const processor = unified().use(remarkParse).use(remarkGfm).use(remarkDirective).use(remarkMath).use(remarkHeadingIds).use(remarkCallouts).use(remarkCodeBlockTitles).use(remarkRehype, { allowDangerousHtml: true }).use(rehypeRaw);
|
|
157
|
-
if (options?.emitDiagnostic) {
|
|
158
|
-
processor.use(rehypeChartBlocks_default, { emitDiagnostic: options.emitDiagnostic });
|
|
159
|
-
} else {
|
|
160
|
-
processor.use(rehypeChartBlocks_default);
|
|
161
|
-
}
|
|
162
|
-
processor.use(rehypeCodeBlockTitles_default).use(rehypeKatex, { output: "html" }).use(rehypeSanitize, markdownSanitizeSchema).use(rehypeSlug).use(rehypeAutolinkHeadings, { behavior: "wrap" }).use(rehypeHighlight).use(rehypeCodeLineHighlights_default);
|
|
163
|
-
if (!options?.preserveHeadingCustomIdMarker) {
|
|
164
|
-
processor.use(rehypeStripHeadingCustomIdMarker);
|
|
165
|
-
}
|
|
166
|
-
processor.use(rehypeCdnImages, options).use(rehypeStringify);
|
|
167
|
-
return processor;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// src/createMarkdownProcessor.ts
|
|
171
|
-
function createMarkdownProcessor(options) {
|
|
172
|
-
return createMarkdownProcessorInternal(options);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// src/rehypeChartBlocks.ts
|
|
176
|
-
var rehypeChartBlocks = rehypeChartBlocks_default;
|
|
177
|
-
|
|
178
|
-
// src/rehypeCdnImages.ts
|
|
179
|
-
var rehypeCdnImages2 = rehypeCdnImages;
|
|
180
|
-
|
|
181
|
-
// src/internal/diagnostics.ts
|
|
182
|
-
function createDiagnosticCollector() {
|
|
183
|
-
const diagnostics = [];
|
|
184
|
-
const emit = (d) => {
|
|
185
|
-
diagnostics.push(d);
|
|
186
|
-
};
|
|
187
|
-
return {
|
|
188
|
-
emit,
|
|
189
|
-
diagnostics
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// src/internal/renderMarkdownDocumentInternal.ts
|
|
194
|
-
var WORDS_PER_MINUTE = 200;
|
|
195
|
-
var excerptTagNames = /* @__PURE__ */ new Set(["p", "blockquote", "li"]);
|
|
196
|
-
function normalizeText(text) {
|
|
197
|
-
return text.replace(/\s+/g, " ").trim();
|
|
198
|
-
}
|
|
199
|
-
function getHeadingDepth(tagName) {
|
|
200
|
-
const match = /^h([1-6])$/.exec(tagName);
|
|
201
|
-
if (!match) {
|
|
202
|
-
return null;
|
|
203
|
-
}
|
|
204
|
-
return Number(match[1]);
|
|
205
|
-
}
|
|
206
|
-
function isParagraphLikeTagName(tagName) {
|
|
207
|
-
return excerptTagNames.has(tagName);
|
|
208
|
-
}
|
|
209
|
-
function isCustomHeadingId(value) {
|
|
210
|
-
return value === true || value === "true" || value === "";
|
|
211
|
-
}
|
|
212
|
-
function extractHeadings(root) {
|
|
213
|
-
const headings = [];
|
|
214
|
-
visit(root, "element", (node) => {
|
|
215
|
-
const depth = getHeadingDepth(node.tagName);
|
|
216
|
-
if (!depth) {
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
const id = typeof node.properties.id === "string" ? node.properties.id : "";
|
|
220
|
-
if (!id) {
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
const text = normalizeText(toText(node));
|
|
224
|
-
if (!text) {
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
headings.push({
|
|
228
|
-
index: headings.length,
|
|
229
|
-
depth,
|
|
230
|
-
text,
|
|
231
|
-
id,
|
|
232
|
-
hasCustomId: isCustomHeadingId(node.properties.dataHeadingCustomId)
|
|
233
|
-
});
|
|
234
|
-
delete node.properties.dataHeadingCustomId;
|
|
235
|
-
});
|
|
236
|
-
return headings;
|
|
237
|
-
}
|
|
238
|
-
function extractToc(headings) {
|
|
239
|
-
return headings.map((heading) => ({
|
|
240
|
-
depth: heading.depth,
|
|
241
|
-
text: heading.text,
|
|
242
|
-
id: heading.id
|
|
243
|
-
}));
|
|
244
|
-
}
|
|
245
|
-
function extractExcerpt(root) {
|
|
246
|
-
let excerpt = null;
|
|
247
|
-
visit(root, "element", (node) => {
|
|
248
|
-
if (excerpt !== null) {
|
|
249
|
-
return EXIT;
|
|
250
|
-
}
|
|
251
|
-
if (!isParagraphLikeTagName(node.tagName)) {
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
const text = normalizeText(toText(node));
|
|
255
|
-
if (!text) {
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
excerpt = text;
|
|
259
|
-
return EXIT;
|
|
260
|
-
});
|
|
261
|
-
return excerpt;
|
|
262
|
-
}
|
|
263
|
-
function countWords(root) {
|
|
264
|
-
const text = normalizeText(toText(root));
|
|
265
|
-
if (!text) {
|
|
266
|
-
return 0;
|
|
267
|
-
}
|
|
268
|
-
const words = text.match(/\S+/g);
|
|
269
|
-
return words ? words.length : 0;
|
|
270
|
-
}
|
|
271
|
-
function estimateReadingMinutes(wordCount) {
|
|
272
|
-
if (wordCount <= 0) {
|
|
273
|
-
return 0;
|
|
274
|
-
}
|
|
275
|
-
return Math.max(1, Math.ceil(wordCount / WORDS_PER_MINUTE));
|
|
276
|
-
}
|
|
277
|
-
async function renderMarkdownDocumentInternal(markdown, options) {
|
|
278
|
-
const collector = createDiagnosticCollector();
|
|
279
|
-
const processor = createMarkdownProcessorInternal({
|
|
280
|
-
...options,
|
|
281
|
-
emitDiagnostic: collector.emit,
|
|
282
|
-
preserveHeadingCustomIdMarker: true
|
|
283
|
-
});
|
|
284
|
-
const parsed = processor.parse(markdown);
|
|
285
|
-
const root = await processor.run(parsed);
|
|
286
|
-
const headings = extractHeadings(root);
|
|
287
|
-
const html = String(processor.stringify(root));
|
|
288
|
-
const wordCount = countWords(root);
|
|
289
|
-
return {
|
|
290
|
-
html,
|
|
291
|
-
diagnostics: collector.diagnostics,
|
|
292
|
-
toc: extractToc(headings),
|
|
293
|
-
headings,
|
|
294
|
-
excerpt: extractExcerpt(root),
|
|
295
|
-
wordCount,
|
|
296
|
-
estimatedReadingMinutes: estimateReadingMinutes(wordCount)
|
|
297
|
-
};
|
|
11
|
+
// src/renderMarkdownDocument.ts
|
|
12
|
+
async function renderMarkdownDocument(markdown, options) {
|
|
13
|
+
return renderMarkdownDocumentInternal(markdown, options);
|
|
298
14
|
}
|
|
299
15
|
|
|
300
16
|
// src/renderMarkdown.ts
|
|
301
17
|
async function renderMarkdown(markdown, options) {
|
|
302
|
-
const result = await
|
|
18
|
+
const result = await renderMarkdownDocument(markdown, options);
|
|
303
19
|
return { html: result.html, diagnostics: result.diagnostics };
|
|
304
20
|
}
|
|
305
21
|
|
|
306
|
-
// src/renderMarkdownDocument.ts
|
|
307
|
-
async function renderMarkdownDocument(markdown, options) {
|
|
308
|
-
return renderMarkdownDocumentInternal(markdown, options);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
22
|
// src/renderMarkdownToHtml.ts
|
|
312
23
|
async function renderMarkdownToHtml(markdown, options) {
|
|
313
|
-
const result = await
|
|
24
|
+
const result = await renderMarkdownDocument(markdown, options);
|
|
314
25
|
return result.html;
|
|
315
26
|
}
|
|
316
27
|
|
|
317
|
-
|
|
28
|
+
// src/parseMarkdownFile.ts
|
|
29
|
+
function parseMarkdownFile(raw) {
|
|
30
|
+
const { body, frontmatter } = extractFrontMatterStrict(raw);
|
|
31
|
+
return { frontMatter: frontmatter, content: body };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { libraryId, parseMarkdownFile, renderMarkdown, renderMarkdownDocument, renderMarkdownToHtml };
|
|
318
35
|
//# sourceMappingURL=index.js.map
|
|
319
36
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/libraryId.ts","../src/parseMarkdownFile.ts","../src/internal/remarkCallouts.ts","../src/internal/createMarkdownProcessorInternal.ts","../src/createMarkdownProcessor.ts","../src/rehypeChartBlocks.ts","../src/rehypeCdnImages.ts","../src/internal/diagnostics.ts","../src/internal/renderMarkdownDocumentInternal.ts","../src/renderMarkdown.ts","../src/renderMarkdownDocument.ts","../src/renderMarkdownToHtml.ts"],"names":["visit","rehypeCdnImages"],"mappings":";;;;;;;;;;;;;;;;;;;AASO,SAAS,SAAA,GAAoB;AAClC,EAAA,OAAO,aAAA;AACT;ACkBO,SAAS,kBAAkB,GAAA,EAAiC;AACjE,EAAA,MAAM,KAAA,GAAQ,wCAAA,CAAyC,IAAA,CAAK,GAAG,CAAA;AAC/D,EAAA,IAAI,CAAC,GAAA,CAAI,UAAA,CAAW,KAAK,CAAA,IAAK,CAAC,KAAA,EAAO;AACpC,IAAA,OAAO,EAAE,WAAA,EAAa,EAAC,EAAG,SAAS,GAAA,EAAI;AAAA,EACzC;AAEA,EAAA,MAAM,UAAA,GAAa,KAAA,CAAM,CAAC,CAAA,IAAK,EAAA;AAC/B,EAAA,MAAM,UAAU,GAAA,CAAI,KAAA,CAAM,KAAA,CAAM,CAAC,EAAE,MAAM,CAAA;AAEzC,EAAA,IAAI;AACF,IAAA,MAAM,MAAA,GAAkB,IAAA,CAAK,IAAA,CAAK,UAAU,CAAA;AAC5C,IAA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eAAsB,sBAAA,CACpB,UACA,OAAA,EACuC;AACvC,EAAA,OAAO,8BAAA,CAA+B,UAAU,OAAO,CAAA;AACzD;;;ACHA,eAAsB,oBAAA,CACpB,UACA,OAAA,EACiB;AACjB,EAAA,MAAM,MAAA,GAAS,MAAM,cAAA,CAAe,QAAA,EAAU,OAAO,CAAA;AACrD,EAAA,OAAO,MAAA,CAAO,IAAA;AAChB","file":"index.js","sourcesContent":["/**\n * Utility entrypoint for package identity checks.\n *\n * Exports a stable library identifier used in diagnostics and smoke tests.\n */\n\n/**\n * Stable identifier for this library. Intended for diagnostics and smoke tests.\n */\nexport function libraryId(): string {\n return 'featherdown';\n}\n","import yaml from 'js-yaml';\n\n/**\n * Parse Markdown content with optional YAML front matter.\n *\n * Exports a small utility that splits a raw Markdown file into front matter\n * metadata and content body for downstream rendering pipelines.\n */\n\n/**\n * Parsed result from a Markdown file with optional front matter.\n */\nexport type ParsedMarkdownFile = {\n /**\n * YAML front matter object. Empty when front matter is missing.\n */\n frontMatter: Record<string, unknown>;\n /**\n * Markdown body content after the front matter fence.\n */\n content: string;\n};\n\n/**\n * Reads optional YAML front matter and returns metadata plus Markdown body.\n *\n * Throws when front matter exists but is invalid YAML, or when the root value\n * is not a mapping object.\n */\nexport function parseMarkdownFile(raw: string): ParsedMarkdownFile {\n const match = /^---\\r?\\n([\\s\\S]*?)\\r?\\n---(?:\\r?\\n|$)/.exec(raw);\n if (!raw.startsWith('---') || !match) {\n return { frontMatter: {}, content: raw };\n }\n\n const yamlSource = match[1] ?? '';\n const content = raw.slice(match[0].length);\n\n try {\n const loaded: unknown = yaml.load(yamlSource);\n if (loaded === undefined || loaded === null) {\n return { frontMatter: {}, content };\n }\n if (typeof loaded !== 'object' || Array.isArray(loaded)) {\n throw new Error(\n 'Front matter root must be a YAML mapping (object), not a list or scalar.',\n );\n }\n return { frontMatter: loaded as Record<string, unknown>, content };\n } catch (e) {\n if (e instanceof Error && e.message.startsWith('Front matter')) {\n throw e;\n }\n const detail = e instanceof Error ? e.message : String(e);\n throw new Error(`Front matter YAML could not be parsed: ${detail}`);\n }\n}\n","import type { BlockContent, Root, RootContent } from 'mdast';\nimport { SKIP, visit } from 'unist-util-visit';\n\nconst SUPPORTED_CALLOUT_TYPES = [\n 'note',\n 'tip',\n 'warning',\n 'info',\n 'success',\n 'danger',\n 'error',\n 'caution',\n 'important',\n] as const;\ntype SupportedCalloutType = (typeof SUPPORTED_CALLOUT_TYPES)[number];\n\nconst DEFAULT_TITLES: Record<SupportedCalloutType, string> = {\n note: 'Note',\n tip: 'Tip',\n warning: 'Warning',\n info: 'Info',\n success: 'Success',\n danger: 'Danger',\n error: 'Error',\n caution: 'Caution',\n important: 'Important',\n};\n\nfunction isSupportedCalloutType(value: string): value is SupportedCalloutType {\n return (SUPPORTED_CALLOUT_TYPES as readonly string[]).includes(value);\n}\n\nfunction createMarkerParagraph(value: string): RootContent {\n return {\n type: 'paragraph',\n children: [{ type: 'text', value }],\n };\n}\n\nfunction normalizeWhitespace(value: string): string {\n return value.replace(/\\s+/g, ' ').trim();\n}\n\nfunction createTitleNode(title: string): BlockContent {\n return {\n type: 'paragraph',\n data: {\n hName: 'div',\n hProperties: {\n className: ['callout-title'],\n },\n },\n children: [{ type: 'text', value: title }],\n };\n}\n\nfunction toPlainMarkdownNodes(name: string, label: string | null | undefined, children: RootContent[]): RootContent[] {\n const openMarker = label ? `:::${name}[${label}]` : `:::${name}`;\n return [createMarkerParagraph(openMarker), ...children, createMarkerParagraph(':::')];\n}\n\nfunction extractDirectiveLabel(children: BlockContent[]): { label: string | null; bodyChildren: BlockContent[] } {\n const first = children[0];\n if (!first || first.type !== 'paragraph') {\n return { label: null, bodyChildren: children };\n }\n\n const hasDirectiveLabelFlag = (first.data as { directiveLabel?: boolean } | undefined)?.directiveLabel === true;\n if (!hasDirectiveLabelFlag) {\n return { label: null, bodyChildren: children };\n }\n\n const label = first.children\n .map((child) => (child.type === 'text' ? child.value : ''))\n .join('');\n const normalizedLabel = normalizeWhitespace(label);\n\n return {\n label: normalizedLabel || null,\n bodyChildren: children.slice(1),\n };\n}\n\ntype DirectiveNode = RootContent & {\n type: 'containerDirective';\n name: string;\n data?: {\n hName?: string;\n hProperties?: Record<string, unknown>;\n };\n children: BlockContent[];\n};\n\n/**\n * Maps supported :::type directives to stable callout HTML.\n */\nexport function remarkCallouts() {\n return (tree: Root): void => {\n visit(tree, 'containerDirective', (node, index, parent) => {\n if (index === undefined || !parent) {\n return;\n }\n\n const directive = node as DirectiveNode;\n const name = directive.name;\n const { label, bodyChildren } = extractDirectiveLabel(directive.children);\n\n if (isSupportedCalloutType(name)) {\n const title = label ?? DEFAULT_TITLES[name];\n directive.children = [createTitleNode(title), ...bodyChildren];\n directive.data = {\n ...(directive.data ?? {}),\n hName: 'div',\n hProperties: {\n ...(directive.data?.hProperties ?? {}),\n className: ['callout', `callout-${name}`],\n },\n };\n return;\n }\n\n const replacement = toPlainMarkdownNodes(name, label, bodyChildren);\n parent.children.splice(index, 1, ...replacement);\n return [SKIP, index + replacement.length];\n });\n };\n}\n","import rehypeAutolinkHeadings from 'rehype-autolink-headings';\nimport rehypeHighlight from 'rehype-highlight';\nimport rehypeKatex from 'rehype-katex';\nimport rehypeCodeBlockTitles from './rehypeCodeBlockTitles.js';\nimport rehypeCodeLineHighlights from './rehypeCodeLineHighlights.js';\nimport rehypeRaw from 'rehype-raw';\nimport rehypeChartBlocksInternal from './rehypeChartBlocksInternal.js';\nimport rehypeCdnImagesInternal from './rehypeCdnImagesInternal.js';\nimport rehypeSanitize from 'rehype-sanitize';\nimport rehypeSlug from 'rehype-slug';\nimport rehypeStringify from 'rehype-stringify';\nimport remarkDirective from 'remark-directive';\nimport remarkGfm from 'remark-gfm';\nimport remarkMath from 'remark-math';\nimport remarkParse from 'remark-parse';\nimport remarkRehype from 'remark-rehype';\nimport type { Root as HastRoot } from 'hast';\nimport { visit } from 'unist-util-visit';\nimport type { Root as MdastRoot } from 'mdast';\nimport type { Processor } from 'unified';\nimport { unified } from 'unified';\nimport type { RenderMarkdownOptions } from '../types.js';\nimport { remarkHeadingIds } from './headingIdsRemark.js';\nimport { remarkCallouts } from './remarkCallouts.js';\nimport { remarkCodeBlockTitles } from './remarkCodeBlockTitles.js';\nimport type { DiagnosticEmitter } from './diagnostics.js';\nimport { markdownSanitizeSchema } from './sanitizeSchema.js';\n\ntype InternalOptions = RenderMarkdownOptions & {\n emitDiagnostic?: DiagnosticEmitter;\n preserveHeadingCustomIdMarker?: boolean;\n};\n\nfunction rehypeStripHeadingCustomIdMarker() {\n return (tree: HastRoot): undefined => {\n visit(tree, 'element', (node) => {\n if (!/^h[1-6]$/.test(node.tagName)) {\n return;\n }\n delete node.properties.dataHeadingCustomId;\n });\n };\n}\n\n/**\n * Build the default browser-safe unified processor used by public APIs.\n *\n * Internal helper that wires remark/rehype plugins for math, highlighting,\n * sanitization, heading ids, chart placeholders, and image rewriting.\n */\nexport function createMarkdownProcessorInternal(\n options?: InternalOptions,\n): Processor<MdastRoot, MdastRoot, HastRoot> {\n const processor = unified()\n .use(remarkParse)\n .use(remarkGfm)\n .use(remarkDirective)\n .use(remarkMath)\n .use(remarkHeadingIds)\n .use(remarkCallouts)\n .use(remarkCodeBlockTitles)\n .use(remarkRehype, { allowDangerousHtml: true })\n .use(rehypeRaw);\n\n if (options?.emitDiagnostic) {\n processor.use(rehypeChartBlocksInternal, { emitDiagnostic: options.emitDiagnostic });\n } else {\n processor.use(rehypeChartBlocksInternal);\n }\n\n processor\n .use(rehypeCodeBlockTitles)\n .use(rehypeKatex, { output: 'html' })\n .use(rehypeSanitize, markdownSanitizeSchema)\n .use(rehypeSlug)\n .use(rehypeAutolinkHeadings, { behavior: 'wrap' })\n .use(rehypeHighlight)\n .use(rehypeCodeLineHighlights);\n\n if (!options?.preserveHeadingCustomIdMarker) {\n processor.use(rehypeStripHeadingCustomIdMarker);\n }\n\n processor.use(rehypeCdnImagesInternal, options).use(rehypeStringify);\n\n return processor;\n}\n\n","import type { RenderMarkdownOptions } from './types.js';\nimport { createMarkdownProcessorInternal } from './internal/createMarkdownProcessorInternal.js';\n\n/**\n * Create a browser-safe unified processor configured for featherdown defaults.\n *\n * This entrypoint exports the lower-level processor factory so callers can run\n * custom `.process()` flows while still using the package's sanitization and\n * plugin pipeline.\n */\nexport function createMarkdownProcessor(\n options?: RenderMarkdownOptions,\n): ReturnType<typeof createMarkdownProcessorInternal> {\n return createMarkdownProcessorInternal(options);\n}\n\n","import type { Plugin } from 'unified';\nimport type { Root } from 'hast';\nimport rehypeChartBlocksInternal from './internal/rehypeChartBlocksInternal.js';\n\n/**\n * Rehype plugin entrypoint for chart code fence transformations.\n *\n * Exports a plugin that converts supported `chart-*` fenced JSON blocks into\n * chart mount placeholders in the output HTML tree.\n */\n\n/**\n * Replaces supported `chart-…` fenced JSON blocks with a mount placeholder.\n * Invalid JSON leaves the original `<pre><code>` unchanged.\n */\nexport const rehypeChartBlocks: Plugin<[], Root> =\n rehypeChartBlocksInternal as unknown as Plugin<[], Root>;\n\n","import type { Plugin } from 'unified';\nimport type { Root } from 'hast';\nimport type { RenderMarkdownOptions } from './types.js';\nimport rehypeCdnImagesInternal from './internal/rehypeCdnImagesInternal.js';\n\n/**\n * Rehype plugin entrypoint for image class and CDN URL rewriting.\n *\n * Exports plugin options and a plugin that annotates image nodes and can\n * rewrite local image sources with caller-provided manifest mappings.\n */\n\n/**\n * Options accepted by `rehypeCdnImages`.\n */\nexport type RehypeCdnImagesOptions = RenderMarkdownOptions;\n\n/**\n * Adds `markdown-inline-img` to all images and optionally rewrites `src` using\n * caller-provided manifest data.\n */\nexport const rehypeCdnImages: Plugin<[RehypeCdnImagesOptions?], Root> =\n rehypeCdnImagesInternal as unknown as Plugin<[RehypeCdnImagesOptions?], Root>;\n\n","import type { RenderDiagnostic } from '../types.js';\n\n/**\n * Emits a non-fatal rendering diagnostic.\n */\nexport type DiagnosticEmitter = (d: RenderDiagnostic) => void;\n\n/**\n * Create a collector used to accumulate diagnostics during rendering.\n */\nexport function createDiagnosticCollector() {\n const diagnostics: RenderDiagnostic[] = [];\n const emit: DiagnosticEmitter = (d) => {\n diagnostics.push(d);\n };\n\n return {\n emit,\n diagnostics,\n };\n}\n\n","import { toText } from 'hast-util-to-text';\nimport { EXIT, visit } from 'unist-util-visit';\nimport { createMarkdownProcessorInternal } from './createMarkdownProcessorInternal.js';\nimport { createDiagnosticCollector } from './diagnostics.js';\nimport type {\n HeadingMetadata,\n RenderMarkdownDocumentResult,\n RenderMarkdownOptions,\n TocItem,\n} from '../types.js';\nimport type { Element, Root as HastRoot } from 'hast';\n\nconst WORDS_PER_MINUTE = 200;\n\ntype ParagraphLikeTagName = 'p' | 'blockquote' | 'li';\n\nconst excerptTagNames: ReadonlySet<ParagraphLikeTagName> = new Set(['p', 'blockquote', 'li']);\n\nfunction normalizeText(text: string): string {\n return text.replace(/\\s+/g, ' ').trim();\n}\n\nfunction getHeadingDepth(tagName: string): number | null {\n const match = /^h([1-6])$/.exec(tagName);\n if (!match) {\n return null;\n }\n return Number(match[1]);\n}\n\nfunction isParagraphLikeTagName(tagName: string): tagName is ParagraphLikeTagName {\n return excerptTagNames.has(tagName as ParagraphLikeTagName);\n}\n\nfunction isCustomHeadingId(value: unknown): boolean {\n return value === true || value === 'true' || value === '';\n}\n\nfunction extractHeadings(root: HastRoot): HeadingMetadata[] {\n const headings: HeadingMetadata[] = [];\n\n visit(root, 'element', (node) => {\n const depth = getHeadingDepth(node.tagName);\n if (!depth) {\n return;\n }\n\n const id = typeof node.properties.id === 'string' ? node.properties.id : '';\n if (!id) {\n return;\n }\n\n const text = normalizeText(toText(node));\n if (!text) {\n return;\n }\n\n headings.push({\n index: headings.length,\n depth,\n text,\n id,\n hasCustomId: isCustomHeadingId(node.properties.dataHeadingCustomId),\n });\n delete node.properties.dataHeadingCustomId;\n });\n\n return headings;\n}\n\nfunction extractToc(headings: HeadingMetadata[]): TocItem[] {\n return headings.map((heading) => ({\n depth: heading.depth,\n text: heading.text,\n id: heading.id,\n }));\n}\n\nfunction extractExcerpt(root: HastRoot): string | null {\n let excerpt: string | null = null;\n\n visit(root, 'element', (node: Element) => {\n if (excerpt !== null) {\n return EXIT;\n }\n\n if (!isParagraphLikeTagName(node.tagName)) {\n return;\n }\n\n const text = normalizeText(toText(node));\n if (!text) {\n return;\n }\n\n excerpt = text;\n return EXIT;\n });\n\n return excerpt;\n}\n\nfunction countWords(root: HastRoot): number {\n const text = normalizeText(toText(root));\n if (!text) {\n return 0;\n }\n const words = text.match(/\\S+/g);\n return words ? words.length : 0;\n}\n\nfunction estimateReadingMinutes(wordCount: number): number {\n if (wordCount <= 0) {\n return 0;\n }\n return Math.max(1, Math.ceil(wordCount / WORDS_PER_MINUTE));\n}\n\n/**\n * Render markdown through the default browser-safe pipeline and derive\n * publishing metadata from the final processed document tree.\n */\nexport async function renderMarkdownDocumentInternal(\n markdown: string,\n options?: RenderMarkdownOptions,\n): Promise<RenderMarkdownDocumentResult> {\n const collector = createDiagnosticCollector();\n const processor = createMarkdownProcessorInternal({\n ...options,\n emitDiagnostic: collector.emit,\n preserveHeadingCustomIdMarker: true,\n });\n\n const parsed = processor.parse(markdown);\n const root: HastRoot = await processor.run(parsed);\n\n const headings = extractHeadings(root);\n const html = String(processor.stringify(root));\n const wordCount = countWords(root);\n\n return {\n html,\n diagnostics: collector.diagnostics,\n toc: extractToc(headings),\n headings,\n excerpt: extractExcerpt(root),\n wordCount,\n estimatedReadingMinutes: estimateReadingMinutes(wordCount),\n };\n}\n","import { renderMarkdownDocumentInternal } from './internal/renderMarkdownDocumentInternal.js';\nimport type { RenderDiagnostic, RenderMarkdownOptions } from './types.js';\n\n/**\n * Render Markdown to sanitized HTML and collect non-fatal diagnostics.\n *\n * This entrypoint is useful when callers want warning metadata in addition to\n * the final HTML string.\n */\nexport async function renderMarkdown(\n markdown: string,\n options?: RenderMarkdownOptions,\n): Promise<{ html: string; diagnostics: RenderDiagnostic[] }> {\n const result = await renderMarkdownDocumentInternal(markdown, options);\n return { html: result.html, diagnostics: result.diagnostics };\n}\n\n","import { renderMarkdownDocumentInternal } from './internal/renderMarkdownDocumentInternal.js';\nimport type { RenderMarkdownDocumentResult, RenderMarkdownOptions } from './types.js';\n\n/**\n * Render Markdown to sanitized HTML and extract publishing metadata from the\n * final rendered document structure.\n */\nexport async function renderMarkdownDocument(\n markdown: string,\n options?: RenderMarkdownOptions,\n): Promise<RenderMarkdownDocumentResult> {\n return renderMarkdownDocumentInternal(markdown, options);\n}\n","import { renderMarkdown } from './renderMarkdown.js';\nimport type { RenderMarkdownOptions } from './types.js';\n\n/**\n * Render Markdown to sanitized HTML with featherdown defaults.\n *\n * This is the simplest public API for callers that only need HTML output and\n * do not need diagnostics.\n */\nexport async function renderMarkdownToHtml(\n markdown: string,\n options?: RenderMarkdownOptions,\n): Promise<string> {\n const result = await renderMarkdown(markdown, options);\n return result.html;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/libraryId.ts","../src/renderMarkdownDocument.ts","../src/renderMarkdown.ts","../src/renderMarkdownToHtml.ts","../src/parseMarkdownFile.ts"],"names":[],"mappings":";;;;;;AASO,SAAS,SAAA,GAAoB;AAClC,EAAA,OAAO,aAAA;AACT;;;ACAA,eAAsB,sBAAA,CACpB,UACA,OAAA,EACuC;AACvC,EAAA,OAAO,8BAAA,CAA+B,UAAU,OAAO,CAAA;AACzD;;;ACHA,eAAsB,cAAA,CACpB,UACA,OAAA,EAC4D;AAC5D,EAAA,MAAM,MAAA,GAAS,MAAM,sBAAA,CAAuB,QAAA,EAAU,OAAO,CAAA;AAC7D,EAAA,OAAO,EAAE,IAAA,EAAM,MAAA,CAAO,IAAA,EAAM,WAAA,EAAa,OAAO,WAAA,EAAY;AAC9D;;;ACNA,eAAsB,oBAAA,CACpB,UACA,OAAA,EACiB;AACjB,EAAA,MAAM,MAAA,GAAS,MAAM,sBAAA,CAAuB,QAAA,EAAU,OAAO,CAAA;AAC7D,EAAA,OAAO,MAAA,CAAO,IAAA;AAChB;;;ACOO,SAAS,kBAAkB,GAAA,EAAiC;AACjE,EAAA,MAAM,EAAE,IAAA,EAAM,WAAA,EAAY,GAAI,yBAAyB,GAAG,CAAA;AAC1D,EAAA,OAAO,EAAE,WAAA,EAAa,WAAA,EAAa,OAAA,EAAS,IAAA,EAAK;AACnD","file":"index.js","sourcesContent":["/**\n * Utility entrypoint for package identity checks.\n *\n * Exports a stable library identifier used in diagnostics and smoke tests.\n */\n\n/**\n * Stable identifier for this library. Intended for diagnostics and smoke tests.\n */\nexport function libraryId(): string {\n return 'featherdown';\n}\n","import { renderMarkdownDocumentInternal } from './internal/renderMarkdownDocumentInternal.js';\nimport type { RenderMarkdownDocumentResult, RenderMarkdownOptions } from './types.js';\n\n/**\n * Render Markdown to sanitized HTML and extract publishing metadata from the\n * final rendered document structure.\n *\n * @deprecated Prefer `new Featherdown().parse(markdown)` for new code.\n * This helper accepts `RenderMarkdownOptions` only—not full `FeatherdownOptions`.\n * This helper remains available for compatibility.\n */\nexport async function renderMarkdownDocument(\n markdown: string,\n options?: RenderMarkdownOptions,\n): Promise<RenderMarkdownDocumentResult> {\n return renderMarkdownDocumentInternal(markdown, options);\n}\n","import { renderMarkdownDocument } from './renderMarkdownDocument.js';\nimport type { RenderDiagnostic, RenderMarkdownOptions } from './types.js';\n\n/**\n * Render Markdown to sanitized HTML and collect non-fatal diagnostics.\n *\n * @deprecated Prefer `new Featherdown().parse(markdown)` for new code.\n * This helper accepts `RenderMarkdownOptions` only—not full `FeatherdownOptions`.\n * This helper remains available for compatibility.\n *\n * This entrypoint is useful when callers want warning metadata in addition to\n * the final HTML string.\n */\nexport async function renderMarkdown(\n markdown: string,\n options?: RenderMarkdownOptions,\n): Promise<{ html: string; diagnostics: RenderDiagnostic[] }> {\n const result = await renderMarkdownDocument(markdown, options);\n return { html: result.html, diagnostics: result.diagnostics };\n}\n","import { renderMarkdownDocument } from './renderMarkdownDocument.js';\nimport type { RenderMarkdownOptions } from './types.js';\n\n/**\n * Render Markdown to sanitized HTML with featherdown defaults.\n *\n * @deprecated Prefer `(await new Featherdown().parse(markdown)).html` for new code.\n * This helper accepts `RenderMarkdownOptions` only—not full `FeatherdownOptions`.\n * This helper remains available for compatibility.\n *\n * This is the simplest public API for callers that only need HTML output and\n * do not need diagnostics.\n */\nexport async function renderMarkdownToHtml(\n markdown: string,\n options?: RenderMarkdownOptions,\n): Promise<string> {\n const result = await renderMarkdownDocument(markdown, options);\n return result.html;\n}\n","import { extractFrontMatterStrict } from './internal/parseFrontmatter.js';\n\n/**\n * Parsed result from a Markdown file with optional front matter.\n */\nexport type ParsedMarkdownFile = {\n /**\n * YAML front matter object. Empty when front matter is missing.\n */\n frontMatter: Record<string, unknown>;\n /**\n * Markdown body content after the front matter fence.\n */\n content: string;\n};\n\n/**\n * Reads optional YAML front matter and returns metadata plus Markdown body.\n *\n * @deprecated Prefer `new Featherdown({ frontmatter: \"auto\" }).parse(markdown)` for new code.\n * That path returns a full `FeatherdownResult`; this function uses a separate strict front-matter-only contract.\n * This strict front matter utility remains available for compatibility.\n *\n * Throws when front matter exists but is invalid YAML, or when the root value\n * is not a mapping object.\n */\nexport function parseMarkdownFile(raw: string): ParsedMarkdownFile {\n const { body, frontmatter } = extractFrontMatterStrict(raw);\n return { frontMatter: frontmatter, content: body };\n}\n"]}
|
package/dist/node.d.ts
CHANGED
|
@@ -1,8 +1,43 @@
|
|
|
1
|
-
import { a as RenderMarkdownOptions } from './types-
|
|
1
|
+
import { a as FeatherdownOptions, F as FeatherdownResult, b as RenderMarkdownOptions } from './types-Blk9BrZ4.js';
|
|
2
|
+
export { F as FeatherdownDiagnosticsError } from './featherdownDiagnosticsError-CE9gG3W7.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Node-only Mermaid rendering intent for {@link Featherdown} from `featherdown/node`.
|
|
6
|
+
* SVG rendering uses the optional Playwright peer; see `featherdown` docs.
|
|
7
|
+
*/
|
|
8
|
+
type NodeFeatherdownMermaidOptions = {
|
|
9
|
+
render: 'svg';
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* {@link FeatherdownOptions} plus optional Mermaid SVG rendering (Node entry only).
|
|
13
|
+
*/
|
|
14
|
+
type NodeFeatherdownOptions = FeatherdownOptions & {
|
|
15
|
+
mermaid?: false | NodeFeatherdownMermaidOptions;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Per-call options for Node {@link Featherdown.parse} / {@link Featherdown.parseFile}.
|
|
19
|
+
*/
|
|
20
|
+
type NodeFeatherdownParseOptions = NodeFeatherdownOptions;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Node {@link Featherdown}: same {@link Featherdown.parse} behavior as the browser
|
|
24
|
+
* entry when Mermaid SVG is off; delegates to the base class. With `mermaid: { render: "svg" }`,
|
|
25
|
+
* uses the inline-SVG Mermaid pipeline and sets {@link FeatherdownResult.assets.features.mermaid}.
|
|
26
|
+
*/
|
|
27
|
+
declare class Featherdown {
|
|
28
|
+
private readonly base;
|
|
29
|
+
private readonly ctorOptions;
|
|
30
|
+
constructor(options?: NodeFeatherdownOptions);
|
|
31
|
+
parse(markdown: string, parseOptions?: NodeFeatherdownParseOptions): Promise<FeatherdownResult>;
|
|
32
|
+
parseFile(path: string, parseOptions?: NodeFeatherdownParseOptions): Promise<FeatherdownResult>;
|
|
33
|
+
}
|
|
2
34
|
|
|
3
35
|
/**
|
|
4
36
|
* Node-only Mermaid rendering entrypoint.
|
|
5
37
|
*
|
|
38
|
+
* @deprecated Prefer `new Featherdown({ mermaid: { render: "svg" } }).parse(markdown)` from `featherdown/node`.
|
|
39
|
+
* This helper remains available for compatibility.
|
|
40
|
+
*
|
|
6
41
|
* Renders Markdown to sanitized HTML with Mermaid diagrams expanded to inline
|
|
7
42
|
* SVG using the Node publishing pipeline. If an individual Mermaid block fails
|
|
8
43
|
* to render, that block is preserved as a normal code fence while the rest of
|
|
@@ -10,4 +45,4 @@ import { a as RenderMarkdownOptions } from './types-BuSz3Zo6.js';
|
|
|
10
45
|
*/
|
|
11
46
|
declare function renderMarkdownToHtmlWithMermaid(markdown: string, options?: RenderMarkdownOptions): Promise<string>;
|
|
12
47
|
|
|
13
|
-
export { RenderMarkdownOptions, renderMarkdownToHtmlWithMermaid };
|
|
48
|
+
export { Featherdown, type NodeFeatherdownMermaidOptions, type NodeFeatherdownOptions, type NodeFeatherdownParseOptions, RenderMarkdownOptions, renderMarkdownToHtmlWithMermaid };
|