featherdown 0.1.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/LICENSE +21 -0
- package/README.md +173 -0
- package/dist/chunk-CVZY5VWM.js +243 -0
- package/dist/chunk-CVZY5VWM.js.map +1 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +99 -0
- package/dist/index.js.map +1 -0
- package/dist/node.d.ts +5 -0
- package/dist/node.js +29 -0
- package/dist/node.js.map +1 -0
- package/dist/types-DlRranpy.d.ts +20 -0
- package/package.json +76 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# featherdown
|
|
2
|
+
|
|
3
|
+
`featherdown` is a TypeScript package for converting Markdown into sanitized HTML for publishing workflows.
|
|
4
|
+
|
|
5
|
+
It provides a browser-safe default entry and a separate Node-only Mermaid subpath.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install featherdown
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Node.js 18+ is required.
|
|
14
|
+
|
|
15
|
+
If you use Mermaid rendering from `featherdown/node`, install Playwright Chromium:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npx playwright install chromium
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Quick Start (Browser-Safe Default Entry)
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { renderMarkdownToHtml } from 'featherdown';
|
|
25
|
+
|
|
26
|
+
const html = await renderMarkdownToHtml('## Hello **world**');
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The default entry does not include Mermaid rendering.
|
|
30
|
+
|
|
31
|
+
## HTML + Diagnostics
|
|
32
|
+
|
|
33
|
+
Use `renderMarkdown` to get both HTML and non-fatal warnings.
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { renderMarkdown } from 'featherdown';
|
|
37
|
+
|
|
38
|
+
const { html, diagnostics } = await renderMarkdown(
|
|
39
|
+
'```chart-line\nnot json\n```',
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
console.log(html);
|
|
43
|
+
console.log(diagnostics);
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Processor Factory Usage
|
|
47
|
+
|
|
48
|
+
Use `createMarkdownProcessor` when you want direct control of processing calls.
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
import { createMarkdownProcessor } from 'featherdown';
|
|
52
|
+
|
|
53
|
+
const processor = createMarkdownProcessor();
|
|
54
|
+
const file = await processor.process('# Hello');
|
|
55
|
+
const html = String(file);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Direct Plugin Usage
|
|
59
|
+
|
|
60
|
+
The package exports focused plugins for custom unified pipelines.
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
import { unified } from 'unified';
|
|
64
|
+
import remarkParse from 'remark-parse';
|
|
65
|
+
import remarkRehype from 'remark-rehype';
|
|
66
|
+
import rehypeStringify from 'rehype-stringify';
|
|
67
|
+
import { rehypeChartBlocks, rehypeCdnImages } from 'featherdown';
|
|
68
|
+
|
|
69
|
+
const html = String(
|
|
70
|
+
await unified()
|
|
71
|
+
.use(remarkParse)
|
|
72
|
+
.use(remarkRehype)
|
|
73
|
+
.use(rehypeChartBlocks)
|
|
74
|
+
.use(rehypeCdnImages, { kind: 'post', slug: 'hello-world' })
|
|
75
|
+
.use(rehypeStringify)
|
|
76
|
+
.process(markdown),
|
|
77
|
+
);
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Image Rewriting Example
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import { renderMarkdownToHtml } from 'featherdown';
|
|
84
|
+
|
|
85
|
+
const html = await renderMarkdownToHtml('', {
|
|
86
|
+
kind: 'post',
|
|
87
|
+
slug: 'hello-world',
|
|
88
|
+
manifest: {
|
|
89
|
+
map: {
|
|
90
|
+
'post/hello-world/images/logo.png': {
|
|
91
|
+
url: 'https://cdn.example.com/blog/hello-world/logo.hash.png',
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Chart Placeholder Example
|
|
99
|
+
|
|
100
|
+
Valid JSON in supported `chart-*` fences becomes a placeholder mount node:
|
|
101
|
+
|
|
102
|
+
````md
|
|
103
|
+
```chart-line
|
|
104
|
+
{"labels":["a"],"datasets":[]}
|
|
105
|
+
```
|
|
106
|
+
````
|
|
107
|
+
|
|
108
|
+
Rendered HTML shape:
|
|
109
|
+
|
|
110
|
+
```html
|
|
111
|
+
<div
|
|
112
|
+
class="chart-mount"
|
|
113
|
+
data-chart="line"
|
|
114
|
+
data-chart-data="{"labels":["a"],"datasets":[]}"
|
|
115
|
+
></div>
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
This package does not bundle a chart runtime; it only emits mount markup.
|
|
119
|
+
|
|
120
|
+
## Node-Only Mermaid Subpath
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
import { renderMarkdownToHtmlWithMermaid } from 'featherdown/node';
|
|
124
|
+
|
|
125
|
+
const html = await renderMarkdownToHtmlWithMermaid(
|
|
126
|
+
'```mermaid\ngraph TD; A-->B;\n```',
|
|
127
|
+
);
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Use this entry in Node publishing environments where Playwright + Mermaid dependencies are acceptable.
|
|
131
|
+
|
|
132
|
+
## CSS / Asset Expectations
|
|
133
|
+
|
|
134
|
+
- KaTeX CSS is required for correct math styling.
|
|
135
|
+
- Syntax highlighting output includes highlight.js classes; include matching styles in your app.
|
|
136
|
+
- Mermaid rendering from `featherdown/node` depends on Playwright Chromium availability.
|
|
137
|
+
|
|
138
|
+
## Security and Trust Guidance
|
|
139
|
+
|
|
140
|
+
- Input is sanitized with `rehype-sanitize`; scripts are removed.
|
|
141
|
+
- Treat Markdown as untrusted by default unless your ingestion workflow guarantees trusted content.
|
|
142
|
+
- Review and test your final HTML integration, including any custom render-time plugins you add.
|
|
143
|
+
|
|
144
|
+
## Public API
|
|
145
|
+
|
|
146
|
+
Default entry (`featherdown`):
|
|
147
|
+
|
|
148
|
+
- `renderMarkdownToHtml`
|
|
149
|
+
- `renderMarkdown`
|
|
150
|
+
- `createMarkdownProcessor`
|
|
151
|
+
- `rehypeChartBlocks`
|
|
152
|
+
- `rehypeCdnImages`
|
|
153
|
+
- `parseMarkdownFile`
|
|
154
|
+
- `libraryId`
|
|
155
|
+
|
|
156
|
+
Node-only entry (`featherdown/node`):
|
|
157
|
+
|
|
158
|
+
- `renderMarkdownToHtmlWithMermaid`
|
|
159
|
+
|
|
160
|
+
## Scripts
|
|
161
|
+
|
|
162
|
+
| Script | Description |
|
|
163
|
+
|---|---|
|
|
164
|
+
| `npm run build` | Build ESM artifacts in `dist/` |
|
|
165
|
+
| `npm test` | Run Vitest once |
|
|
166
|
+
| `npm run test:watch` | Run Vitest in watch mode |
|
|
167
|
+
| `npm run lint` | Run ESLint |
|
|
168
|
+
| `npm run typecheck` | Run TypeScript checks |
|
|
169
|
+
| `npm run test:exports` | Build and run export smoke checks |
|
|
170
|
+
|
|
171
|
+
## License
|
|
172
|
+
|
|
173
|
+
MIT. See [LICENSE](./LICENSE).
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { toText } from 'hast-util-to-text';
|
|
2
|
+
import { visit } from 'unist-util-visit';
|
|
3
|
+
import { defaultSchema } from 'rehype-sanitize';
|
|
4
|
+
|
|
5
|
+
// src/internal/rehypeChartBlocks.ts
|
|
6
|
+
|
|
7
|
+
// src/internal/chartTypes.ts
|
|
8
|
+
var CHART_BLOCK_TYPES = [
|
|
9
|
+
"line",
|
|
10
|
+
"bar",
|
|
11
|
+
"radar",
|
|
12
|
+
"doughnut",
|
|
13
|
+
"pie",
|
|
14
|
+
"polarArea",
|
|
15
|
+
"bubble",
|
|
16
|
+
"scatter"
|
|
17
|
+
];
|
|
18
|
+
var CHART_BLOCK_TYPE_SET = new Set(CHART_BLOCK_TYPES);
|
|
19
|
+
|
|
20
|
+
// src/internal/rehypeChartBlocks.ts
|
|
21
|
+
var LANG_PREFIX = "language-chart-";
|
|
22
|
+
function chartTypeFromClassName(className) {
|
|
23
|
+
const list = Array.isArray(className) ? className : typeof className === "string" ? [className] : [];
|
|
24
|
+
for (const c of list) {
|
|
25
|
+
if (typeof c === "string" && c.startsWith(LANG_PREFIX)) {
|
|
26
|
+
return c.slice(LANG_PREFIX.length);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return void 0;
|
|
30
|
+
}
|
|
31
|
+
var rehypeChartBlocks = function rehypeChartBlocks2(options) {
|
|
32
|
+
const emitDiagnostic = options?.emitDiagnostic;
|
|
33
|
+
return (tree) => {
|
|
34
|
+
visit(tree, "element", (node, index, parent) => {
|
|
35
|
+
if (node.tagName !== "pre") return;
|
|
36
|
+
if (!parent || typeof index !== "number") return;
|
|
37
|
+
const code = node.children[0];
|
|
38
|
+
if (!code || code.type !== "element" || code.tagName !== "code") return;
|
|
39
|
+
const chartType = chartTypeFromClassName(code.properties.className);
|
|
40
|
+
if (!chartType || !CHART_BLOCK_TYPE_SET.has(chartType)) return;
|
|
41
|
+
const raw = toText(code, { whitespace: "pre" }).trim();
|
|
42
|
+
try {
|
|
43
|
+
const parsed = JSON.parse(raw);
|
|
44
|
+
const jsonStr = JSON.stringify(parsed);
|
|
45
|
+
const div = {
|
|
46
|
+
type: "element",
|
|
47
|
+
tagName: "div",
|
|
48
|
+
properties: {
|
|
49
|
+
className: ["chart-mount"],
|
|
50
|
+
dataChart: chartType,
|
|
51
|
+
dataChartData: jsonStr
|
|
52
|
+
},
|
|
53
|
+
children: []
|
|
54
|
+
};
|
|
55
|
+
parent.children[index] = div;
|
|
56
|
+
} catch {
|
|
57
|
+
emitDiagnostic?.({
|
|
58
|
+
code: "chart.invalid_json",
|
|
59
|
+
message: `Chart JSON could not be parsed for type "${chartType}".`,
|
|
60
|
+
severity: "warning",
|
|
61
|
+
source: "chart"
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
var rehypeChartBlocks_default = rehypeChartBlocks;
|
|
68
|
+
var REMOTE_SRC_PATTERN = /^(https?:\/\/|data:|blob:)/;
|
|
69
|
+
function getClassList(className) {
|
|
70
|
+
if (Array.isArray(className)) {
|
|
71
|
+
return className.filter((value) => typeof value === "string");
|
|
72
|
+
}
|
|
73
|
+
if (typeof className === "string") {
|
|
74
|
+
return [className];
|
|
75
|
+
}
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
function ensureInlineClass(node) {
|
|
79
|
+
const classes = getClassList(node.properties.className);
|
|
80
|
+
if (!classes.includes("markdown-inline-img")) {
|
|
81
|
+
classes.push("markdown-inline-img");
|
|
82
|
+
}
|
|
83
|
+
node.properties.className = classes;
|
|
84
|
+
}
|
|
85
|
+
function rehypeCdnImages(options) {
|
|
86
|
+
const kind = options?.kind;
|
|
87
|
+
const slug = options?.slug;
|
|
88
|
+
const map = options?.manifest?.map;
|
|
89
|
+
const remote = options?.manifest?.remote;
|
|
90
|
+
const emitDiagnostic = options?.emitDiagnostic;
|
|
91
|
+
return (tree) => {
|
|
92
|
+
visit(tree, "element", (node) => {
|
|
93
|
+
if (node.tagName !== "img") return;
|
|
94
|
+
ensureInlineClass(node);
|
|
95
|
+
if (!kind || !slug) return;
|
|
96
|
+
const src = node.properties.src;
|
|
97
|
+
if (typeof src !== "string") return;
|
|
98
|
+
if (REMOTE_SRC_PATTERN.test(src)) {
|
|
99
|
+
const nextSrc2 = remote?.[src]?.url;
|
|
100
|
+
if (nextSrc2) node.properties.src = nextSrc2;
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (src.startsWith("/")) return;
|
|
104
|
+
const cleanPath = src.replace(/^\.\/+/, "");
|
|
105
|
+
const key = `${kind}/${slug}/${cleanPath}`;
|
|
106
|
+
const nextSrc = map?.[key]?.url;
|
|
107
|
+
if (nextSrc) {
|
|
108
|
+
node.properties.src = nextSrc;
|
|
109
|
+
} else {
|
|
110
|
+
emitDiagnostic?.({
|
|
111
|
+
code: "images.manifest_miss",
|
|
112
|
+
message: `No manifest entry found for "${key}".`,
|
|
113
|
+
severity: "warning",
|
|
114
|
+
source: "images"
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
var TRAILING_ID = /\s+\{#([\w-]+)\}\s*$/;
|
|
121
|
+
function remarkHeadingIds() {
|
|
122
|
+
return function(tree) {
|
|
123
|
+
visit(tree, "heading", (node) => {
|
|
124
|
+
const last = node.children[node.children.length - 1];
|
|
125
|
+
if (!last || last.type !== "text") return;
|
|
126
|
+
const match = TRAILING_ID.exec(last.value);
|
|
127
|
+
if (!match?.[1]) return;
|
|
128
|
+
if (!node.data) node.data = {};
|
|
129
|
+
if (!node.data.hProperties) node.data.hProperties = {};
|
|
130
|
+
const id = match[1];
|
|
131
|
+
const data = node.data;
|
|
132
|
+
data.id = id;
|
|
133
|
+
data.hProperties.id = id;
|
|
134
|
+
last.value = last.value.slice(0, match.index).replace(/\s+$/, "");
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
var baseAttrs = defaultSchema.attributes ?? {};
|
|
139
|
+
var baseStar = baseAttrs["*"] ?? [];
|
|
140
|
+
var baseSpan = baseAttrs.span ?? [];
|
|
141
|
+
var baseDiv = baseAttrs.div ?? [];
|
|
142
|
+
var baseTags = defaultSchema.tagNames ?? [];
|
|
143
|
+
var markdownSanitizeSchema = {
|
|
144
|
+
...defaultSchema,
|
|
145
|
+
attributes: {
|
|
146
|
+
...baseAttrs,
|
|
147
|
+
"*": [...baseStar, "className"],
|
|
148
|
+
span: [...baseSpan, "style"],
|
|
149
|
+
div: [
|
|
150
|
+
...baseDiv,
|
|
151
|
+
["className", "chart-mount"],
|
|
152
|
+
["dataChart", ...CHART_BLOCK_TYPES],
|
|
153
|
+
"dataChartData"
|
|
154
|
+
]
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
var svgTags = [
|
|
158
|
+
"svg",
|
|
159
|
+
"g",
|
|
160
|
+
"path",
|
|
161
|
+
"marker",
|
|
162
|
+
"rect",
|
|
163
|
+
"circle",
|
|
164
|
+
"line",
|
|
165
|
+
"polygon",
|
|
166
|
+
"text",
|
|
167
|
+
"tspan",
|
|
168
|
+
"style",
|
|
169
|
+
"foreignObject",
|
|
170
|
+
"defs",
|
|
171
|
+
"symbol"
|
|
172
|
+
];
|
|
173
|
+
var svgSharedAttributes = [
|
|
174
|
+
"style",
|
|
175
|
+
"transform",
|
|
176
|
+
"fill",
|
|
177
|
+
"stroke",
|
|
178
|
+
"strokeWidth",
|
|
179
|
+
"strokeDasharray",
|
|
180
|
+
"id",
|
|
181
|
+
"className"
|
|
182
|
+
];
|
|
183
|
+
var schemaWithSvg = {
|
|
184
|
+
...markdownSanitizeSchema,
|
|
185
|
+
tagNames: [...baseTags, ...svgTags],
|
|
186
|
+
attributes: {
|
|
187
|
+
...markdownSanitizeSchema.attributes ?? {},
|
|
188
|
+
div: [
|
|
189
|
+
...baseDiv,
|
|
190
|
+
"style",
|
|
191
|
+
"xmlns",
|
|
192
|
+
["className", "chart-mount"],
|
|
193
|
+
["dataChart", ...CHART_BLOCK_TYPES],
|
|
194
|
+
"dataChartData"
|
|
195
|
+
],
|
|
196
|
+
svg: [
|
|
197
|
+
...svgSharedAttributes,
|
|
198
|
+
"ariaRoleDescription",
|
|
199
|
+
"role",
|
|
200
|
+
"viewBox",
|
|
201
|
+
"width",
|
|
202
|
+
"xmlns"
|
|
203
|
+
],
|
|
204
|
+
g: [
|
|
205
|
+
...svgSharedAttributes,
|
|
206
|
+
"dataId",
|
|
207
|
+
"dataNode"
|
|
208
|
+
],
|
|
209
|
+
path: [...svgSharedAttributes, "d", "markerEnd"],
|
|
210
|
+
marker: [
|
|
211
|
+
...svgSharedAttributes,
|
|
212
|
+
"markerHeight",
|
|
213
|
+
"markerUnits",
|
|
214
|
+
"markerWidth",
|
|
215
|
+
"orient",
|
|
216
|
+
"refX",
|
|
217
|
+
"refY",
|
|
218
|
+
"viewBox"
|
|
219
|
+
],
|
|
220
|
+
rect: [...svgSharedAttributes, "height", "rx", "ry", "width", "x", "y", "name"],
|
|
221
|
+
circle: [...svgSharedAttributes, "cx", "cy", "r"],
|
|
222
|
+
line: [...svgSharedAttributes, "markerEnd", "x1", "x2", "y1", "y2"],
|
|
223
|
+
polygon: [...svgSharedAttributes, "points"],
|
|
224
|
+
text: [
|
|
225
|
+
...svgSharedAttributes,
|
|
226
|
+
"alignmentBaseline",
|
|
227
|
+
"dominantBaseline",
|
|
228
|
+
"dy",
|
|
229
|
+
"textAnchor",
|
|
230
|
+
"x",
|
|
231
|
+
"y"
|
|
232
|
+
],
|
|
233
|
+
tspan: [...svgSharedAttributes, "dy", "x"],
|
|
234
|
+
foreignObject: ["height", "width"],
|
|
235
|
+
symbol: ["clipRule", "fillRule", "height", "id", "width"],
|
|
236
|
+
defs: [],
|
|
237
|
+
style: []
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
export { markdownSanitizeSchema, rehypeCdnImages, rehypeChartBlocks_default, remarkHeadingIds, schemaWithSvg };
|
|
242
|
+
//# sourceMappingURL=chunk-CVZY5VWM.js.map
|
|
243
|
+
//# sourceMappingURL=chunk-CVZY5VWM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internal/chartTypes.ts","../src/internal/rehypeChartBlocks.ts","../src/internal/rehypeCdnImages.ts","../src/internal/headingIdsRemark.ts","../src/internal/sanitizeSchema.ts"],"names":["rehypeChartBlocks","visit","nextSrc"],"mappings":";;;;;;;AACO,IAAM,iBAAA,GAAoB;AAAA,EAC/B,MAAA;AAAA,EACA,KAAA;AAAA,EACA,OAAA;AAAA,EACA,UAAA;AAAA,EACA,KAAA;AAAA,EACA,WAAA;AAAA,EACA,QAAA;AAAA,EACA;AACF,CAAA;AAEO,IAAM,oBAAA,GAA4C,IAAI,GAAA,CAAI,iBAAiB,CAAA;;;ACLlF,IAAM,WAAA,GAAc,iBAAA;AAEpB,SAAS,uBAAuB,SAAA,EAAwC;AACtE,EAAA,MAAM,IAAA,GAAO,KAAA,CAAM,OAAA,CAAQ,SAAS,CAAA,GAChC,SAAA,GACA,OAAO,SAAA,KAAc,QAAA,GACnB,CAAC,SAAS,CAAA,GACV,EAAC;AACP,EAAA,KAAA,MAAW,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mBAAA,EAAqB,MAAM,GAAG,CAAA;AAAA,IACzC,aAAA,EAAe,CAAC,QAAA,EAAU,OAAO,CAAA;AAAA,IACjC,QAAQ,CAAC,UAAA,EAAY,UAAA,EAAY,QAAA,EAAU,MAAM,OAAO,CAAA;AAAA,IACxD,MAAM,EAAC;AAAA,IACP,OAAO;AAAC;AAEZ","file":"chunk-CVZY5VWM.js","sourcesContent":["/** Supported `language-chart-<type>` fence identifiers for chart placeholder blocks. */\nexport const CHART_BLOCK_TYPES = [\n 'line',\n 'bar',\n 'radar',\n 'doughnut',\n 'pie',\n 'polarArea',\n 'bubble',\n 'scatter',\n] as const;\n\nexport const CHART_BLOCK_TYPE_SET: ReadonlySet<string> = new Set(CHART_BLOCK_TYPES);\n","import { toText } from 'hast-util-to-text';\nimport type { Element, Root } from 'hast';\nimport { visit } from 'unist-util-visit';\nimport type { Plugin } from 'unified';\nimport { CHART_BLOCK_TYPE_SET } from './chartTypes.js';\nimport type { DiagnosticEmitter } from './diagnostics.js';\n\nconst LANG_PREFIX = 'language-chart-';\n\nfunction chartTypeFromClassName(className: unknown): string | undefined {\n const list = Array.isArray(className)\n ? className\n : typeof className === 'string'\n ? [className]\n : [];\n for (const c of list) {\n if (typeof c === 'string' && c.startsWith(LANG_PREFIX)) {\n return c.slice(LANG_PREFIX.length);\n }\n }\n return undefined;\n}\n\n/**\n * Turns ` ```chart-<type> ` fenced JSON into a mount placeholder `div`.\n * Invalid JSON leaves the original `<pre><code>` unchanged.\n */\nconst rehypeChartBlocks: Plugin<\n [{ emitDiagnostic?: DiagnosticEmitter }?],\n Root\n> = function rehypeChartBlocks(options) {\n const emitDiagnostic = options?.emitDiagnostic;\n return (tree): undefined => {\n visit(tree, 'element', (node, index, parent) => {\n if (node.tagName !== 'pre') return;\n if (!parent || typeof index !== 'number') return;\n const code = node.children[0];\n if (!code || code.type !== 'element' || code.tagName !== 'code') return;\n\n const chartType = chartTypeFromClassName(code.properties.className);\n if (!chartType || !CHART_BLOCK_TYPE_SET.has(chartType)) return;\n\n const raw = toText(code, { whitespace: 'pre' }).trim();\n try {\n const parsed: unknown = JSON.parse(raw);\n const jsonStr = JSON.stringify(parsed);\n const div: Element = {\n type: 'element',\n tagName: 'div',\n properties: {\n className: ['chart-mount'],\n dataChart: chartType,\n dataChartData: jsonStr,\n },\n children: [],\n };\n parent.children[index] = div;\n } catch {\n emitDiagnostic?.({\n code: 'chart.invalid_json',\n message: `Chart JSON could not be parsed for type \"${chartType}\".`,\n severity: 'warning',\n source: 'chart',\n });\n /* keep original pre/code */\n }\n });\n };\n};\n\nexport default rehypeChartBlocks;\n","import type { Element, Root } from 'hast';\nimport { visit } from 'unist-util-visit';\nimport type { DiagnosticEmitter } from './diagnostics.js';\n\ntype ManifestEntry = { url: string };\n\ntype RehypeCdnImagesOptions = {\n kind?: string;\n slug?: string;\n manifest?: {\n map?: Record<string, ManifestEntry>;\n remote?: Record<string, ManifestEntry>;\n };\n emitDiagnostic?: DiagnosticEmitter;\n};\n\nconst REMOTE_SRC_PATTERN = /^(https?:\\/\\/|data:|blob:)/;\n\nfunction getClassList(className: unknown): string[] {\n if (Array.isArray(className)) {\n return className.filter((value): value is string => typeof value === 'string');\n }\n if (typeof className === 'string') {\n return [className];\n }\n return [];\n}\n\nfunction ensureInlineClass(node: Element): void {\n const classes = getClassList(node.properties.className);\n if (!classes.includes('markdown-inline-img')) {\n classes.push('markdown-inline-img');\n }\n node.properties.className = classes;\n}\n\nexport default function rehypeCdnImages(options?: RehypeCdnImagesOptions) {\n const kind = options?.kind;\n const slug = options?.slug;\n const map = options?.manifest?.map;\n const remote = options?.manifest?.remote;\n const emitDiagnostic = options?.emitDiagnostic;\n\n return (tree: Root): undefined => {\n visit(tree, 'element', (node) => {\n if (node.tagName !== 'img') return;\n\n ensureInlineClass(node);\n\n if (!kind || !slug) return;\n\n const src = node.properties.src;\n if (typeof src !== 'string') return;\n\n if (REMOTE_SRC_PATTERN.test(src)) {\n const nextSrc = remote?.[src]?.url;\n if (nextSrc) node.properties.src = nextSrc;\n return;\n }\n\n if (src.startsWith('/')) return;\n\n const cleanPath = src.replace(/^\\.\\/+/, '');\n const key = `${kind}/${slug}/${cleanPath}`;\n const nextSrc = map?.[key]?.url;\n if (nextSrc) {\n node.properties.src = nextSrc;\n } else {\n emitDiagnostic?.({\n code: 'images.manifest_miss',\n message: `No manifest entry found for \"${key}\".`,\n severity: 'warning',\n source: 'images',\n });\n }\n });\n };\n}\n","import type { Heading, Root } from 'mdast';\nimport { visit } from 'unist-util-visit';\n\nconst TRAILING_ID = /\\s+\\{#([\\w-]+)\\}\\s*$/;\n\n/**\n * Remark plugin: strips ` {#custom-id}` from heading text and sets `hProperties.id`\n * so remark-rehype puts `id` on the heading in hast before `rehype-sanitize`.\n * `rehype-slug` runs after sanitize and only fills in missing ids, so it does not\n * overwrite these (see `!node.properties.id` in rehype-slug).\n */\nexport function remarkHeadingIds(): (tree: Root) => undefined {\n return function (tree: Root): undefined {\n visit(tree, 'heading', (node: Heading) => {\n const last = node.children[node.children.length - 1];\n if (!last || last.type !== 'text') return;\n\n const match = TRAILING_ID.exec(last.value);\n if (!match?.[1]) return;\n\n if (!node.data) node.data = {};\n if (!node.data.hProperties) node.data.hProperties = {};\n const id = match[1];\n const data = node.data as typeof node.data & {\n id?: string;\n hProperties: Record<string, string | undefined>;\n };\n data.id = id;\n data.hProperties.id = id;\n\n last.value = last.value.slice(0, match.index).replace(/\\s+$/, '');\n });\n };\n}\n","import type { Schema } from 'hast-util-sanitize';\nimport { defaultSchema } from 'rehype-sanitize';\nimport { CHART_BLOCK_TYPES } from './chartTypes.js';\n\n/**\n * Extends the GitHub-style default sanitizer for this pipeline:\n *\n * - **`className` on `*`** — highlight.js and KaTeX mark up nested spans (and raw HTML\n * may set classes on other allowed tags). The base schema does not allow\n * arbitrary classes without this.\n * - **`style` on `span` only** — KaTeX `output: 'html'` uses inline `style` on spans for\n * layout; samples from KaTeX do not attach `style` to other tag names. Allowing\n * `style` on every element would broaden XSS surface for author-controlled raw HTML.\n * - **Chart placeholders** — `div.chart-mount` with `dataChart` / `dataChartData` (narrow\n * allowed chart type strings; data payload is the JSON string).\n *\n * Scripts remain stripped (`strip: ['script']`).\n */\nconst baseAttrs = defaultSchema.attributes ?? {};\nconst baseStar = baseAttrs['*'] ?? [];\nconst baseSpan = baseAttrs.span ?? [];\nconst baseDiv = baseAttrs.div ?? [];\nconst baseTags = defaultSchema.tagNames ?? [];\n\nexport const markdownSanitizeSchema: Schema = {\n ...defaultSchema,\n attributes: {\n ...baseAttrs,\n '*': [...baseStar, 'className'],\n span: [...baseSpan, 'style'],\n div: [\n ...baseDiv,\n ['className', 'chart-mount'],\n ['dataChart', ...CHART_BLOCK_TYPES],\n 'dataChartData',\n ],\n },\n};\n\nconst svgTags = [\n 'svg',\n 'g',\n 'path',\n 'marker',\n 'rect',\n 'circle',\n 'line',\n 'polygon',\n 'text',\n 'tspan',\n 'style',\n 'foreignObject',\n 'defs',\n 'symbol',\n] as const;\n\nconst svgSharedAttributes = [\n 'style',\n 'transform',\n 'fill',\n 'stroke',\n 'strokeWidth',\n 'strokeDasharray',\n 'id',\n 'className',\n] as const;\n\n/**\n * Mermaid-capable sanitizer schema for the Node-only rendering path.\n * It extends the browser-safe schema with a narrow SVG allowlist used by\n * inline Mermaid output.\n */\nexport const schemaWithSvg: Schema = {\n ...markdownSanitizeSchema,\n tagNames: [...baseTags, ...svgTags],\n attributes: {\n ...(markdownSanitizeSchema.attributes ?? {}),\n div: [\n ...baseDiv,\n 'style',\n 'xmlns',\n ['className', 'chart-mount'],\n ['dataChart', ...CHART_BLOCK_TYPES],\n 'dataChartData',\n ],\n svg: [\n ...svgSharedAttributes,\n 'ariaRoleDescription',\n 'role',\n 'viewBox',\n 'width',\n 'xmlns',\n ],\n g: [\n ...svgSharedAttributes,\n 'dataId',\n 'dataNode',\n ],\n path: [...svgSharedAttributes, 'd', 'markerEnd'],\n marker: [\n ...svgSharedAttributes,\n 'markerHeight',\n 'markerUnits',\n 'markerWidth',\n 'orient',\n 'refX',\n 'refY',\n 'viewBox',\n ],\n rect: [...svgSharedAttributes, 'height', 'rx', 'ry', 'width', 'x', 'y', 'name'],\n circle: [...svgSharedAttributes, 'cx', 'cy', 'r'],\n line: [...svgSharedAttributes, 'markerEnd', 'x1', 'x2', 'y1', 'y2'],\n polygon: [...svgSharedAttributes, 'points'],\n text: [\n ...svgSharedAttributes,\n 'alignmentBaseline',\n 'dominantBaseline',\n 'dy',\n 'textAnchor',\n 'x',\n 'y',\n ],\n tspan: [...svgSharedAttributes, 'dy', 'x'],\n foreignObject: ['height', 'width'],\n symbol: ['clipRule', 'fillRule', 'height', 'id', 'width'],\n defs: [],\n style: [],\n },\n};\n"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { R as RenderDiagnostic, a as RenderMarkdownOptions } from './types-DlRranpy.js';
|
|
2
|
+
import * as unified from 'unified';
|
|
3
|
+
import { Plugin } from 'unified';
|
|
4
|
+
import * as hast from 'hast';
|
|
5
|
+
import { Root } from 'hast';
|
|
6
|
+
import * as mdast from 'mdast';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Stable identifier for this library. Intended for diagnostics and smoke tests.
|
|
10
|
+
*/
|
|
11
|
+
declare function libraryId(): string;
|
|
12
|
+
|
|
13
|
+
declare function parseMarkdownFile(raw: string): {
|
|
14
|
+
frontMatter: Record<string, unknown>;
|
|
15
|
+
content: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
type DiagnosticEmitter = (d: RenderDiagnostic) => void;
|
|
19
|
+
|
|
20
|
+
type InternalOptions = RenderMarkdownOptions & {
|
|
21
|
+
emitDiagnostic?: DiagnosticEmitter;
|
|
22
|
+
};
|
|
23
|
+
declare function createMarkdownProcessorInternal(options?: InternalOptions): unified.Processor<mdast.Root, mdast.Root, hast.Root, undefined, undefined>;
|
|
24
|
+
|
|
25
|
+
declare function createMarkdownProcessor(options?: RenderMarkdownOptions): ReturnType<typeof createMarkdownProcessorInternal>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Replaces supported `chart-…` fenced JSON blocks with a mount placeholder.
|
|
29
|
+
* Invalid JSON leaves the original `<pre><code>` unchanged.
|
|
30
|
+
*/
|
|
31
|
+
declare const rehypeChartBlocks: Plugin<[], Root>;
|
|
32
|
+
|
|
33
|
+
type RehypeCdnImagesOptions = RenderMarkdownOptions;
|
|
34
|
+
/**
|
|
35
|
+
* Adds `markdown-inline-img` to all images and optionally rewrites `src` using
|
|
36
|
+
* caller-provided manifest data.
|
|
37
|
+
*/
|
|
38
|
+
declare const rehypeCdnImages: Plugin<[RehypeCdnImagesOptions?], Root>;
|
|
39
|
+
|
|
40
|
+
declare function renderMarkdown(markdown: string, options?: RenderMarkdownOptions): Promise<{
|
|
41
|
+
html: string;
|
|
42
|
+
diagnostics: RenderDiagnostic[];
|
|
43
|
+
}>;
|
|
44
|
+
|
|
45
|
+
declare function renderMarkdownToHtml(markdown: string, options?: RenderMarkdownOptions): Promise<string>;
|
|
46
|
+
|
|
47
|
+
export { RenderDiagnostic, RenderMarkdownOptions, createMarkdownProcessor, libraryId, parseMarkdownFile, rehypeCdnImages, rehypeChartBlocks, renderMarkdown, renderMarkdownToHtml };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { rehypeCdnImages, rehypeChartBlocks_default, remarkHeadingIds, markdownSanitizeSchema } from './chunk-CVZY5VWM.js';
|
|
2
|
+
import yaml from 'js-yaml';
|
|
3
|
+
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
|
|
4
|
+
import rehypeHighlight from 'rehype-highlight';
|
|
5
|
+
import rehypeKatex from 'rehype-katex';
|
|
6
|
+
import rehypeRaw from 'rehype-raw';
|
|
7
|
+
import rehypeSanitize from 'rehype-sanitize';
|
|
8
|
+
import rehypeSlug from 'rehype-slug';
|
|
9
|
+
import rehypeStringify from 'rehype-stringify';
|
|
10
|
+
import remarkGfm from 'remark-gfm';
|
|
11
|
+
import remarkMath from 'remark-math';
|
|
12
|
+
import remarkParse from 'remark-parse';
|
|
13
|
+
import remarkRehype from 'remark-rehype';
|
|
14
|
+
import { unified } from 'unified';
|
|
15
|
+
|
|
16
|
+
// src/libraryId.ts
|
|
17
|
+
function libraryId() {
|
|
18
|
+
return "featherdown";
|
|
19
|
+
}
|
|
20
|
+
function parseMarkdownFile(raw) {
|
|
21
|
+
const match = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/.exec(raw);
|
|
22
|
+
if (!raw.startsWith("---") || !match) {
|
|
23
|
+
return { frontMatter: {}, content: raw };
|
|
24
|
+
}
|
|
25
|
+
const yamlSource = match[1] ?? "";
|
|
26
|
+
const content = raw.slice(match[0].length);
|
|
27
|
+
try {
|
|
28
|
+
const loaded = yaml.load(yamlSource);
|
|
29
|
+
if (loaded === void 0 || loaded === null) {
|
|
30
|
+
return { frontMatter: {}, content };
|
|
31
|
+
}
|
|
32
|
+
if (typeof loaded !== "object" || Array.isArray(loaded)) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
"Front matter root must be a YAML mapping (object), not a list or scalar."
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
return { frontMatter: loaded, content };
|
|
38
|
+
} catch (e) {
|
|
39
|
+
if (e instanceof Error && e.message.startsWith("Front matter")) {
|
|
40
|
+
throw e;
|
|
41
|
+
}
|
|
42
|
+
const detail = e instanceof Error ? e.message : String(e);
|
|
43
|
+
throw new Error(`Front matter YAML could not be parsed: ${detail}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function createMarkdownProcessorInternal(options) {
|
|
47
|
+
const processor = unified().use(remarkParse).use(remarkGfm).use(remarkMath).use(remarkHeadingIds).use(remarkRehype, { allowDangerousHtml: true }).use(rehypeRaw);
|
|
48
|
+
if (options?.emitDiagnostic) {
|
|
49
|
+
processor.use(rehypeChartBlocks_default, { emitDiagnostic: options.emitDiagnostic });
|
|
50
|
+
} else {
|
|
51
|
+
processor.use(rehypeChartBlocks_default);
|
|
52
|
+
}
|
|
53
|
+
processor.use(rehypeKatex, { output: "html" }).use(rehypeSanitize, markdownSanitizeSchema).use(rehypeSlug).use(rehypeAutolinkHeadings, { behavior: "wrap" }).use(rehypeHighlight).use(rehypeCdnImages, options).use(rehypeStringify);
|
|
54
|
+
return processor;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// src/createMarkdownProcessor.ts
|
|
58
|
+
function createMarkdownProcessor(options) {
|
|
59
|
+
return createMarkdownProcessorInternal(options);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/rehypeChartBlocks.ts
|
|
63
|
+
var rehypeChartBlocks = rehypeChartBlocks_default;
|
|
64
|
+
|
|
65
|
+
// src/rehypeCdnImages.ts
|
|
66
|
+
var rehypeCdnImages2 = rehypeCdnImages;
|
|
67
|
+
|
|
68
|
+
// src/internal/diagnostics.ts
|
|
69
|
+
function createDiagnosticCollector() {
|
|
70
|
+
const diagnostics = [];
|
|
71
|
+
const emit = (d) => {
|
|
72
|
+
diagnostics.push(d);
|
|
73
|
+
};
|
|
74
|
+
return {
|
|
75
|
+
emit,
|
|
76
|
+
diagnostics
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// src/renderMarkdown.ts
|
|
81
|
+
async function renderMarkdown(markdown, options) {
|
|
82
|
+
const collector = createDiagnosticCollector();
|
|
83
|
+
const processor = createMarkdownProcessorInternal({
|
|
84
|
+
...options,
|
|
85
|
+
emitDiagnostic: collector.emit
|
|
86
|
+
});
|
|
87
|
+
const file = await processor.process(markdown);
|
|
88
|
+
return { html: String(file), diagnostics: collector.diagnostics };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// src/renderMarkdownToHtml.ts
|
|
92
|
+
async function renderMarkdownToHtml(markdown, options) {
|
|
93
|
+
const result = await renderMarkdown(markdown, options);
|
|
94
|
+
return result.html;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export { createMarkdownProcessor, libraryId, parseMarkdownFile, rehypeCdnImages2 as rehypeCdnImages, rehypeChartBlocks, renderMarkdown, renderMarkdownToHtml };
|
|
98
|
+
//# sourceMappingURL=index.js.map
|
|
99
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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,IAAY,KAAA,CAAM,OAAA,CAAQ,MAAM,CAAA,EAAG;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AA,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"]}
|
package/dist/node.d.ts
ADDED
package/dist/node.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { remarkHeadingIds, rehypeChartBlocks_default, schemaWithSvg, rehypeCdnImages } from './chunk-CVZY5VWM.js';
|
|
2
|
+
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
|
|
3
|
+
import rehypeHighlight from 'rehype-highlight';
|
|
4
|
+
import rehypeKatex from 'rehype-katex';
|
|
5
|
+
import rehypeMermaid from 'rehype-mermaidjs';
|
|
6
|
+
import rehypeRaw from 'rehype-raw';
|
|
7
|
+
import rehypeSanitize from 'rehype-sanitize';
|
|
8
|
+
import rehypeSlug from 'rehype-slug';
|
|
9
|
+
import rehypeStringify from 'rehype-stringify';
|
|
10
|
+
import remarkGfm from 'remark-gfm';
|
|
11
|
+
import remarkMath from 'remark-math';
|
|
12
|
+
import remarkParse from 'remark-parse';
|
|
13
|
+
import remarkRehype from 'remark-rehype';
|
|
14
|
+
import { unified } from 'unified';
|
|
15
|
+
|
|
16
|
+
function createMarkdownProcessorWithMermaidInternal(options) {
|
|
17
|
+
return unified().use(remarkParse).use(remarkGfm).use(remarkMath).use(remarkHeadingIds).use(remarkRehype, { allowDangerousHtml: true }).use(rehypeRaw).use(rehypeChartBlocks_default).use(rehypeSlug).use(rehypeAutolinkHeadings, { behavior: "wrap" }).use(rehypeKatex, { output: "html" }).use(rehypeHighlight).use(rehypeMermaid, { strategy: "inline-svg" }).use(rehypeSanitize, schemaWithSvg).use(rehypeCdnImages, options).use(rehypeStringify);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// src/node.ts
|
|
21
|
+
async function renderMarkdownToHtmlWithMermaid(markdown, options) {
|
|
22
|
+
const processor = createMarkdownProcessorWithMermaidInternal(options);
|
|
23
|
+
const file = await processor.process(markdown);
|
|
24
|
+
return String(file);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { renderMarkdownToHtmlWithMermaid };
|
|
28
|
+
//# sourceMappingURL=node.js.map
|
|
29
|
+
//# sourceMappingURL=node.js.map
|
package/dist/node.js.map
ADDED
|
@@ -0,0 +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-mermaidjs';\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"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
type RenderMarkdownOptions = {
|
|
2
|
+
kind?: string;
|
|
3
|
+
slug?: string;
|
|
4
|
+
manifest?: {
|
|
5
|
+
map?: Record<string, {
|
|
6
|
+
url: string;
|
|
7
|
+
}>;
|
|
8
|
+
remote?: Record<string, {
|
|
9
|
+
url: string;
|
|
10
|
+
}>;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
type RenderDiagnostic = {
|
|
14
|
+
code: string;
|
|
15
|
+
message: string;
|
|
16
|
+
severity: 'warning';
|
|
17
|
+
source: 'chart' | 'images';
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type { RenderDiagnostic as R, RenderMarkdownOptions as a };
|
package/package.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "featherdown",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Markdown-to-HTML pipeline with sanitization, diagnostics, and optional Node Mermaid rendering.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./node": {
|
|
19
|
+
"types": "./dist/node.d.ts",
|
|
20
|
+
"import": "./dist/node.js",
|
|
21
|
+
"default": "./dist/node.js"
|
|
22
|
+
},
|
|
23
|
+
"./package.json": "./package.json"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsup",
|
|
27
|
+
"test": "vitest run",
|
|
28
|
+
"test:watch": "vitest",
|
|
29
|
+
"lint": "eslint .",
|
|
30
|
+
"typecheck": "tsc --noEmit",
|
|
31
|
+
"test:exports": "npm run build && node ./test/exports.smoke.mjs",
|
|
32
|
+
"prepublishOnly": "npm run lint && npm run typecheck && npm test && npm run test:exports"
|
|
33
|
+
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"markdown",
|
|
36
|
+
"remark",
|
|
37
|
+
"rehype",
|
|
38
|
+
"html",
|
|
39
|
+
"sanitization",
|
|
40
|
+
"katex",
|
|
41
|
+
"mermaid",
|
|
42
|
+
"publishing"
|
|
43
|
+
],
|
|
44
|
+
"license": "MIT",
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=18"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@eslint/js": "^9.18.0",
|
|
50
|
+
"@types/js-yaml": "^4.0.9",
|
|
51
|
+
"eslint": "^9.18.0",
|
|
52
|
+
"tsup": "^8.3.5",
|
|
53
|
+
"typescript": "^5.7.3",
|
|
54
|
+
"typescript-eslint": "^8.21.0",
|
|
55
|
+
"vitest": "^3.0.5"
|
|
56
|
+
},
|
|
57
|
+
"dependencies": {
|
|
58
|
+
"hast-util-to-text": "^4.0.2",
|
|
59
|
+
"js-yaml": "^4.1.1",
|
|
60
|
+
"lowlight": "^3.3.0",
|
|
61
|
+
"rehype-autolink-headings": "^7.1.0",
|
|
62
|
+
"rehype-highlight": "^7.0.2",
|
|
63
|
+
"rehype-katex": "^7.0.1",
|
|
64
|
+
"rehype-mermaidjs": "^2.0.0",
|
|
65
|
+
"rehype-raw": "^7.0.0",
|
|
66
|
+
"rehype-sanitize": "^6.0.0",
|
|
67
|
+
"rehype-slug": "^6.0.0",
|
|
68
|
+
"rehype-stringify": "^10.0.1",
|
|
69
|
+
"remark-gfm": "^4.0.1",
|
|
70
|
+
"remark-math": "^6.0.0",
|
|
71
|
+
"remark-parse": "^11.0.0",
|
|
72
|
+
"remark-rehype": "^11.1.2",
|
|
73
|
+
"unified": "^11.0.5",
|
|
74
|
+
"unist-util-visit": "^5.1.0"
|
|
75
|
+
}
|
|
76
|
+
}
|