featherdown 0.1.1 → 0.2.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 +418 -64
- package/dist/chunk-3D4JFT3A.js +552 -0
- package/dist/chunk-3D4JFT3A.js.map +1 -0
- package/dist/index.d.ts +87 -11
- package/dist/index.js +229 -9
- package/dist/index.js.map +1 -1
- package/dist/node.d.ts +9 -1
- package/dist/node.js +17 -2
- package/dist/node.js.map +1 -1
- package/dist/types-BuSz3Zo6.d.ts +139 -0
- package/package.json +14 -1
- package/dist/chunk-CVZY5VWM.js +0 -243
- package/dist/chunk-CVZY5VWM.js.map +0 -1
- package/dist/types-DlRranpy.d.ts +0 -20
package/dist/index.d.ts
CHANGED
|
@@ -1,47 +1,123 @@
|
|
|
1
|
-
import { R as RenderDiagnostic, a as RenderMarkdownOptions } from './types-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import * as mdast from 'mdast';
|
|
1
|
+
import { R as RenderDiagnostic, a as RenderMarkdownOptions, b as RenderMarkdownDocumentResult } from './types-BuSz3Zo6.js';
|
|
2
|
+
export { H as HeadingMetadata, T as TocItem } from './types-BuSz3Zo6.js';
|
|
3
|
+
import { Root as Root$1 } from 'hast';
|
|
4
|
+
import { Root } from 'mdast';
|
|
5
|
+
import { Processor, Plugin } from 'unified';
|
|
7
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Utility entrypoint for package identity checks.
|
|
9
|
+
*
|
|
10
|
+
* Exports a stable library identifier used in diagnostics and smoke tests.
|
|
11
|
+
*/
|
|
8
12
|
/**
|
|
9
13
|
* Stable identifier for this library. Intended for diagnostics and smoke tests.
|
|
10
14
|
*/
|
|
11
15
|
declare function libraryId(): string;
|
|
12
16
|
|
|
13
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Parse Markdown content with optional YAML front matter.
|
|
19
|
+
*
|
|
20
|
+
* Exports a small utility that splits a raw Markdown file into front matter
|
|
21
|
+
* metadata and content body for downstream rendering pipelines.
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* Parsed result from a Markdown file with optional front matter.
|
|
25
|
+
*/
|
|
26
|
+
type ParsedMarkdownFile = {
|
|
27
|
+
/**
|
|
28
|
+
* YAML front matter object. Empty when front matter is missing.
|
|
29
|
+
*/
|
|
14
30
|
frontMatter: Record<string, unknown>;
|
|
31
|
+
/**
|
|
32
|
+
* Markdown body content after the front matter fence.
|
|
33
|
+
*/
|
|
15
34
|
content: string;
|
|
16
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;
|
|
17
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Emits a non-fatal rendering diagnostic.
|
|
46
|
+
*/
|
|
18
47
|
type DiagnosticEmitter = (d: RenderDiagnostic) => void;
|
|
19
48
|
|
|
20
49
|
type InternalOptions = RenderMarkdownOptions & {
|
|
21
50
|
emitDiagnostic?: DiagnosticEmitter;
|
|
51
|
+
preserveHeadingCustomIdMarker?: boolean;
|
|
22
52
|
};
|
|
23
|
-
|
|
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>;
|
|
24
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
|
+
*/
|
|
25
68
|
declare function createMarkdownProcessor(options?: RenderMarkdownOptions): ReturnType<typeof createMarkdownProcessorInternal>;
|
|
26
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
|
+
*/
|
|
27
76
|
/**
|
|
28
77
|
* Replaces supported `chart-…` fenced JSON blocks with a mount placeholder.
|
|
29
78
|
* Invalid JSON leaves the original `<pre><code>` unchanged.
|
|
30
79
|
*/
|
|
31
|
-
declare const rehypeChartBlocks: Plugin<[], Root>;
|
|
80
|
+
declare const rehypeChartBlocks: Plugin<[], Root$1>;
|
|
32
81
|
|
|
82
|
+
/**
|
|
83
|
+
* Rehype plugin entrypoint for image class and CDN URL rewriting.
|
|
84
|
+
*
|
|
85
|
+
* Exports plugin options and a plugin that annotates image nodes and can
|
|
86
|
+
* rewrite local image sources with caller-provided manifest mappings.
|
|
87
|
+
*/
|
|
88
|
+
/**
|
|
89
|
+
* Options accepted by `rehypeCdnImages`.
|
|
90
|
+
*/
|
|
33
91
|
type RehypeCdnImagesOptions = RenderMarkdownOptions;
|
|
34
92
|
/**
|
|
35
93
|
* Adds `markdown-inline-img` to all images and optionally rewrites `src` using
|
|
36
94
|
* caller-provided manifest data.
|
|
37
95
|
*/
|
|
38
|
-
declare const rehypeCdnImages: Plugin<[RehypeCdnImagesOptions?], Root>;
|
|
96
|
+
declare const rehypeCdnImages: Plugin<[RehypeCdnImagesOptions?], Root$1>;
|
|
39
97
|
|
|
98
|
+
/**
|
|
99
|
+
* Render Markdown to sanitized HTML and collect non-fatal diagnostics.
|
|
100
|
+
*
|
|
101
|
+
* This entrypoint is useful when callers want warning metadata in addition to
|
|
102
|
+
* the final HTML string.
|
|
103
|
+
*/
|
|
40
104
|
declare function renderMarkdown(markdown: string, options?: RenderMarkdownOptions): Promise<{
|
|
41
105
|
html: string;
|
|
42
106
|
diagnostics: RenderDiagnostic[];
|
|
43
107
|
}>;
|
|
44
108
|
|
|
109
|
+
/**
|
|
110
|
+
* Render Markdown to sanitized HTML and extract publishing metadata from the
|
|
111
|
+
* final rendered document structure.
|
|
112
|
+
*/
|
|
113
|
+
declare function renderMarkdownDocument(markdown: string, options?: RenderMarkdownOptions): Promise<RenderMarkdownDocumentResult>;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Render Markdown to sanitized HTML with featherdown defaults.
|
|
117
|
+
*
|
|
118
|
+
* This is the simplest public API for callers that only need HTML output and
|
|
119
|
+
* do not need diagnostics.
|
|
120
|
+
*/
|
|
45
121
|
declare function renderMarkdownToHtml(markdown: string, options?: RenderMarkdownOptions): Promise<string>;
|
|
46
122
|
|
|
47
|
-
export { RenderDiagnostic, RenderMarkdownOptions, createMarkdownProcessor, libraryId, parseMarkdownFile, rehypeCdnImages, rehypeChartBlocks, renderMarkdown, renderMarkdownToHtml };
|
|
123
|
+
export { RenderDiagnostic, RenderMarkdownDocumentResult, RenderMarkdownOptions, createMarkdownProcessor, libraryId, parseMarkdownFile, rehypeCdnImages, rehypeChartBlocks, renderMarkdown, renderMarkdownDocument, renderMarkdownToHtml };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { rehypeCdnImages, rehypeChartBlocks_default, remarkHeadingIds, markdownSanitizeSchema } from './chunk-
|
|
1
|
+
import { rehypeCdnImages, rehypeChartBlocks_default, remarkHeadingIds, remarkCodeBlockTitles, rehypeCodeBlockTitles_default, markdownSanitizeSchema, rehypeCodeLineHighlights_default } from './chunk-3D4JFT3A.js';
|
|
2
2
|
import yaml from 'js-yaml';
|
|
3
3
|
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
|
|
4
4
|
import rehypeHighlight from 'rehype-highlight';
|
|
@@ -7,11 +7,14 @@ import rehypeRaw from 'rehype-raw';
|
|
|
7
7
|
import rehypeSanitize from 'rehype-sanitize';
|
|
8
8
|
import rehypeSlug from 'rehype-slug';
|
|
9
9
|
import rehypeStringify from 'rehype-stringify';
|
|
10
|
+
import remarkDirective from 'remark-directive';
|
|
10
11
|
import remarkGfm from 'remark-gfm';
|
|
11
12
|
import remarkMath from 'remark-math';
|
|
12
13
|
import remarkParse from 'remark-parse';
|
|
13
14
|
import remarkRehype from 'remark-rehype';
|
|
15
|
+
import { visit, SKIP, EXIT } from 'unist-util-visit';
|
|
14
16
|
import { unified } from 'unified';
|
|
17
|
+
import { toText } from 'hast-util-to-text';
|
|
15
18
|
|
|
16
19
|
// src/libraryId.ts
|
|
17
20
|
function libraryId() {
|
|
@@ -43,14 +46,124 @@ function parseMarkdownFile(raw) {
|
|
|
43
46
|
throw new Error(`Front matter YAML could not be parsed: ${detail}`);
|
|
44
47
|
}
|
|
45
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
|
+
|
|
144
|
+
// src/internal/createMarkdownProcessorInternal.ts
|
|
145
|
+
function rehypeStripHeadingCustomIdMarker() {
|
|
146
|
+
return (tree) => {
|
|
147
|
+
visit(tree, "element", (node) => {
|
|
148
|
+
if (!/^h[1-6]$/.test(node.tagName)) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
delete node.properties.dataHeadingCustomId;
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
}
|
|
46
155
|
function createMarkdownProcessorInternal(options) {
|
|
47
|
-
const processor = unified().use(remarkParse).use(remarkGfm).use(remarkMath).use(remarkHeadingIds).use(remarkRehype, { allowDangerousHtml: true }).use(rehypeRaw);
|
|
156
|
+
const processor = unified().use(remarkParse).use(remarkGfm).use(remarkDirective).use(remarkMath).use(remarkHeadingIds).use(remarkCallouts).use(remarkCodeBlockTitles).use(remarkRehype, { allowDangerousHtml: true }).use(rehypeRaw);
|
|
48
157
|
if (options?.emitDiagnostic) {
|
|
49
158
|
processor.use(rehypeChartBlocks_default, { emitDiagnostic: options.emitDiagnostic });
|
|
50
159
|
} else {
|
|
51
160
|
processor.use(rehypeChartBlocks_default);
|
|
52
161
|
}
|
|
53
|
-
processor.use(rehypeKatex, { output: "html" }).use(rehypeSanitize, markdownSanitizeSchema).use(rehypeSlug).use(rehypeAutolinkHeadings, { behavior: "wrap" }).use(rehypeHighlight).use(
|
|
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);
|
|
54
167
|
return processor;
|
|
55
168
|
}
|
|
56
169
|
|
|
@@ -77,15 +190,122 @@ function createDiagnosticCollector() {
|
|
|
77
190
|
};
|
|
78
191
|
}
|
|
79
192
|
|
|
80
|
-
// src/
|
|
81
|
-
|
|
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) {
|
|
82
278
|
const collector = createDiagnosticCollector();
|
|
83
279
|
const processor = createMarkdownProcessorInternal({
|
|
84
280
|
...options,
|
|
85
|
-
emitDiagnostic: collector.emit
|
|
281
|
+
emitDiagnostic: collector.emit,
|
|
282
|
+
preserveHeadingCustomIdMarker: true
|
|
86
283
|
});
|
|
87
|
-
const
|
|
88
|
-
|
|
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
|
+
};
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// src/renderMarkdown.ts
|
|
301
|
+
async function renderMarkdown(markdown, options) {
|
|
302
|
+
const result = await renderMarkdownDocumentInternal(markdown, options);
|
|
303
|
+
return { html: result.html, diagnostics: result.diagnostics };
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// src/renderMarkdownDocument.ts
|
|
307
|
+
async function renderMarkdownDocument(markdown, options) {
|
|
308
|
+
return renderMarkdownDocumentInternal(markdown, options);
|
|
89
309
|
}
|
|
90
310
|
|
|
91
311
|
// src/renderMarkdownToHtml.ts
|
|
@@ -94,6 +314,6 @@ async function renderMarkdownToHtml(markdown, options) {
|
|
|
94
314
|
return result.html;
|
|
95
315
|
}
|
|
96
316
|
|
|
97
|
-
export { createMarkdownProcessor, libraryId, parseMarkdownFile, rehypeCdnImages2 as rehypeCdnImages, rehypeChartBlocks, renderMarkdown, renderMarkdownToHtml };
|
|
317
|
+
export { createMarkdownProcessor, libraryId, parseMarkdownFile, rehypeCdnImages2 as rehypeCdnImages, rehypeChartBlocks, renderMarkdown, renderMarkdownDocument, renderMarkdownToHtml };
|
|
98
318
|
//# sourceMappingURL=index.js.map
|
|
99
319
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/libraryId.ts","../src/parseMarkdownFile.ts","../src/internal/createMarkdownProcessorInternal.ts","../src/createMarkdownProcessor.ts","../src/rehypeChartBlocks.ts","../src/rehypeCdnImages.ts","../src/internal/diagnostics.ts","../src/renderMarkdown.ts","../src/renderMarkdownToHtml.ts"],"names":["rehypeCdnImages"],"mappings":";;;;;;;;;;;;;;;;AAGO,SAAS,SAAA,GAAoB;AAClC,EAAA,OAAO,aAAA;AACT;ACHO,SAAS,kBAAkB,GAAA,EAGhC;AACA,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,IAAA,IAAI,MAAA,KAAW,KAAA,CAAA,IAAa,MAAA,KAAW,IAAA,EAAM;AAC3C,MAAA,OAAO,EAAE,WAAA,EAAa,EAAC,EAAG,OAAA,EAAQ;AAAA,IACpC;AACA,IAAA,IAAI,OAAO,MAAA,KAAW,QAAA,I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ChD,GAAA,CAAI,eAAe,CAAA,CACnB,GAAA,CAAI,eAAA,EAAyB,OAAO,CAAA,CACpC,IAAI,eAAe,CAAA;AAEtB,EAAA,OAAO,SAAA;AACT;;;AC/CO,SAAS,wBACd,OAAA,EACoD;AACpD,EAAA,OAAO,gCAAgC,OAAO,CAAA;AAChD;;;ACCO,IAAM,iBAAA,GACX;;;ACEK,IAAMA,gBAAAA,GACX;;;ACRK,SAAS,yBAAA,GAA4B;AAC1C,EAAA,MAAM,cAAkC,EAAC;AACzC,EAAA,MAAM,IAAA,GAA0B,CAAC,CAAA,KAAM;AACrC,IAAA,WAAA,CAAY,KAAK,CAAC,CAAA;AAAA,EACpB,CAAA;AAEA,EAAA,OAAO;AAAA,IACL,IAAA;AAAA,IACA;AAAA,GACF;AACF;;;ACVA,eAAsB,cAAA,CACpB,UACA,OAAA,EAC4D;AAC5D,EAAA,MAAM,YAAY,yBAAA,EAA0B;AAC5C,EAAA,MAAM,YAAY,+BAAA,CAAgC;AAAA,IAChD,GAAG,OAAA;AAAA,IACH,gBAAgB,SAAA,CAAU;AAAA,GAC3B,CAAA;AACD,EAAA,MAAM,IAAA,GAAO,MAAM,SAAA,CAAU,OAAA,CAAQ,QAAQ,CAAA;AAC7C,EAAA,OAAO,EAAE,IAAA,EAAM,MAAA,CAAO,IAAI,CAAA,EAAG,WAAA,EAAa,UAAU,WAAA,EAAY;AAClE;;;ACZA,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 * 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\nexport function parseMarkdownFile(raw: string): {\n frontMatter: Record<string, unknown>;\n content: string;\n} {\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 rehypeAutolinkHeadings from 'rehype-autolink-headings';\nimport rehypeHighlight from 'rehype-highlight';\nimport rehypeKatex from 'rehype-katex';\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 remarkGfm from 'remark-gfm';\nimport remarkMath from 'remark-math';\nimport remarkParse from 'remark-parse';\nimport remarkRehype from 'remark-rehype';\nimport { unified } from 'unified';\nimport type { RenderMarkdownOptions } from '../types.js';\nimport { remarkHeadingIds } from './headingIdsRemark.js';\nimport type { DiagnosticEmitter } from './diagnostics.js';\nimport { markdownSanitizeSchema } from './sanitizeSchema.js';\n\ntype InternalOptions = RenderMarkdownOptions & {\n emitDiagnostic?: DiagnosticEmitter;\n};\n\nexport function createMarkdownProcessorInternal(\n options?: InternalOptions,\n) {\n const processor = unified()\n .use(remarkParse)\n .use(remarkGfm)\n .use(remarkMath)\n .use(remarkHeadingIds)\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(rehypeKatex, { output: 'html' })\n .use(rehypeSanitize, markdownSanitizeSchema)\n .use(rehypeSlug)\n .use(rehypeAutolinkHeadings, { behavior: 'wrap' })\n .use(rehypeHighlight)\n .use(rehypeCdnImagesInternal, options)\n .use(rehypeStringify);\n\n return processor;\n}\n\n","import type { RenderMarkdownOptions } from './types.js';\nimport { createMarkdownProcessorInternal } from './internal/createMarkdownProcessorInternal.js';\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 * 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\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\nexport type DiagnosticEmitter = (d: RenderDiagnostic) => void;\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 { createMarkdownProcessorInternal } from './internal/createMarkdownProcessorInternal.js';\nimport { createDiagnosticCollector } from './internal/diagnostics.js';\nimport type { RenderDiagnostic, RenderMarkdownOptions } from './types.js';\n\nexport async function renderMarkdown(\n markdown: string,\n options?: RenderMarkdownOptions,\n): Promise<{ html: string; diagnostics: RenderDiagnostic[] }> {\n const collector = createDiagnosticCollector();\n const processor = createMarkdownProcessorInternal({\n ...options,\n emitDiagnostic: collector.emit,\n });\n const file = await processor.process(markdown);\n return { html: String(file), diagnostics: collector.diagnostics };\n}\n\n","import { renderMarkdown } from './renderMarkdown.js';\nimport type { RenderMarkdownOptions } from './types.js';\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/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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A,CAA+B,QAAA,EAAU,OAAO,CAAA;AACrE,EAAA,OAAO,EAAE,IAAA,EAAM,MAAA,CAAO,IAAA,EAAM,WAAA,EAAa,OAAO,WAAA,EAAY;AAC9D;;;ACRA,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"]}
|
package/dist/node.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
import { a as RenderMarkdownOptions } from './types-
|
|
1
|
+
import { a as RenderMarkdownOptions } from './types-BuSz3Zo6.js';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Node-only Mermaid rendering entrypoint.
|
|
5
|
+
*
|
|
6
|
+
* Renders Markdown to sanitized HTML with Mermaid diagrams expanded to inline
|
|
7
|
+
* SVG using the Node publishing pipeline. If an individual Mermaid block fails
|
|
8
|
+
* to render, that block is preserved as a normal code fence while the rest of
|
|
9
|
+
* the document continues rendering.
|
|
10
|
+
*/
|
|
3
11
|
declare function renderMarkdownToHtmlWithMermaid(markdown: string, options?: RenderMarkdownOptions): Promise<string>;
|
|
4
12
|
|
|
5
13
|
export { RenderMarkdownOptions, renderMarkdownToHtmlWithMermaid };
|
package/dist/node.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { remarkHeadingIds, rehypeChartBlocks_default, schemaWithSvg, rehypeCdnImages } from './chunk-
|
|
1
|
+
import { remarkHeadingIds, remarkCodeBlockTitles, rehypeChartBlocks_default, rehypeCodeBlockTitles_default, schemaWithSvg, rehypeCodeLineHighlights_default, rehypeCdnImages } from './chunk-3D4JFT3A.js';
|
|
2
2
|
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
|
|
3
3
|
import rehypeHighlight from 'rehype-highlight';
|
|
4
4
|
import rehypeKatex from 'rehype-katex';
|
|
@@ -12,9 +12,24 @@ import remarkMath from 'remark-math';
|
|
|
12
12
|
import remarkParse from 'remark-parse';
|
|
13
13
|
import remarkRehype from 'remark-rehype';
|
|
14
14
|
import { unified } from 'unified';
|
|
15
|
+
import { visit } from 'unist-util-visit';
|
|
15
16
|
|
|
17
|
+
function rehypeStripHeadingCustomIdMarker() {
|
|
18
|
+
return (tree) => {
|
|
19
|
+
visit(tree, "element", (node) => {
|
|
20
|
+
if (!/^h[1-6]$/.test(node.tagName)) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
delete node.properties.dataHeadingCustomId;
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
}
|
|
16
27
|
function createMarkdownProcessorWithMermaidInternal(options) {
|
|
17
|
-
|
|
28
|
+
const fallbackToOriginalCodeBlock = (element) => element;
|
|
29
|
+
return unified().use(remarkParse).use(remarkGfm).use(remarkMath).use(remarkHeadingIds).use(remarkCodeBlockTitles).use(remarkRehype, { allowDangerousHtml: true }).use(rehypeRaw).use(rehypeChartBlocks_default).use(rehypeSlug).use(rehypeAutolinkHeadings, { behavior: "wrap" }).use(rehypeCodeBlockTitles_default).use(rehypeKatex, { output: "html" }).use(rehypeHighlight).use(rehypeMermaid, {
|
|
30
|
+
strategy: "inline-svg",
|
|
31
|
+
errorFallback: fallbackToOriginalCodeBlock
|
|
32
|
+
}).use(rehypeSanitize, schemaWithSvg).use(rehypeCodeLineHighlights_default).use(rehypeStripHeadingCustomIdMarker).use(rehypeCdnImages, options).use(rehypeStringify);
|
|
18
33
|
}
|
|
19
34
|
|
|
20
35
|
// src/node.ts
|
package/dist/node.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/internal/createMarkdownProcessorWithMermaidInternal.ts","../src/node.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/internal/createMarkdownProcessorWithMermaidInternal.ts","../src/node.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAwBA,SAAS,gCAAA,GAAmC;AAC1C,EAAA,OAAO,CAAC,IAAA,KAA8B;AACpC,IAAA,KAAA,CAAM,IAAA,EAAM,SAAA,EAAW,CAAC,IAAA,KAAS;AAC/B,MAAA,IAAI,CAAC,UAAA,CAAW,IAAA,CAAK,IAAA,CAAK,OAAO,CAAA,EAAG;AAClC,QAAA;AAAA,MACF;AACA,MAAA,OAAO,KAAK,UAAA,CAAW,mBAAA;AAAA,IACzB,CAAC,CAAA;AAAA,EACH,CAAA;AACF;AAQO,SAAS,2CACd,OAAA,EACA;AACA,EAAA,MAAM,2BAAA,GAA8B,CAAC,OAAA,KAA8B,OAAA;AAEnE,EAAA,OAAO,OAAA,EAAQ,CACZ,GAAA,CAAI,WAAW,CAAA,CACf,IAAI,SAAS,CAAA,CACb,GAAA,CAAI,UAAU,CAAA,CACd,GAAA,CAAI,gBAAgB,CAAA,CACpB,GAAA,CAAI,qBAAqB,CAAA,CACzB,GAAA,CAAI,YAAA,EAAc,EAAE,kBAAA,EAAoB,IAAA,EAAM,CAAA,CAC9C,GAAA,CAAI,SAAS,CAAA,CACb,IAAI,yBAAyB,CAAA,CAC7B,GAAA,CAAI,UAAU,CAAA,CACd,GAAA,CAAI,wBAAwB,EAAE,QAAA,EAAU,MAAA,EAAQ,CAAA,CAChD,GAAA,CAAI,6BAAqB,CAAA,CACzB,GAAA,CAAI,WAAA,EAAa,EAAE,MAAA,EAAQ,MAAA,EAAQ,CAAA,CACnC,GAAA,CAAI,eAAe,CAAA,CACnB,GAAA,CAAI,aAAA,EAAe;AAAA,IAClB,QAAA,EAAU,YAAA;AAAA,IACV,aAAA,EAAe;AAAA,GAChB,CAAA,CACA,GAAA,CAAI,cAAA,EAAgB,aAAa,EACjC,GAAA,CAAI,gCAAwB,CAAA,CAC5B,GAAA,CAAI,gCAAgC,CAAA,CACpC,GAAA,CAAI,iBAAyB,OAAO,CAAA,CACpC,IAAI,eAAe,CAAA;AACxB;;;AC1DA,eAAsB,+BAAA,CACpB,UACA,OAAA,EACiB;AACjB,EAAA,MAAM,SAAA,GAAY,2CAA2C,OAAO,CAAA;AACpE,EAAA,MAAM,IAAA,GAAO,MAAM,SAAA,CAAU,OAAA,CAAQ,QAAQ,CAAA;AAC7C,EAAA,OAAO,OAAO,IAAI,CAAA;AACpB","file":"node.js","sourcesContent":["import rehypeAutolinkHeadings from 'rehype-autolink-headings';\nimport rehypeHighlight from 'rehype-highlight';\nimport rehypeKatex from 'rehype-katex';\nimport rehypeMermaid from 'rehype-mermaid';\nimport rehypeCodeBlockTitles from './rehypeCodeBlockTitles.js';\nimport rehypeCodeLineHighlights from './rehypeCodeLineHighlights.js';\nimport rehypeRaw from 'rehype-raw';\nimport rehypeSanitize from 'rehype-sanitize';\nimport rehypeSlug from 'rehype-slug';\nimport rehypeStringify from 'rehype-stringify';\nimport type { Element, Root as HastRoot } from 'hast';\nimport remarkGfm from 'remark-gfm';\nimport remarkMath from 'remark-math';\nimport remarkParse from 'remark-parse';\nimport remarkRehype from 'remark-rehype';\nimport { unified } from 'unified';\nimport { visit } from 'unist-util-visit';\nimport type { RenderMarkdownOptions } from '../types.js';\nimport rehypeChartBlocksInternal from './rehypeChartBlocksInternal.js';\nimport rehypeCdnImagesInternal from './rehypeCdnImagesInternal.js';\nimport { remarkHeadingIds } from './headingIdsRemark.js';\nimport { remarkCodeBlockTitles } from './remarkCodeBlockTitles.js';\nimport { schemaWithSvg } from './sanitizeSchema.js';\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 Node-focused unified processor that includes Mermaid rendering.\n *\n * Internal helper for the `node` subpath; enables inline SVG Mermaid output\n * with a sanitizer schema that permits the required SVG elements.\n */\nexport function createMarkdownProcessorWithMermaidInternal(\n options?: RenderMarkdownOptions,\n) {\n const fallbackToOriginalCodeBlock = (element: Element): Element => element;\n\n return unified()\n .use(remarkParse)\n .use(remarkGfm)\n .use(remarkMath)\n .use(remarkHeadingIds)\n .use(remarkCodeBlockTitles)\n .use(remarkRehype, { allowDangerousHtml: true })\n .use(rehypeRaw)\n .use(rehypeChartBlocksInternal)\n .use(rehypeSlug)\n .use(rehypeAutolinkHeadings, { behavior: 'wrap' })\n .use(rehypeCodeBlockTitles)\n .use(rehypeKatex, { output: 'html' })\n .use(rehypeHighlight)\n .use(rehypeMermaid, {\n strategy: 'inline-svg',\n errorFallback: fallbackToOriginalCodeBlock,\n })\n .use(rehypeSanitize, schemaWithSvg)\n .use(rehypeCodeLineHighlights)\n .use(rehypeStripHeadingCustomIdMarker)\n .use(rehypeCdnImagesInternal, options)\n .use(rehypeStringify);\n}\n\n","import { createMarkdownProcessorWithMermaidInternal } from './internal/createMarkdownProcessorWithMermaidInternal.js';\nimport type { RenderMarkdownOptions } from './types.js';\n\n/**\n * Node-only Mermaid rendering entrypoint.\n *\n * Renders Markdown to sanitized HTML with Mermaid diagrams expanded to inline\n * SVG using the Node publishing pipeline. If an individual Mermaid block fails\n * to render, that block is preserved as a normal code fence while the rest of\n * the document continues rendering.\n */\nexport async function renderMarkdownToHtmlWithMermaid(\n markdown: string,\n options?: RenderMarkdownOptions,\n): Promise<string> {\n const processor = createMarkdownProcessorWithMermaidInternal(options);\n const file = await processor.process(markdown);\n return String(file);\n}\n\n/**\n * Shared rendering options used by the Node Mermaid entrypoint.\n */\nexport type { RenderMarkdownOptions } from './types.js';\n\n"]}
|