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.
@@ -0,0 +1,139 @@
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
+ export type { HeadingMetadata as H, RenderDiagnostic as R, TocItem as T, RenderMarkdownOptions as a, RenderMarkdownDocumentResult as b };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "featherdown",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Markdown-to-HTML pipeline with sanitization, diagnostics, and optional Node Mermaid rendering.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -29,6 +29,7 @@
29
29
  "lint": "eslint .",
30
30
  "typecheck": "tsc --noEmit",
31
31
  "test:exports": "npm run build && node ./test/exports.smoke.mjs",
32
+ "verify-release-version": "node ./scripts/verify-release-version.mjs",
32
33
  "prepublishOnly": "npm run lint && npm run typecheck && npm test && npm run test:exports"
33
34
  },
34
35
  "keywords": [
@@ -42,6 +43,17 @@
42
43
  "publishing"
43
44
  ],
44
45
  "license": "MIT",
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "git+https://github.com/karuifeather/featherdown.git"
49
+ },
50
+ "bugs": {
51
+ "url": "https://github.com/karuifeather/featherdown/issues"
52
+ },
53
+ "publishConfig": {
54
+ "access": "public",
55
+ "provenance": true
56
+ },
45
57
  "engines": {
46
58
  "node": ">=18"
47
59
  },
@@ -75,6 +87,7 @@
75
87
  "rehype-sanitize": "^6.0.0",
76
88
  "rehype-slug": "^6.0.0",
77
89
  "rehype-stringify": "^10.0.1",
90
+ "remark-directive": "^4.0.0",
78
91
  "remark-gfm": "^4.0.1",
79
92
  "remark-math": "^6.0.0",
80
93
  "remark-parse": "^11.0.0",
@@ -1,243 +0,0 @@
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
@@ -1 +0,0 @@
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,KAAK,IAAA,EAAM;AACpB,IAAA,IAAI,OAAO,CAAA,KAAM,QAAA,IAAY,CAAA,CAAE,UAAA,CAAW,WAAW,CAAA,EAAG;AACtD,MAAA,OAAO,CAAA,CAAE,KAAA,CAAM,WAAA,CAAY,MAAM,CAAA;AAAA,IACnC;AAAA,EACF;AACA,EAAA,OAAO,MAAA;AACT;AAMA,IAAM,iBAAA,GAGF,SAASA,kBAAAA,CAAkB,OAAA,EAAS;AACtC,EAAA,MAAM,iBAAiB,OAAA,EAAS,cAAA;AAChC,EAAA,OAAO,CAAC,IAAA,KAAoB;AAC1B,IAAA,KAAA,CAAM,IAAA,EAAM,SAAA,EAAW,CAAC,IAAA,EAAM,OAAO,MAAA,KAAW;AAC9C,MAAA,IAAI,IAAA,CAAK,YAAY,KAAA,EAAO;AAC5B,MAAA,IAAI,CAAC,MAAA,IAAU,OAAO,KAAA,KAAU,QAAA,EAAU;AAC1C,MAAA,MAAM,IAAA,GAAO,IAAA,CAAK,QAAA,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AAA,MACA,MAAA;AAAA,MACA,MAAA;AAAA,MACA;AAAA,KACF;AAAA,IACA,IAAA,EAAM,CAAC,GAAG,mBAAA,EAAqB,QAAA,EAAU,MAAM,IAAA,EAAM,OAAA,EAAS,GAAA,EAAK,GAAA,EAAK,MAAM,CAAA;AAAA,IAC9E,QAAQ,CAAC,GAAG,mBAAA,EAAqB,IAAA,EAAM,MAAM,GAAG,CAAA;AAAA,IAChD,IAAA,EAAM,CAAC,GAAG,mBAAA,EAAqB,aAAa,IAAA,EAAM,IAAA,EAAM,MAAM,IAAI,CAAA;AAAA,IAClE,OAAA,EAAS,CAAC,GAAG,mBAAA,EAAqB,QAAQ,CAAA;AAAA,IAC1C,IAAA,EAAM;AAAA,MACJ,GAAG,mBAAA;AAAA,MACH,mBAAA;AAAA,MACA,kBAAA;AAAA,MACA,IAAA;AAAA,MACA,YAAA;AAAA,MACA,GAAA;AAAA,MACA;AAAA,KACF;AAAA,IACA,KAAA,EAAO,CAAC,GAAG,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"]}
@@ -1,20 +0,0 @@
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 };