featherdown 0.1.2 → 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 +382 -107
- 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-YKLQHPRB.js +711 -0
- package/dist/chunk-YKLQHPRB.js.map +1 -0
- package/dist/featherdownDiagnosticsError-CE9gG3W7.d.ts +19 -0
- package/dist/index.d.ts +82 -29
- package/dist/index.js +17 -80
- package/dist/index.js.map +1 -1
- package/dist/node.d.ts +45 -2
- package/dist/node.js +232 -3
- package/dist/node.js.map +1 -1
- package/dist/types-Blk9BrZ4.d.ts +250 -0
- package/package.json +27 -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-CVZY5VWM.js +0 -243
- package/dist/chunk-CVZY5VWM.js.map +0 -1
- package/dist/types-DlRranpy.d.ts +0 -20
package/dist/node.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Featherdown, mergeFeatherdownOptions, resolveFeatherdownOptions, pickRenderMarkdownOptions, parseFrontmatter, buildMetadataFromFrontmatter, toProcessorGates, buildFeatherdownResult, throwIfStrictDiagnosticsViolated, createDiagnosticCollector } from './chunk-CWUDY7YI.js';
|
|
2
|
+
export { FeatherdownDiagnosticsError } from './chunk-CWUDY7YI.js';
|
|
3
|
+
import { remarkHeadingIds, remarkCallouts, remarkCodeBlockTitles, rehypeChartBlocks_default, rehypeCodeBlockTitles_default, schemaWithSvg, rehypeCodeLineHighlights_default, rehypeCdnImages } from './chunk-YKLQHPRB.js';
|
|
2
4
|
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
|
|
3
5
|
import rehypeHighlight from 'rehype-highlight';
|
|
4
6
|
import rehypeKatex from 'rehype-katex';
|
|
@@ -7,15 +9,242 @@ import rehypeRaw from 'rehype-raw';
|
|
|
7
9
|
import rehypeSanitize from 'rehype-sanitize';
|
|
8
10
|
import rehypeSlug from 'rehype-slug';
|
|
9
11
|
import rehypeStringify from 'rehype-stringify';
|
|
12
|
+
import remarkDirective from 'remark-directive';
|
|
10
13
|
import remarkGfm from 'remark-gfm';
|
|
11
14
|
import remarkMath from 'remark-math';
|
|
12
15
|
import remarkParse from 'remark-parse';
|
|
13
16
|
import remarkRehype from 'remark-rehype';
|
|
14
17
|
import { unified } from 'unified';
|
|
18
|
+
import { visit, EXIT } from 'unist-util-visit';
|
|
19
|
+
import { readFile } from 'fs/promises';
|
|
20
|
+
import { toText } from 'hast-util-to-text';
|
|
15
21
|
|
|
22
|
+
function rehypeStripHeadingCustomIdMarker() {
|
|
23
|
+
return (tree) => {
|
|
24
|
+
visit(tree, "element", (node) => {
|
|
25
|
+
if (!/^h[1-6]$/.test(node.tagName)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
delete node.properties.dataHeadingCustomId;
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
}
|
|
16
32
|
function createMarkdownProcessorWithMermaidInternal(options) {
|
|
17
|
-
|
|
33
|
+
const gates = options?.features ?? {
|
|
34
|
+
math: true,
|
|
35
|
+
code: true,
|
|
36
|
+
codeHighlighting: true,
|
|
37
|
+
charts: true,
|
|
38
|
+
sanitize: true
|
|
39
|
+
};
|
|
40
|
+
const fallbackToOriginalCodeBlock = (element) => element;
|
|
41
|
+
const processor = unified().use(remarkParse).use(remarkGfm).use(remarkDirective);
|
|
42
|
+
if (gates.math) {
|
|
43
|
+
processor.use(remarkMath);
|
|
44
|
+
}
|
|
45
|
+
processor.use(remarkHeadingIds).use(remarkCallouts);
|
|
46
|
+
if (gates.code) {
|
|
47
|
+
processor.use(remarkCodeBlockTitles);
|
|
48
|
+
}
|
|
49
|
+
processor.use(remarkRehype, { allowDangerousHtml: true }).use(rehypeRaw);
|
|
50
|
+
if (gates.charts) {
|
|
51
|
+
if (options?.emitDiagnostic) {
|
|
52
|
+
processor.use(rehypeChartBlocks_default, { emitDiagnostic: options.emitDiagnostic });
|
|
53
|
+
} else {
|
|
54
|
+
processor.use(rehypeChartBlocks_default);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
processor.use(rehypeSlug).use(rehypeAutolinkHeadings, { behavior: "wrap" });
|
|
58
|
+
if (gates.code) {
|
|
59
|
+
processor.use(rehypeCodeBlockTitles_default);
|
|
60
|
+
}
|
|
61
|
+
if (gates.math) {
|
|
62
|
+
processor.use(rehypeKatex, { output: "html" });
|
|
63
|
+
}
|
|
64
|
+
if (gates.code && gates.codeHighlighting) {
|
|
65
|
+
processor.use(rehypeHighlight);
|
|
66
|
+
}
|
|
67
|
+
processor.use(rehypeMermaid, {
|
|
68
|
+
strategy: "inline-svg",
|
|
69
|
+
errorFallback: fallbackToOriginalCodeBlock
|
|
70
|
+
});
|
|
71
|
+
if (gates.sanitize) {
|
|
72
|
+
processor.use(rehypeSanitize, schemaWithSvg);
|
|
73
|
+
}
|
|
74
|
+
if (gates.code && gates.codeHighlighting) {
|
|
75
|
+
processor.use(rehypeCodeLineHighlights_default);
|
|
76
|
+
}
|
|
77
|
+
if (!options?.preserveHeadingCustomIdMarker) {
|
|
78
|
+
processor.use(rehypeStripHeadingCustomIdMarker);
|
|
79
|
+
}
|
|
80
|
+
processor.use(rehypeCdnImages, options).use(rehypeStringify);
|
|
81
|
+
return processor;
|
|
82
|
+
}
|
|
83
|
+
var WORDS_PER_MINUTE = 200;
|
|
84
|
+
var excerptTagNames = /* @__PURE__ */ new Set(["p", "blockquote", "li"]);
|
|
85
|
+
function normalizeText(text) {
|
|
86
|
+
return text.replace(/\s+/g, " ").trim();
|
|
87
|
+
}
|
|
88
|
+
function getHeadingDepth(tagName) {
|
|
89
|
+
const match = /^h([1-6])$/.exec(tagName);
|
|
90
|
+
if (!match) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
return Number(match[1]);
|
|
94
|
+
}
|
|
95
|
+
function isParagraphLikeTagName(tagName) {
|
|
96
|
+
return excerptTagNames.has(tagName);
|
|
97
|
+
}
|
|
98
|
+
function isCustomHeadingId(value) {
|
|
99
|
+
return value === true || value === "true" || value === "";
|
|
100
|
+
}
|
|
101
|
+
function extractHeadings(root) {
|
|
102
|
+
const headings = [];
|
|
103
|
+
visit(root, "element", (node) => {
|
|
104
|
+
const depth = getHeadingDepth(node.tagName);
|
|
105
|
+
if (!depth) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const id = typeof node.properties.id === "string" ? node.properties.id : "";
|
|
109
|
+
if (!id) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const text = normalizeText(toText(node));
|
|
113
|
+
if (!text) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
headings.push({
|
|
117
|
+
index: headings.length,
|
|
118
|
+
depth,
|
|
119
|
+
text,
|
|
120
|
+
id,
|
|
121
|
+
hasCustomId: isCustomHeadingId(node.properties.dataHeadingCustomId)
|
|
122
|
+
});
|
|
123
|
+
delete node.properties.dataHeadingCustomId;
|
|
124
|
+
});
|
|
125
|
+
return headings;
|
|
126
|
+
}
|
|
127
|
+
function extractToc(headings) {
|
|
128
|
+
return headings.map((heading) => ({
|
|
129
|
+
depth: heading.depth,
|
|
130
|
+
text: heading.text,
|
|
131
|
+
id: heading.id
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
function extractExcerpt(root) {
|
|
135
|
+
let excerpt = null;
|
|
136
|
+
visit(root, "element", (node) => {
|
|
137
|
+
if (excerpt !== null) {
|
|
138
|
+
return EXIT;
|
|
139
|
+
}
|
|
140
|
+
if (!isParagraphLikeTagName(node.tagName)) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const text = normalizeText(toText(node));
|
|
144
|
+
if (!text) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
excerpt = text;
|
|
148
|
+
return EXIT;
|
|
149
|
+
});
|
|
150
|
+
return excerpt;
|
|
151
|
+
}
|
|
152
|
+
function countWords(root) {
|
|
153
|
+
const text = normalizeText(toText(root));
|
|
154
|
+
if (!text) {
|
|
155
|
+
return 0;
|
|
156
|
+
}
|
|
157
|
+
const words = text.match(/\S+/g);
|
|
158
|
+
return words ? words.length : 0;
|
|
159
|
+
}
|
|
160
|
+
function estimateReadingMinutes(wordCount) {
|
|
161
|
+
if (wordCount <= 0) {
|
|
162
|
+
return 0;
|
|
163
|
+
}
|
|
164
|
+
return Math.max(1, Math.ceil(wordCount / WORDS_PER_MINUTE));
|
|
165
|
+
}
|
|
166
|
+
async function renderMarkdownDocumentWithMermaidInternal(markdown, options, pipelineFeatures) {
|
|
167
|
+
const collector = createDiagnosticCollector();
|
|
168
|
+
const processor = createMarkdownProcessorWithMermaidInternal({
|
|
169
|
+
...options,
|
|
170
|
+
emitDiagnostic: collector.emit,
|
|
171
|
+
preserveHeadingCustomIdMarker: true,
|
|
172
|
+
...pipelineFeatures !== void 0 ? { features: pipelineFeatures } : {}
|
|
173
|
+
});
|
|
174
|
+
const parsed = processor.parse(markdown);
|
|
175
|
+
const root = await processor.run(parsed);
|
|
176
|
+
const headings = extractHeadings(root);
|
|
177
|
+
const html = String(processor.stringify(root));
|
|
178
|
+
const wordCount = countWords(root);
|
|
179
|
+
return {
|
|
180
|
+
html,
|
|
181
|
+
diagnostics: collector.diagnostics,
|
|
182
|
+
toc: extractToc(headings),
|
|
183
|
+
headings,
|
|
184
|
+
excerpt: extractExcerpt(root),
|
|
185
|
+
wordCount,
|
|
186
|
+
estimatedReadingMinutes: estimateReadingMinutes(wordCount)
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// src/nodeFeatherdown.ts
|
|
191
|
+
function stripMermaidForBase(options) {
|
|
192
|
+
if (!options) {
|
|
193
|
+
return void 0;
|
|
194
|
+
}
|
|
195
|
+
const rest = { ...options };
|
|
196
|
+
delete rest.mermaid;
|
|
197
|
+
return Object.keys(rest).length > 0 ? rest : void 0;
|
|
198
|
+
}
|
|
199
|
+
function mergeNodeFeatherdownOptions(ctor, parse) {
|
|
200
|
+
const baseMerged = mergeFeatherdownOptions(stripMermaidForBase(ctor), stripMermaidForBase(parse));
|
|
201
|
+
const mermaid = parse?.mermaid !== void 0 ? parse.mermaid : ctor?.mermaid !== void 0 ? ctor.mermaid : void 0;
|
|
202
|
+
if (mermaid === void 0) {
|
|
203
|
+
return baseMerged;
|
|
204
|
+
}
|
|
205
|
+
return { ...baseMerged ?? {}, mermaid };
|
|
206
|
+
}
|
|
207
|
+
function isMermaidSvgEnabled(merged) {
|
|
208
|
+
return merged?.mermaid !== void 0 && merged.mermaid !== false;
|
|
18
209
|
}
|
|
210
|
+
var Featherdown2 = class {
|
|
211
|
+
base;
|
|
212
|
+
ctorOptions;
|
|
213
|
+
constructor(options) {
|
|
214
|
+
this.base = new Featherdown(stripMermaidForBase(options));
|
|
215
|
+
this.ctorOptions = options;
|
|
216
|
+
}
|
|
217
|
+
async parse(markdown, parseOptions) {
|
|
218
|
+
const mergedNode = mergeNodeFeatherdownOptions(this.ctorOptions, parseOptions);
|
|
219
|
+
if (!isMermaidSvgEnabled(mergedNode)) {
|
|
220
|
+
return this.base.parse(markdown, stripMermaidForBase(mergedNode));
|
|
221
|
+
}
|
|
222
|
+
const mergedOptions = mergeFeatherdownOptions(stripMermaidForBase(this.ctorOptions), stripMermaidForBase(parseOptions));
|
|
223
|
+
const resolvedOptions = resolveFeatherdownOptions(mergedOptions);
|
|
224
|
+
const legacy = pickRenderMarkdownOptions(mergedOptions);
|
|
225
|
+
const fm = parseFrontmatter(markdown, resolvedOptions.frontmatter);
|
|
226
|
+
const metadata = buildMetadataFromFrontmatter(fm.frontmatter);
|
|
227
|
+
const document = await renderMarkdownDocumentWithMermaidInternal(
|
|
228
|
+
fm.body,
|
|
229
|
+
legacy,
|
|
230
|
+
toProcessorGates(resolvedOptions)
|
|
231
|
+
);
|
|
232
|
+
const result = buildFeatherdownResult({
|
|
233
|
+
body: fm.body,
|
|
234
|
+
frontmatter: fm.frontmatter,
|
|
235
|
+
metadata,
|
|
236
|
+
document,
|
|
237
|
+
options: resolvedOptions,
|
|
238
|
+
mermaidFeature: true
|
|
239
|
+
});
|
|
240
|
+
throwIfStrictDiagnosticsViolated(resolvedOptions, result);
|
|
241
|
+
return result;
|
|
242
|
+
}
|
|
243
|
+
async parseFile(path, parseOptions) {
|
|
244
|
+
const markdown = await readFile(path, "utf8");
|
|
245
|
+
return this.parse(markdown, parseOptions);
|
|
246
|
+
}
|
|
247
|
+
};
|
|
19
248
|
|
|
20
249
|
// src/node.ts
|
|
21
250
|
async function renderMarkdownToHtmlWithMermaid(markdown, options) {
|
|
@@ -24,6 +253,6 @@ async function renderMarkdownToHtmlWithMermaid(markdown, options) {
|
|
|
24
253
|
return String(file);
|
|
25
254
|
}
|
|
26
255
|
|
|
27
|
-
export { renderMarkdownToHtmlWithMermaid };
|
|
256
|
+
export { Featherdown2 as Featherdown, renderMarkdownToHtmlWithMermaid };
|
|
28
257
|
//# sourceMappingURL=node.js.map
|
|
29
258
|
//# sourceMappingURL=node.js.map
|
package/dist/node.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/internal/createMarkdownProcessorWithMermaidInternal.ts","../src/node.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAmBO,SAAS,2CACd,OAAA,EACA;AACA,EAAA,OAAO,OAAA,EAAQ,CACZ,GAAA,CAAI,WAAW,CAAA,CACf,GAAA,CAAI,SAAS,CAAA,CACb,GAAA,CAAI,UAAU,CAAA,CACd,GAAA,CAAI,gBAAgB,CAAA,CACpB,GAAA,CAAI,YAAA,EAAc,EAAE,kBAAA,EAAoB,IAAA,EAAM,CAAA,CAC9C,GAAA,CAAI,SAAS,CAAA,CACb,GAAA,CAAI,yBAAyB,CAAA,CAC7B,GAAA,CAAI,UAAU,CAAA,CACd,GAAA,CAAI,sBAAA,EAAwB,EAAE,QAAA,EAAU,MAAA,EAAQ,CAAA,CAChD,GAAA,CAAI,WAAA,EAAa,EAAE,MAAA,EAAQ,MAAA,EAAQ,CAAA,CACnC,GAAA,CAAI,eAAe,CAAA,CACnB,GAAA,CAAI,aAAA,EAAe,EAAE,QAAA,EAAU,YAAA,EAAc,CAAA,CAC7C,GAAA,CAAI,cAAA,EAAgB,aAAa,CAAA,CACjC,GAAA,CAAI,eAAA,EAAyB,OAAO,CAAA,CACpC,IAAI,eAAe,CAAA;AACxB;;;ACnCA,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 rehypeRaw from 'rehype-raw';\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 rehypeChartBlocksInternal from './rehypeChartBlocksInternal.js';\nimport rehypeCdnImagesInternal from './rehypeCdnImagesInternal.js';\nimport { remarkHeadingIds } from './headingIdsRemark.js';\nimport { schemaWithSvg } from './sanitizeSchema.js';\n\nexport function createMarkdownProcessorWithMermaidInternal(\n options?: RenderMarkdownOptions,\n) {\n return unified()\n .use(remarkParse)\n .use(remarkGfm)\n .use(remarkMath)\n .use(remarkHeadingIds)\n .use(remarkRehype, { allowDangerousHtml: true })\n .use(rehypeRaw)\n .use(rehypeChartBlocksInternal)\n .use(rehypeSlug)\n .use(rehypeAutolinkHeadings, { behavior: 'wrap' })\n .use(rehypeKatex, { output: 'html' })\n .use(rehypeHighlight)\n .use(rehypeMermaid, { strategy: 'inline-svg' })\n .use(rehypeSanitize, schemaWithSvg)\n .use(rehypeCdnImagesInternal, options)\n .use(rehypeStringify);\n}\n\n","import { createMarkdownProcessorWithMermaidInternal } from './internal/createMarkdownProcessorWithMermaidInternal.js';\nimport type { RenderMarkdownOptions } from './types.js';\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\nexport type { RenderMarkdownOptions } from './types.js';\n\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/internal/createMarkdownProcessorWithMermaidInternal.ts","../src/internal/renderMarkdownDocumentWithMermaidInternal.ts","../src/nodeFeatherdown.ts","../src/node.ts"],"names":["visit","Featherdown"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA8BA,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;AAeO,SAAS,2CAA2C,OAAA,EAA2B;AACpF,EAAA,MAAM,KAAA,GAAuC,SAAS,QAAA,IAAY;AAAA,IAChE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,CAAgB,WAAW,CAAA;AACjE,IAAA,MAAM,QAAA,GAAW,4BAAA,CAA6B,EAAA,CAAG,WAAW,CAAA;AAC5D,IAAA,MAAM,WAAW,MAAM,yCAAA;AAAA,MACrB,EAAA,CAAG,IAAA;AAAA,MACH,MAAA;AAAA,MACA,iBAAiB,eAAe;AAAA,KAClC;AAEA,IAAA,MAAM,SAAS,sBAAA,CAAuB;AAAA,MACpC,MAAM,EAAA,CAAG,IAAA;AAAA,MACT,aAAa,EAAA,CAAG,WAAA;AAAA,MAChB,QAAA;AAAA,MACA,QAAA;AAAA,MACA,OAAA,EAAS,eAAA;AAAA,MACT,cAAA,EAAgB;AAAA,KACjB,CAAA;AACD,IAAA,gCAAA,CAAiC,iBAAiB,MAAM,CAAA;AACxD,IAAA,OAAO,MAAA;AAAA,EACT;AAAA,EAEA,MAAM,SAAA,CAAU,IAAA,EAAc,YAAA,EAAwE;AACpG,IAAA,MAAM,QAAA,GAAW,MAAM,QAAA,CAAS,IAAA,EAAM,MAAM,CAAA;AAC5C,IAAA,OAAO,IAAA,CAAK,KAAA,CAAM,QAAA,EAAU,YAAY,CAAA;AAAA,EAC1C;AACF;;;AC3EA,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 type { Root as MdastRoot } from 'mdast';\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 { Processor } from 'unified';\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 { remarkCallouts } from './remarkCallouts.js';\nimport { remarkCodeBlockTitles } from './remarkCodeBlockTitles.js';\nimport type { MarkdownProcessorFeatureGates } from './createMarkdownProcessorInternal.js';\nimport type { DiagnosticEmitter } from './diagnostics.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\ntype InternalOptions = RenderMarkdownOptions & {\n emitDiagnostic?: DiagnosticEmitter;\n preserveHeadingCustomIdMarker?: boolean;\n features?: MarkdownProcessorFeatureGates;\n};\n\n/**\n * Build the Node-focused unified processor that includes Mermaid rendering.\n *\n * Remark/rehype stages align with {@link createMarkdownProcessorInternal} intent\n * (GFM, directives, callouts, gated math/code/charts/sanitize). Rehype ordering\n * keeps the prior Mermaid-capable sequence so existing Node Mermaid snapshots stay stable.\n */\nexport function createMarkdownProcessorWithMermaidInternal(options?: InternalOptions) {\n const gates: MarkdownProcessorFeatureGates = options?.features ?? {\n math: true,\n code: true,\n codeHighlighting: true,\n charts: true,\n sanitize: true,\n };\n\n const fallbackToOriginalCodeBlock = (element: Element): Element => element;\n\n const processor = unified().use(remarkParse).use(remarkGfm).use(remarkDirective);\n\n if (gates.math) {\n processor.use(remarkMath);\n }\n\n processor.use(remarkHeadingIds).use(remarkCallouts);\n\n if (gates.code) {\n processor.use(remarkCodeBlockTitles);\n }\n\n processor.use(remarkRehype, { allowDangerousHtml: true }).use(rehypeRaw);\n\n if (gates.charts) {\n if (options?.emitDiagnostic) {\n processor.use(rehypeChartBlocksInternal, { emitDiagnostic: options.emitDiagnostic });\n } else {\n processor.use(rehypeChartBlocksInternal);\n }\n }\n\n processor.use(rehypeSlug).use(rehypeAutolinkHeadings, { behavior: 'wrap' });\n\n if (gates.code) {\n processor.use(rehypeCodeBlockTitles);\n }\n\n if (gates.math) {\n processor.use(rehypeKatex, { output: 'html' });\n }\n\n if (gates.code && gates.codeHighlighting) {\n processor.use(rehypeHighlight);\n }\n\n processor.use(rehypeMermaid, {\n strategy: 'inline-svg',\n errorFallback: fallbackToOriginalCodeBlock,\n });\n\n if (gates.sanitize) {\n processor.use(rehypeSanitize, schemaWithSvg);\n }\n\n if (gates.code && gates.codeHighlighting) {\n processor.use(rehypeCodeLineHighlights);\n }\n\n if (!options?.preserveHeadingCustomIdMarker) {\n processor.use(rehypeStripHeadingCustomIdMarker);\n }\n\n processor.use(rehypeCdnImagesInternal, options).use(rehypeStringify);\n\n return processor as unknown as Processor<MdastRoot, MdastRoot, HastRoot>;\n}\n","import { toText } from 'hast-util-to-text';\nimport { EXIT, visit } from 'unist-util-visit';\nimport type { MarkdownProcessorFeatureGates } from './createMarkdownProcessorInternal.js';\nimport { createMarkdownProcessorWithMermaidInternal } from './createMarkdownProcessorWithMermaidInternal.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 * Like {@link renderMarkdownDocumentInternal}, but uses the Mermaid inline-SVG pipeline.\n */\nexport async function renderMarkdownDocumentWithMermaidInternal(\n markdown: string,\n options?: RenderMarkdownOptions,\n pipelineFeatures?: MarkdownProcessorFeatureGates,\n): Promise<RenderMarkdownDocumentResult> {\n const collector = createDiagnosticCollector();\n const processor = createMarkdownProcessorWithMermaidInternal({\n ...options,\n emitDiagnostic: collector.emit,\n preserveHeadingCustomIdMarker: true,\n ...(pipelineFeatures !== undefined ? { features: pipelineFeatures } : {}),\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 { readFile } from 'node:fs/promises';\nimport { buildFeatherdownResult } from './internal/buildFeatherdownResult.js';\nimport { buildMetadataFromFrontmatter } from './internal/buildMetadataFromFrontmatter.js';\nimport { pickRenderMarkdownOptions, toProcessorGates } from './internal/featherdownParseHelpers.js';\nimport { parseFrontmatter } from './internal/parseFrontmatter.js';\nimport { renderMarkdownDocumentWithMermaidInternal } from './internal/renderMarkdownDocumentWithMermaidInternal.js';\nimport {\n mergeFeatherdownOptions,\n resolveFeatherdownOptions,\n} from './internal/resolveFeatherdownOptions.js';\nimport { throwIfStrictDiagnosticsViolated } from './internal/throwIfStrictDiagnosticsViolated.js';\nimport { Featherdown as BaseFeatherdown } from './featherdown.js';\nimport type { NodeFeatherdownOptions, NodeFeatherdownParseOptions } from './nodeTypes.js';\nimport type { FeatherdownOptions, FeatherdownResult } from './types.js';\n\nfunction stripMermaidForBase(options?: NodeFeatherdownOptions): FeatherdownOptions | undefined {\n if (!options) {\n return undefined;\n }\n const rest = { ...options };\n delete rest.mermaid;\n return Object.keys(rest).length > 0 ? (rest as FeatherdownOptions) : undefined;\n}\n\nfunction mergeNodeFeatherdownOptions(\n ctor?: NodeFeatherdownOptions,\n parse?: NodeFeatherdownParseOptions,\n): NodeFeatherdownOptions | undefined {\n const baseMerged = mergeFeatherdownOptions(stripMermaidForBase(ctor), stripMermaidForBase(parse));\n const mermaid =\n parse?.mermaid !== undefined ? parse.mermaid : ctor?.mermaid !== undefined ? ctor.mermaid : undefined;\n if (mermaid === undefined) {\n return baseMerged as NodeFeatherdownOptions | undefined;\n }\n return { ...(baseMerged ?? {}), mermaid };\n}\n\nfunction isMermaidSvgEnabled(merged?: NodeFeatherdownOptions): boolean {\n return merged?.mermaid !== undefined && merged.mermaid !== false;\n}\n\n/**\n * Node {@link Featherdown}: same {@link Featherdown.parse} behavior as the browser\n * entry when Mermaid SVG is off; delegates to the base class. With `mermaid: { render: \"svg\" }`,\n * uses the inline-SVG Mermaid pipeline and sets {@link FeatherdownResult.assets.features.mermaid}.\n */\nexport class Featherdown {\n private readonly base: BaseFeatherdown;\n private readonly ctorOptions: NodeFeatherdownOptions | undefined;\n\n constructor(options?: NodeFeatherdownOptions) {\n this.base = new BaseFeatherdown(stripMermaidForBase(options));\n this.ctorOptions = options;\n }\n\n async parse(markdown: string, parseOptions?: NodeFeatherdownParseOptions): Promise<FeatherdownResult> {\n const mergedNode = mergeNodeFeatherdownOptions(this.ctorOptions, parseOptions);\n if (!isMermaidSvgEnabled(mergedNode)) {\n return this.base.parse(markdown, stripMermaidForBase(mergedNode));\n }\n\n const mergedOptions = mergeFeatherdownOptions(stripMermaidForBase(this.ctorOptions), stripMermaidForBase(parseOptions));\n const resolvedOptions = resolveFeatherdownOptions(mergedOptions);\n const legacy = pickRenderMarkdownOptions(mergedOptions);\n\n const fm = parseFrontmatter(markdown, resolvedOptions.frontmatter);\n const metadata = buildMetadataFromFrontmatter(fm.frontmatter);\n const document = await renderMarkdownDocumentWithMermaidInternal(\n fm.body,\n legacy,\n toProcessorGates(resolvedOptions),\n );\n\n const result = buildFeatherdownResult({\n body: fm.body,\n frontmatter: fm.frontmatter,\n metadata,\n document,\n options: resolvedOptions,\n mermaidFeature: true,\n });\n throwIfStrictDiagnosticsViolated(resolvedOptions, result);\n return result;\n }\n\n async parseFile(path: string, parseOptions?: NodeFeatherdownParseOptions): Promise<FeatherdownResult> {\n const markdown = await readFile(path, 'utf8');\n return this.parse(markdown, parseOptions);\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 * @deprecated Prefer `new Featherdown({ mermaid: { render: \"svg\" } }).parse(markdown)` from `featherdown/node`.\n * This helper remains available for compatibility.\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\nexport { Featherdown } from './nodeFeatherdown.js';\nexport { FeatherdownDiagnosticsError } from './featherdownDiagnosticsError.js';\nexport type {\n NodeFeatherdownMermaidOptions,\n NodeFeatherdownOptions,\n NodeFeatherdownParseOptions,\n} from './nodeTypes.js';\n\n/**\n * Shared rendering options used by the Node Mermaid entrypoint.\n */\nexport type { RenderMarkdownOptions } from './types.js';\n"]}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared public type definitions for featherdown rendering APIs.
|
|
3
|
+
*
|
|
4
|
+
* This module documents option and diagnostic shapes used by browser-safe
|
|
5
|
+
* entrypoints.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Options for Markdown rendering and image URL rewriting.
|
|
9
|
+
*/
|
|
10
|
+
type RenderMarkdownOptions = {
|
|
11
|
+
/**
|
|
12
|
+
* Content kind used in generated manifest lookup keys (for example `post`).
|
|
13
|
+
*/
|
|
14
|
+
kind?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Content slug used in generated manifest lookup keys.
|
|
17
|
+
*/
|
|
18
|
+
slug?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Optional manifest mapping local or remote image paths to CDN URLs.
|
|
21
|
+
*/
|
|
22
|
+
manifest?: {
|
|
23
|
+
/**
|
|
24
|
+
* Mapping for local path keys such as `post/my-slug/images/logo.png`.
|
|
25
|
+
*/
|
|
26
|
+
map?: Record<string, {
|
|
27
|
+
url: string;
|
|
28
|
+
}>;
|
|
29
|
+
/**
|
|
30
|
+
* Mapping for remote source URLs that should be replaced.
|
|
31
|
+
*/
|
|
32
|
+
remote?: Record<string, {
|
|
33
|
+
url: string;
|
|
34
|
+
}>;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Non-fatal issue emitted during rendering.
|
|
39
|
+
*/
|
|
40
|
+
type RenderDiagnostic = {
|
|
41
|
+
/**
|
|
42
|
+
* Stable machine-readable code for the warning.
|
|
43
|
+
*/
|
|
44
|
+
code: string;
|
|
45
|
+
/**
|
|
46
|
+
* Human-readable warning text.
|
|
47
|
+
*/
|
|
48
|
+
message: string;
|
|
49
|
+
/**
|
|
50
|
+
* Diagnostic severity level.
|
|
51
|
+
*/
|
|
52
|
+
severity: 'warning';
|
|
53
|
+
/**
|
|
54
|
+
* Pipeline component that emitted the diagnostic.
|
|
55
|
+
*/
|
|
56
|
+
source: 'chart' | 'images';
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Heading entry extracted from final rendered document structure.
|
|
60
|
+
*/
|
|
61
|
+
type TocItem = {
|
|
62
|
+
/**
|
|
63
|
+
* Final heading level from 1 to 6.
|
|
64
|
+
*/
|
|
65
|
+
depth: number;
|
|
66
|
+
/**
|
|
67
|
+
* Final heading text content.
|
|
68
|
+
*/
|
|
69
|
+
text: string;
|
|
70
|
+
/**
|
|
71
|
+
* Final heading id used in rendered HTML.
|
|
72
|
+
*/
|
|
73
|
+
id: string;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Rich heading metadata extracted from final rendered document structure.
|
|
77
|
+
*/
|
|
78
|
+
type HeadingMetadata = {
|
|
79
|
+
/**
|
|
80
|
+
* Zero-based heading index in document order among included headings.
|
|
81
|
+
*/
|
|
82
|
+
index: number;
|
|
83
|
+
/**
|
|
84
|
+
* Final heading level from 1 to 6.
|
|
85
|
+
*/
|
|
86
|
+
depth: number;
|
|
87
|
+
/**
|
|
88
|
+
* Final heading text content.
|
|
89
|
+
*/
|
|
90
|
+
text: string;
|
|
91
|
+
/**
|
|
92
|
+
* Final heading id used in rendered HTML.
|
|
93
|
+
*/
|
|
94
|
+
id: string;
|
|
95
|
+
/**
|
|
96
|
+
* Whether the heading id comes from explicit `{#custom-id}` syntax.
|
|
97
|
+
*/
|
|
98
|
+
hasCustomId: boolean;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Full render output for publishing workflows.
|
|
102
|
+
*/
|
|
103
|
+
type RenderMarkdownDocumentResult = {
|
|
104
|
+
/**
|
|
105
|
+
* Sanitized rendered HTML.
|
|
106
|
+
*/
|
|
107
|
+
html: string;
|
|
108
|
+
/**
|
|
109
|
+
* Non-fatal render diagnostics.
|
|
110
|
+
*/
|
|
111
|
+
diagnostics: RenderDiagnostic[];
|
|
112
|
+
/**
|
|
113
|
+
* Table of contents extracted from rendered headings in document order.
|
|
114
|
+
* Entries are included only when a final heading id exists.
|
|
115
|
+
*/
|
|
116
|
+
toc: TocItem[];
|
|
117
|
+
/**
|
|
118
|
+
* Rich heading metadata in document order.
|
|
119
|
+
* Entries are included only when a final heading id exists.
|
|
120
|
+
*/
|
|
121
|
+
headings: HeadingMetadata[];
|
|
122
|
+
/**
|
|
123
|
+
* First meaningful plain-text excerpt from rendered `p`, `blockquote`,
|
|
124
|
+
* or `li` content, in document order. Returns `null` when no such content
|
|
125
|
+
* exists.
|
|
126
|
+
*/
|
|
127
|
+
excerpt: string | null;
|
|
128
|
+
/**
|
|
129
|
+
* Approximate plain-text word count derived from rendered document text.
|
|
130
|
+
*/
|
|
131
|
+
wordCount: number;
|
|
132
|
+
/**
|
|
133
|
+
* Estimated reading time in whole minutes using a simple words-per-minute
|
|
134
|
+
* heuristic. Returns 0 only when no readable text is present.
|
|
135
|
+
*/
|
|
136
|
+
estimatedReadingMinutes: number;
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Math rendering intent for {@link Featherdown}.
|
|
140
|
+
*/
|
|
141
|
+
type FeatherdownMathOptions = {
|
|
142
|
+
enabled?: boolean;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Code block pipeline intent for {@link Featherdown}.
|
|
146
|
+
*
|
|
147
|
+
* `lineNumbers` and `copyButton` are normalized for future global defaults; per-fence
|
|
148
|
+
* `showLineNumbers` / `showCopyButton` in Markdown are unchanged in this release.
|
|
149
|
+
*/
|
|
150
|
+
type FeatherdownCodeOptions = {
|
|
151
|
+
enabled?: boolean;
|
|
152
|
+
highlighting?: boolean;
|
|
153
|
+
lineNumbers?: boolean;
|
|
154
|
+
copyButton?: boolean;
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* Heading-related metadata intent for {@link Featherdown}. Slug and anchor HTML
|
|
158
|
+
* are still produced by the pipeline when enabled here; `toc` controls returned
|
|
159
|
+
* table-of-contents metadata only in this slice.
|
|
160
|
+
*/
|
|
161
|
+
type FeatherdownHeadingOptions = {
|
|
162
|
+
slugs?: boolean;
|
|
163
|
+
anchors?: boolean;
|
|
164
|
+
toc?: boolean;
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* Publishing metadata fields returned from {@link Featherdown.parse}.
|
|
168
|
+
*/
|
|
169
|
+
type FeatherdownPublishingOptions = {
|
|
170
|
+
excerpt?: boolean;
|
|
171
|
+
wordCount?: boolean;
|
|
172
|
+
readingTime?: boolean;
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* Well-known document metadata derived from YAML front matter when present.
|
|
176
|
+
*/
|
|
177
|
+
type FeatherdownMetadata = {
|
|
178
|
+
title?: string;
|
|
179
|
+
description?: string;
|
|
180
|
+
date?: string;
|
|
181
|
+
updated?: string;
|
|
182
|
+
status?: string;
|
|
183
|
+
tags?: string[];
|
|
184
|
+
author?: string;
|
|
185
|
+
};
|
|
186
|
+
/**
|
|
187
|
+
* Options for {@link Featherdown} construction: legacy manifest fields plus
|
|
188
|
+
* user-intent toggles.
|
|
189
|
+
*/
|
|
190
|
+
type FeatherdownOptions = RenderMarkdownOptions & {
|
|
191
|
+
/**
|
|
192
|
+
* When `true` or `"auto"`, parse leading YAML front matter when present and
|
|
193
|
+
* render only the body. When `false` or omitted, pass the full string through.
|
|
194
|
+
*/
|
|
195
|
+
frontmatter?: false | true | 'auto';
|
|
196
|
+
math?: boolean | FeatherdownMathOptions;
|
|
197
|
+
code?: boolean | FeatherdownCodeOptions;
|
|
198
|
+
sanitize?: boolean;
|
|
199
|
+
/**
|
|
200
|
+
* `false`: hide diagnostics on the result (`[]`). `true` and `"warn"`: collect
|
|
201
|
+
* diagnostics, never throw. `"strict"`: collect diagnostics; throw
|
|
202
|
+
* `FeatherdownDiagnosticsError` if any were produced.
|
|
203
|
+
*/
|
|
204
|
+
diagnostics?: boolean | 'warn' | 'strict';
|
|
205
|
+
charts?: boolean;
|
|
206
|
+
headings?: boolean | FeatherdownHeadingOptions;
|
|
207
|
+
publishing?: boolean | FeatherdownPublishingOptions;
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* Per-call options for {@link Featherdown.parse}. Same shape as {@link FeatherdownOptions}.
|
|
211
|
+
*/
|
|
212
|
+
type FeatherdownParseOptions = FeatherdownOptions;
|
|
213
|
+
/**
|
|
214
|
+
* Stable public contract for {@link Featherdown.parse} output: rendered document
|
|
215
|
+
* fields plus `body`, placeholders, `stats`, and `assets`. `excerpt` is always
|
|
216
|
+
* `string | null` after publishing gates (may be `null` when excerpt is disabled
|
|
217
|
+
* or when the document has no suitable excerpt).
|
|
218
|
+
*/
|
|
219
|
+
type FeatherdownResult = RenderMarkdownDocumentResult & {
|
|
220
|
+
excerpt: string | null;
|
|
221
|
+
/**
|
|
222
|
+
* Markdown body after front matter is removed when front matter parsing is enabled
|
|
223
|
+
* and a valid block exists; otherwise the full input string.
|
|
224
|
+
*/
|
|
225
|
+
body: string;
|
|
226
|
+
/**
|
|
227
|
+
* Parsed YAML front matter object, or `{}` when absent or when parsing is disabled.
|
|
228
|
+
*/
|
|
229
|
+
frontmatter: Record<string, unknown>;
|
|
230
|
+
/**
|
|
231
|
+
* Typed subset of front matter for common publishing fields.
|
|
232
|
+
*/
|
|
233
|
+
metadata: FeatherdownMetadata;
|
|
234
|
+
stats: {
|
|
235
|
+
wordCount: number;
|
|
236
|
+
readingTimeMinutes: number;
|
|
237
|
+
};
|
|
238
|
+
assets: {
|
|
239
|
+
styles: string[];
|
|
240
|
+
scripts: string[];
|
|
241
|
+
features: {
|
|
242
|
+
math: boolean;
|
|
243
|
+
code: boolean;
|
|
244
|
+
charts: boolean;
|
|
245
|
+
mermaid: boolean;
|
|
246
|
+
};
|
|
247
|
+
};
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
export type { FeatherdownResult as F, HeadingMetadata as H, RenderDiagnostic as R, TocItem as T, FeatherdownOptions as a, RenderMarkdownOptions as b, FeatherdownParseOptions as c, RenderMarkdownDocumentResult as d, FeatherdownCodeOptions as e, FeatherdownHeadingOptions as f, FeatherdownMathOptions as g, FeatherdownMetadata as h, FeatherdownPublishingOptions as i };
|
package/package.json
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "featherdown",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Markdown-to-HTML pipeline with sanitization, diagnostics, and optional Node Mermaid rendering.",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"sideEffects":
|
|
6
|
+
"sideEffects": [
|
|
7
|
+
"*.css",
|
|
8
|
+
"styles/**/*.css"
|
|
9
|
+
],
|
|
7
10
|
"files": [
|
|
8
|
-
"dist"
|
|
11
|
+
"dist",
|
|
12
|
+
"styles.css",
|
|
13
|
+
"styles"
|
|
9
14
|
],
|
|
10
15
|
"main": "./dist/index.js",
|
|
11
16
|
"types": "./dist/index.d.ts",
|
|
@@ -20,6 +25,16 @@
|
|
|
20
25
|
"import": "./dist/node.js",
|
|
21
26
|
"default": "./dist/node.js"
|
|
22
27
|
},
|
|
28
|
+
"./advanced": {
|
|
29
|
+
"types": "./dist/advanced.d.ts",
|
|
30
|
+
"import": "./dist/advanced.js",
|
|
31
|
+
"default": "./dist/advanced.js"
|
|
32
|
+
},
|
|
33
|
+
"./styles.css": "./styles.css",
|
|
34
|
+
"./styles/base.css": "./styles/base.css",
|
|
35
|
+
"./styles/katex.css": "./styles/katex.css",
|
|
36
|
+
"./styles/code.css": "./styles/code.css",
|
|
37
|
+
"./styles/highlight.css": "./styles/highlight.css",
|
|
23
38
|
"./package.json": "./package.json"
|
|
24
39
|
},
|
|
25
40
|
"scripts": {
|
|
@@ -30,7 +45,11 @@
|
|
|
30
45
|
"typecheck": "tsc --noEmit",
|
|
31
46
|
"test:exports": "npm run build && node ./test/exports.smoke.mjs",
|
|
32
47
|
"verify-release-version": "node ./scripts/verify-release-version.mjs",
|
|
33
|
-
"prepublishOnly": "npm run lint && npm run typecheck && npm test && npm run test:exports"
|
|
48
|
+
"prepublishOnly": "npm run lint && npm run typecheck && npm test && npm run test:exports",
|
|
49
|
+
"site:install": "npm install --prefix site",
|
|
50
|
+
"site:dev": "npm run dev --prefix site",
|
|
51
|
+
"site:build": "npm run build && npm run build --prefix site",
|
|
52
|
+
"site:preview": "npm run preview --prefix site"
|
|
34
53
|
},
|
|
35
54
|
"keywords": [
|
|
36
55
|
"markdown",
|
|
@@ -68,6 +87,7 @@
|
|
|
68
87
|
"devDependencies": {
|
|
69
88
|
"@eslint/js": "^9.18.0",
|
|
70
89
|
"@types/js-yaml": "^4.0.9",
|
|
90
|
+
"@types/node": "^22.19.17",
|
|
71
91
|
"eslint": "^9.18.0",
|
|
72
92
|
"playwright": "^1.59.1",
|
|
73
93
|
"tsup": "^8.3.5",
|
|
@@ -77,7 +97,9 @@
|
|
|
77
97
|
},
|
|
78
98
|
"dependencies": {
|
|
79
99
|
"hast-util-to-text": "^4.0.2",
|
|
100
|
+
"highlight.js": "^11.11.0",
|
|
80
101
|
"js-yaml": "^4.1.1",
|
|
102
|
+
"katex": "^0.16.0",
|
|
81
103
|
"lowlight": "^3.3.0",
|
|
82
104
|
"rehype-autolink-headings": "^7.1.0",
|
|
83
105
|
"rehype-highlight": "^7.0.2",
|
|
@@ -87,6 +109,7 @@
|
|
|
87
109
|
"rehype-sanitize": "^6.0.0",
|
|
88
110
|
"rehype-slug": "^6.0.0",
|
|
89
111
|
"rehype-stringify": "^10.0.1",
|
|
112
|
+
"remark-directive": "^4.0.0",
|
|
90
113
|
"remark-gfm": "^4.0.1",
|
|
91
114
|
"remark-math": "^6.0.0",
|
|
92
115
|
"remark-parse": "^11.0.0",
|