@lostgradient/cinder 0.16.1 → 0.17.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/CHANGELOG.md +185 -0
- package/README.md +33 -11
- package/components.json +53 -102
- package/dist/_internal/chart/chart-utilities.d.ts +1 -0
- package/dist/cli/index.js +63 -10
- package/dist/cli/mcp-dependencies.d.ts +4 -0
- package/dist/components/approval-card/approval-card.css +1 -6
- package/dist/components/approval-card/index.js +94 -55
- package/dist/components/area-chart/index.js +40 -6
- package/dist/components/bar-chart/index.js +132 -83
- package/dist/components/code-block/index.js +58 -9
- package/dist/components/command-menu/command-menu.css +9 -0
- package/dist/components/command-menu/index.js +7 -2
- package/dist/components/diff-statistics/diff-statistics.svelte.d.ts +3 -3
- package/dist/components/file-upload/file-upload.schema.js +5 -1
- package/dist/components/file-upload/file-upload.types.d.ts +2 -0
- package/dist/components/file-upload/index.js +37 -27
- package/dist/components/invocation-rule-builder/index.d.ts +1 -1
- package/dist/components/invocation-rule-builder/index.js +244 -199
- package/dist/components/invocation-rule-builder/invocation-rule-builder.css +8 -0
- package/dist/components/invocation-rule-builder/invocation-rule-builder.schema.d.ts +2 -2
- package/dist/components/invocation-rule-builder/invocation-rule-builder.schema.js +309 -193
- package/dist/components/invocation-rule-builder/invocation-rule-builder.svelte.d.ts +3 -2
- package/dist/components/invocation-rule-builder/invocation-rule-builder.types.d.ts +98 -31
- package/dist/components/json-editor/index.d.ts +5 -0
- package/dist/components/json-editor/index.js +261 -0
- package/dist/components/json-editor/json-editor.css +49 -0
- package/dist/components/{diff-viewer/diff-viewer.schema.js → json-editor/json-editor.schema.js} +37 -49
- package/dist/components/json-editor/json-editor.svelte.d.ts +21 -0
- package/dist/components/json-editor/json-editor.types.d.ts +25 -0
- package/dist/components/{diff-viewer/diff-viewer.variables.js → json-editor/json-editor.variables.js} +4 -4
- package/dist/components/json-schema-editor/index.js +2041 -4165
- package/dist/components/json-schema-editor/json-schema-editor-state.svelte.d.ts +17 -1
- package/dist/components/json-schema-editor/json-schema-editor-types.d.ts +8 -1
- package/dist/components/json-schema-editor/json-schema-editor.css +35 -0
- package/dist/components/json-schema-editor/json-schema-editor.svelte.d.ts +0 -1
- package/dist/components/json-schema-editor/json-schema-validator.d.ts +9 -4
- package/dist/components/line-chart/index.js +40 -6
- package/dist/components/matrix-chart/index.js +40 -6
- package/dist/components/payload-inspector/index.js +10 -2
- package/dist/components/payload-inspector/payload-inspector.schema.js +11 -1
- package/dist/components/payload-inspector/payload-inspector.types.d.ts +20 -0
- package/dist/components/run-step-timeline/index.js +158 -110
- package/dist/components/run-step-timeline/run-step-timeline.css +46 -0
- package/dist/components/run-step-timeline/run-step-timeline.schema.js +26 -1
- package/dist/components/run-step-timeline/run-step-timeline.types.d.ts +22 -2
- package/dist/components/schedule-builder/index.js +165 -93
- package/dist/components/schedule-builder/schedule-builder.schema.js +8 -1
- package/dist/components/schedule-builder/schedule-builder.svelte.d.ts +1 -1
- package/dist/components/schedule-builder/schedule-builder.types.d.ts +12 -0
- package/dist/components/schema-form/index.d.ts +1 -1
- package/dist/components/schema-form/index.js +107 -25
- package/dist/components/schema-form/schema-form.schema.js +9 -1
- package/dist/components/schema-form/schema-form.svelte.d.ts +1 -1
- package/dist/components/schema-form/schema-form.types.d.ts +8 -0
- package/dist/components/sidebar/index.js +93 -42
- package/dist/components/sidebar/sidebar.css +7 -16
- package/dist/components/sidebar/sidebar.schema.js +8 -9
- package/dist/components/sidebar/sidebar.types.d.ts +14 -12
- package/dist/components/source-diff-viewer/source-diff-viewer.svelte.d.ts +2 -2
- package/dist/components/spectrogram/index.js +40 -6
- package/dist/components/spectrum-chart/index.js +40 -6
- package/dist/components/tabs/tabs.css +2 -0
- package/dist/components/textarea/textarea.svelte.d.ts +1 -1
- package/dist/components/toast-region/index.js +2 -2
- package/dist/components/toast-region/toast-region.css +1 -1
- package/dist/components/waveform/index.js +40 -6
- package/dist/highlighters/shiki/index.d.ts +47 -5
- package/dist/highlighters/shiki/index.js +58 -9
- package/dist/index.d.ts +4 -4
- package/dist/index.js +15347 -16138
- package/dist/server/components/access-gate/index.js +2 -5
- package/dist/server/components/approval-card/index.js +2 -2
- package/dist/server/components/area-chart/index.js +3 -3
- package/dist/server/components/bar-chart/index.js +3 -3
- package/dist/server/components/command-menu/index.js +1 -1
- package/dist/server/components/context-menu/index.js +5 -5
- package/dist/server/components/data-table/index.js +2 -2
- package/dist/server/components/diff-statistics/index.js +3 -5
- package/dist/server/components/dropdown/index.js +6 -7
- package/dist/server/components/file-upload/index.js +2 -3
- package/dist/server/components/icons/index.js +17 -26
- package/dist/server/components/inline-loading/index.js +1 -1
- package/dist/server/components/invocation-rule-builder/index.js +1 -1
- package/dist/server/components/json-editor/index.js +13 -0
- package/dist/server/components/json-schema-editor/index.js +4 -16
- package/dist/server/components/line-chart/index.js +3 -3
- package/dist/server/components/matrix-chart/index.js +2 -2
- package/dist/server/components/menu-bar/index.js +4 -4
- package/dist/server/components/payload-inspector/index.js +2 -2
- package/dist/server/components/run-step-timeline/index.js +1 -1
- package/dist/server/components/schedule-builder/index.js +3 -3
- package/dist/server/components/schema-form/index.js +1 -1
- package/dist/server/components/selection-popover/index.js +3 -5
- package/dist/server/components/sidebar/index.js +1 -1
- package/dist/server/components/spectrogram/index.js +2 -2
- package/dist/server/components/spectrum-chart/index.js +2 -2
- package/dist/server/components/surface/index.js +3 -5
- package/dist/server/components/table/index.js +2 -2
- package/dist/server/components/tabs/index.js +5 -5
- package/dist/server/components/toast-region/index.js +1 -1
- package/dist/server/components/toolbar/index.js +2 -3
- package/dist/server/components/waveform/index.js +2 -2
- package/dist/server/highlighters/shiki/index.js +61 -25
- package/dist/server/index.js +105 -115
- package/dist/server/{index.server-7yfz2t73.js → index.server-003t81xk.js} +1 -1
- package/dist/server/{index.server-gwgm8gqg.js → index.server-032p855q.js} +4 -4
- package/dist/server/{index.server-tf2n3ccm.js → index.server-1vfhzhkj.js} +1 -1
- package/dist/server/{index.server-jz5yxwde.js → index.server-4cbqjf14.js} +16 -7
- package/dist/server/{index.server-aqethy0w.js → index.server-66nm5gd5.js} +102 -26
- package/dist/server/{index.server-m0ezemav.js → index.server-6mnbznbt.js} +4 -2
- package/dist/server/{index.server-1nq8h5yb.js → index.server-6vbpz6dd.js} +40 -6
- package/dist/server/{index.server-796hb0r8.js → index.server-7qak74fg.js} +1 -1
- package/dist/server/{index.server-5exh7rmw.js → index.server-7ygdwxre.js} +57 -5
- package/dist/server/{index.server-q1d48s9t.js → index.server-8c6cck0y.js} +6 -4
- package/dist/server/index.server-93vt8ktj.js +95 -0
- package/dist/server/{index.server-ep81fn23.js → index.server-9eccb2fc.js} +2 -2
- package/dist/server/{index.server-zncgb7mw.js → index.server-9nac5z11.js} +92 -49
- package/dist/server/{index.server-bf7d81b4.js → index.server-9vqfmhez.js} +16 -18
- package/dist/server/{index.server-nt304e00.js → index.server-dx58qant.js} +1 -1
- package/dist/server/{index.server-zh3r8vfd.js → index.server-fhrqsg97.js} +1 -1
- package/dist/server/{index.server-dq0k0qf6.js → index.server-geq56xaz.js} +10 -10
- package/dist/server/{index.server-51sxnete.js → index.server-hxveaqg1.js} +10 -10
- package/dist/server/{index.server-c5qv3p61.js → index.server-j87v28yy.js} +59 -30
- package/dist/server/{index.server-s5g7reqp.js → index.server-mewms9dg.js} +2 -2
- package/dist/server/index.server-mm728d0w.js +20 -0
- package/dist/server/{index.server-5mc2vsy0.js → index.server-n0rbn5yf.js} +4 -2
- package/dist/server/{index.server-qv0kkre4.js → index.server-ng8y854r.js} +188 -107
- package/dist/server/{index.server-wasj5rbh.js → index.server-q5gvb174.js} +4 -4
- package/dist/server/{index.server-g5jgq3jp.js → index.server-qxneqxf8.js} +40 -6
- package/dist/server/{index.server-x1dha7bk.js → index.server-rnddtcb3.js} +4 -2
- package/dist/server/{index.server-7zpzspk6.js → index.server-s4wm4g2a.js} +30 -2
- package/dist/server/index.server-szgghcdh.js +887 -0
- package/dist/server/{index.server-thcda9ny.js → index.server-vd302sxz.js} +11 -4
- package/dist/server/{index.server-3sq9d73w.js → index.server-vz9hqkdq.js} +2 -2
- package/dist/server/{index.server-mvjzcna5.js → index.server-wg6ddzpa.js} +42 -20
- package/dist/server/{index.server-67q8dmbp.js → index.server-y2ncgt7p.js} +1 -1
- package/dist/server/{index.server-4x91gzy1.js → index.server-yqhww50r.js} +4 -4
- package/dist/server/{index.server-7798gc22.js → index.server-zfx4magq.js} +4 -2
- package/package.json +45 -288
- package/src/_internal/chart/chart-utilities.ts +74 -5
- package/src/components/approval-card/approval-card-actions.svelte +12 -28
- package/src/components/approval-card/approval-card.css +1 -6
- package/src/components/bar-chart/bar-chart.examples.json +1 -1
- package/src/components/bar-chart/bar-chart.svelte +3 -1
- package/src/components/command-menu/command-menu.css +9 -0
- package/src/components/command-menu/command-menu.svelte +9 -2
- package/src/components/file-upload/file-upload.schema.json +4 -0
- package/src/components/file-upload/file-upload.schema.ts +4 -0
- package/src/components/file-upload/file-upload.svelte +3 -3
- package/src/components/file-upload/file-upload.types.ts +2 -0
- package/src/components/invocation-rule-builder/index.ts +1 -0
- package/src/components/invocation-rule-builder/invocation-rule-builder.css +8 -0
- package/src/components/invocation-rule-builder/invocation-rule-builder.examples.json +6 -0
- package/src/components/invocation-rule-builder/invocation-rule-builder.schema.json +70 -7
- package/src/components/invocation-rule-builder/invocation-rule-builder.schema.ts +5 -250
- package/src/components/invocation-rule-builder/invocation-rule-builder.svelte +106 -83
- package/src/components/invocation-rule-builder/invocation-rule-builder.types.ts +145 -62
- package/src/components/json-editor/index.ts +6 -0
- package/src/components/json-editor/json-editor.css +49 -0
- package/src/components/json-editor/json-editor.examples.json +13 -0
- package/src/components/json-editor/json-editor.schema.json +57 -0
- package/src/components/json-editor/json-editor.schema.ts +62 -0
- package/src/components/json-editor/json-editor.svelte +104 -0
- package/src/components/json-editor/json-editor.types.ts +29 -0
- package/src/components/json-schema-editor/diff-view.svelte +26 -8
- package/src/components/json-schema-editor/form-view.svelte +1 -1
- package/src/components/json-schema-editor/json-schema-editor-state.svelte.ts +163 -56
- package/src/components/json-schema-editor/json-schema-editor-types.ts +8 -1
- package/src/components/json-schema-editor/json-schema-editor.css +35 -0
- package/src/components/json-schema-editor/json-schema-validator.ts +59 -25
- package/src/components/json-schema-editor/json-view.svelte +52 -18
- package/src/components/payload-inspector/payload-inspector.schema.json +8 -0
- package/src/components/payload-inspector/payload-inspector.schema.ts +10 -0
- package/src/components/payload-inspector/payload-inspector.svelte +2 -2
- package/src/components/payload-inspector/payload-inspector.types.ts +20 -0
- package/src/components/run-step-timeline/run-step-timeline.css +46 -0
- package/src/components/run-step-timeline/run-step-timeline.examples.json +3 -3
- package/src/components/run-step-timeline/run-step-timeline.schema.json +24 -0
- package/src/components/run-step-timeline/run-step-timeline.schema.ts +26 -0
- package/src/components/run-step-timeline/run-step-timeline.svelte +41 -4
- package/src/components/run-step-timeline/run-step-timeline.types.ts +22 -1
- package/src/components/run-step-timeline/run-step-timeline.utilities.ts +9 -1
- package/src/components/schedule-builder/schedule-builder.schema.json +7 -0
- package/src/components/schedule-builder/schedule-builder.schema.ts +8 -0
- package/src/components/schedule-builder/schedule-builder.svelte +94 -22
- package/src/components/schedule-builder/schedule-builder.types.ts +12 -0
- package/src/components/schema-form/index.ts +1 -0
- package/src/components/schema-form/schema-form-body.svelte +94 -17
- package/src/components/schema-form/schema-form.examples.json +1 -1
- package/src/components/schema-form/schema-form.schema.json +5 -0
- package/src/components/schema-form/schema-form.schema.ts +6 -0
- package/src/components/schema-form/schema-form.svelte +4 -0
- package/src/components/schema-form/schema-form.types.ts +9 -0
- package/src/components/side-navigation/side-navigation.examples.json +1 -1
- package/src/components/sidebar/sidebar.css +7 -16
- package/src/components/sidebar/sidebar.examples.json +3 -3
- package/src/components/sidebar/sidebar.schema.json +7 -8
- package/src/components/sidebar/sidebar.schema.ts +8 -8
- package/src/components/sidebar/sidebar.svelte +65 -27
- package/src/components/sidebar/sidebar.types.ts +14 -12
- package/src/components/tabs/tabs.css +2 -0
- package/src/components/toast-region/toast-region.css +1 -1
- package/src/components/toast-region/toast-region.examples.json +1 -1
- package/src/components/toast-region/toast-region.svelte +2 -2
- package/src/highlighters/shiki/index.ts +157 -17
- package/src/index.ts +5 -7
- package/src/styles/components.css +1 -1
- package/src/utilities/change-tracker.svelte.ts +1 -1
- package/dist/commentary/anchor-decorations.d.ts +0 -86
- package/dist/commentary/anchor-decorations.js +0 -490
- package/dist/commentary/anchoring.d.ts +0 -93
- package/dist/commentary/anchoring.js +0 -157
- package/dist/commentary/comments/index.d.ts +0 -12
- package/dist/commentary/comments/index.js +0 -14
- package/dist/commentary/comments/mentions.d.ts +0 -43
- package/dist/commentary/comments/mentions.js +0 -65
- package/dist/commentary/comments/reanchor.d.ts +0 -86
- package/dist/commentary/comments/reanchor.js +0 -220
- package/dist/commentary/comments/types.d.ts +0 -260
- package/dist/commentary/comments/types.js +0 -83
- package/dist/commentary/comments/updates.d.ts +0 -102
- package/dist/commentary/comments/updates.js +0 -226
- package/dist/commentary/export/comments-export.d.ts +0 -42
- package/dist/commentary/export/comments-export.js +0 -258
- package/dist/commentary/export/index.d.ts +0 -12
- package/dist/commentary/export/index.js +0 -12
- package/dist/commentary/export/markdown-summary.d.ts +0 -31
- package/dist/commentary/export/markdown-summary.js +0 -218
- package/dist/commentary/export/types.d.ts +0 -162
- package/dist/commentary/export/types.js +0 -7
- package/dist/commentary/export/unified-diff.d.ts +0 -28
- package/dist/commentary/export/unified-diff.js +0 -250
- package/dist/commentary/index.d.ts +0 -6
- package/dist/commentary/index.js +0 -6
- package/dist/commentary/session/index.d.ts +0 -12
- package/dist/commentary/session/index.js +0 -14
- package/dist/commentary/session/persistence.d.ts +0 -92
- package/dist/commentary/session/persistence.js +0 -253
- package/dist/commentary/session/types.d.ts +0 -208
- package/dist/commentary/session/types.js +0 -26
- package/dist/commentary/session/updates.d.ts +0 -155
- package/dist/commentary/session/updates.js +0 -362
- package/dist/commentary/shared/anchor-types.d.ts +0 -116
- package/dist/commentary/shared/anchor-types.js +0 -9
- package/dist/components/diff-viewer/diff-controller.svelte.d.ts +0 -75
- package/dist/components/diff-viewer/diff-front-matter.svelte.d.ts +0 -28
- package/dist/components/diff-viewer/diff-line.svelte.d.ts +0 -22
- package/dist/components/diff-viewer/diff-summary-bar.svelte.d.ts +0 -13
- package/dist/components/diff-viewer/diff-toolbar.svelte.d.ts +0 -36
- package/dist/components/diff-viewer/diff-viewer.svelte.d.ts +0 -22
- package/dist/components/diff-viewer/diff-viewer.types.d.ts +0 -53
- package/dist/components/diff-viewer/front-matter-header.svelte.d.ts +0 -26
- package/dist/components/diff-viewer/index.d.ts +0 -4
- package/dist/components/diff-viewer/index.js +0 -2848
- package/dist/components/markdown-editor/editor-skeleton.svelte.d.ts +0 -10
- package/dist/components/markdown-editor/editor-toolbar/editor-toolbar.svelte.d.ts +0 -37
- package/dist/components/markdown-editor/editor-toolbar/index.d.ts +0 -11
- package/dist/components/markdown-editor/editor-toolbar/link-popover.svelte.d.ts +0 -30
- package/dist/components/markdown-editor/editor-toolbar/toolbar-button.svelte.d.ts +0 -19
- package/dist/components/markdown-editor/editor-toolbar/toolbar-dropdown.svelte.d.ts +0 -24
- package/dist/components/markdown-editor/editor-toolbar/toolbar-separator.svelte.d.ts +0 -7
- package/dist/components/markdown-editor/editor-toolbar/types.d.ts +0 -13
- package/dist/components/markdown-editor/index.css +0 -61
- package/dist/components/markdown-editor/index.d.ts +0 -4
- package/dist/components/markdown-editor/index.js +0 -7494
- package/dist/components/markdown-editor/markdown-editor.schema.d.ts +0 -3
- package/dist/components/markdown-editor/markdown-editor.schema.js +0 -177
- package/dist/components/markdown-editor/markdown-editor.svelte.d.ts +0 -29
- package/dist/components/markdown-editor/markdown-editor.types.d.ts +0 -100
- package/dist/components/markdown-editor/markdown-editor.variables.d.ts +0 -2
- package/dist/components/markdown-editor/markdown-editor.variables.js +0 -61
- package/dist/components/review-editor/comment-composer.svelte.d.ts +0 -37
- package/dist/components/review-editor/comment-list.svelte.d.ts +0 -19
- package/dist/components/review-editor/comment-sidebar.svelte.d.ts +0 -22
- package/dist/components/review-editor/export-actions.svelte.d.ts +0 -18
- package/dist/components/review-editor/focus-navigation.d.ts +0 -105
- package/dist/components/review-editor/front-matter-fields.svelte.d.ts +0 -10
- package/dist/components/review-editor/index.d.ts +0 -20
- package/dist/components/review-editor/index.js +0 -14731
- package/dist/components/review-editor/live-region.svelte.d.ts +0 -23
- package/dist/components/review-editor/review-editor-anchors.svelte.d.ts +0 -96
- package/dist/components/review-editor/review-editor-controls.svelte.d.ts +0 -41
- package/dist/components/review-editor/review-editor-exports.d.ts +0 -80
- package/dist/components/review-editor/review-editor-front-matter.d.ts +0 -28
- package/dist/components/review-editor/review-editor-impl.svelte.d.ts +0 -31
- package/dist/components/review-editor/review-editor-selection-geometry.d.ts +0 -10
- package/dist/components/review-editor/review-editor-selection-types.d.ts +0 -62
- package/dist/components/review-editor/review-editor-selection.svelte.d.ts +0 -50
- package/dist/components/review-editor/review-editor-state.svelte.d.ts +0 -77
- package/dist/components/review-editor/review-editor-threads.svelte.d.ts +0 -137
- package/dist/components/review-editor/review-editor.css +0 -273
- package/dist/components/review-editor/review-editor.schema.d.ts +0 -3
- package/dist/components/review-editor/review-editor.schema.js +0 -143
- package/dist/components/review-editor/review-editor.svelte.d.ts +0 -19
- package/dist/components/review-editor/review-editor.types.d.ts +0 -77
- package/dist/components/review-editor/review-editor.variables.d.ts +0 -2
- package/dist/components/review-editor/review-editor.variables.js +0 -61
- package/dist/components/review-editor/thread-popover.svelte.d.ts +0 -32
- package/dist/diff/index.d.ts +0 -2
- package/dist/diff/index.js +0 -1
- package/dist/diff/line-diff.d.ts +0 -84
- package/dist/diff/line-diff.js +0 -372
- package/dist/diff/types.d.ts +0 -1
- package/dist/diff/types.js +0 -1
- package/dist/editor/attach.d.ts +0 -30
- package/dist/editor/attach.js +0 -86
- package/dist/editor/bridge.d.ts +0 -110
- package/dist/editor/bridge.js +0 -260
- package/dist/editor/clipboard.d.ts +0 -19
- package/dist/editor/clipboard.js +0 -189
- package/dist/editor/commands.d.ts +0 -167
- package/dist/editor/commands.js +0 -728
- package/dist/editor/component-runtime.d.ts +0 -21
- package/dist/editor/component-runtime.js +0 -20
- package/dist/editor/editor.d.ts +0 -23
- package/dist/editor/editor.js +0 -256
- package/dist/editor/index.d.ts +0 -30
- package/dist/editor/index.js +0 -42
- package/dist/editor/keymap-plugin.d.ts +0 -56
- package/dist/editor/keymap-plugin.js +0 -157
- package/dist/editor/link-input-rule.d.ts +0 -4
- package/dist/editor/link-input-rule.js +0 -26
- package/dist/editor/milkdown-plugin-runtime.d.ts +0 -20
- package/dist/editor/milkdown-plugin-runtime.js +0 -43
- package/dist/editor/placeholder-security.d.ts +0 -22
- package/dist/editor/placeholder-security.js +0 -36
- package/dist/editor/placeholder.d.ts +0 -14
- package/dist/editor/placeholder.js +0 -56
- package/dist/editor/sanitize-html.d.ts +0 -32
- package/dist/editor/sanitize-html.js +0 -111
- package/dist/editor/template-completion-plugin.d.ts +0 -159
- package/dist/editor/template-completion-plugin.js +0 -615
- package/dist/editor/template-invalid-decoration-plugin.d.ts +0 -73
- package/dist/editor/template-invalid-decoration-plugin.js +0 -155
- package/dist/editor/template-placeholders.d.ts +0 -96
- package/dist/editor/template-placeholders.js +0 -355
- package/dist/editor/template-position-utilities.d.ts +0 -34
- package/dist/editor/template-position-utilities.js +0 -63
- package/dist/editor/template-render.d.ts +0 -37
- package/dist/editor/template-render.js +0 -45
- package/dist/editor/test-utilities.d.ts +0 -49
- package/dist/editor/test-utilities.js +0 -93
- package/dist/editor/types.d.ts +0 -234
- package/dist/editor/types.js +0 -8
- package/dist/markdown/diff/compute.d.ts +0 -28
- package/dist/markdown/diff/compute.js +0 -250
- package/dist/markdown/diff/frontmatter.d.ts +0 -66
- package/dist/markdown/diff/frontmatter.js +0 -135
- package/dist/markdown/diff/index.d.ts +0 -27
- package/dist/markdown/diff/index.js +0 -28
- package/dist/markdown/diff/line-diff.d.ts +0 -2
- package/dist/markdown/diff/line-diff.js +0 -1
- package/dist/markdown/diff/positions.d.ts +0 -66
- package/dist/markdown/diff/positions.js +0 -147
- package/dist/markdown/diff/types.d.ts +0 -78
- package/dist/markdown/diff/types.js +0 -7
- package/dist/markdown/index.d.ts +0 -2
- package/dist/markdown/index.js +0 -8
- package/dist/markdown/pipeline/ast.d.ts +0 -302
- package/dist/markdown/pipeline/ast.js +0 -417
- package/dist/markdown/pipeline/errors.d.ts +0 -37
- package/dist/markdown/pipeline/errors.js +0 -49
- package/dist/markdown/pipeline/frontmatter.d.ts +0 -127
- package/dist/markdown/pipeline/frontmatter.js +0 -438
- package/dist/markdown/pipeline/index.d.ts +0 -37
- package/dist/markdown/pipeline/index.js +0 -40
- package/dist/markdown/pipeline/parser.d.ts +0 -65
- package/dist/markdown/pipeline/parser.js +0 -106
- package/dist/markdown/pipeline/serializer.d.ts +0 -67
- package/dist/markdown/pipeline/serializer.js +0 -78
- package/dist/markdown/pipeline/strip-positions.d.ts +0 -20
- package/dist/markdown/pipeline/strip-positions.js +0 -28
- package/dist/markdown/pipeline/types.d.ts +0 -116
- package/dist/markdown/pipeline/types.js +0 -8
- package/dist/markdown/rendering/extract-code-blocks.d.ts +0 -16
- package/dist/markdown/rendering/extract-code-blocks.js +0 -27
- package/dist/markdown/rendering/highlighter.d.ts +0 -109
- package/dist/markdown/rendering/highlighter.js +0 -251
- package/dist/markdown/rendering/index.d.ts +0 -41
- package/dist/markdown/rendering/index.js +0 -46
- package/dist/markdown/rendering/mermaid-cache.d.ts +0 -55
- package/dist/markdown/rendering/mermaid-cache.js +0 -123
- package/dist/markdown/rendering/rehype-shiki-sync.d.ts +0 -57
- package/dist/markdown/rendering/rehype-shiki-sync.js +0 -354
- package/dist/markdown/rendering/render-async.d.ts +0 -43
- package/dist/markdown/rendering/render-async.js +0 -114
- package/dist/markdown/rendering/render-streaming.d.ts +0 -33
- package/dist/markdown/rendering/render-streaming.js +0 -123
- package/dist/markdown/rendering/render-worker.d.ts +0 -19
- package/dist/markdown/rendering/render-worker.js +0 -35
- package/dist/markdown/rendering/render.d.ts +0 -123
- package/dist/markdown/rendering/render.js +0 -477
- package/dist/markdown/rendering/sanitize-schema.d.ts +0 -24
- package/dist/markdown/rendering/sanitize-schema.js +0 -105
- package/dist/markdown/rendering/transform-urls.d.ts +0 -37
- package/dist/markdown/rendering/transform-urls.js +0 -51
- package/dist/markdown/rendering/types.d.ts +0 -51
- package/dist/markdown/rendering/types.js +0 -8
- package/dist/markdown/rendering/worker-dom-shim.d.ts +0 -87
- package/dist/markdown/rendering/worker-dom-shim.js +0 -50
- package/dist/markdown/utilities/safe-url.d.ts +0 -100
- package/dist/markdown/utilities/safe-url.js +0 -236
- package/dist/markdown/utilities/sort-keys.d.ts +0 -19
- package/dist/markdown/utilities/sort-keys.js +0 -33
- package/dist/server/commentary/anchor-decorations.js +0 -490
- package/dist/server/commentary/anchoring.js +0 -157
- package/dist/server/commentary/comments/index.js +0 -14
- package/dist/server/commentary/comments/mentions.js +0 -65
- package/dist/server/commentary/comments/reanchor.js +0 -220
- package/dist/server/commentary/comments/types.js +0 -83
- package/dist/server/commentary/comments/updates.js +0 -226
- package/dist/server/commentary/export/comments-export.js +0 -258
- package/dist/server/commentary/export/index.js +0 -12
- package/dist/server/commentary/export/markdown-summary.js +0 -218
- package/dist/server/commentary/export/types.js +0 -7
- package/dist/server/commentary/export/unified-diff.js +0 -250
- package/dist/server/commentary/index.js +0 -6
- package/dist/server/commentary/session/index.js +0 -14
- package/dist/server/commentary/session/persistence.js +0 -253
- package/dist/server/commentary/session/types.js +0 -26
- package/dist/server/commentary/session/updates.js +0 -362
- package/dist/server/commentary/shared/anchor-types.js +0 -9
- package/dist/server/components/diff-viewer/index.js +0 -33
- package/dist/server/components/markdown-editor/index.js +0 -52
- package/dist/server/components/review-editor/index.js +0 -3493
- package/dist/server/diff/index.js +0 -1
- package/dist/server/diff/line-diff.js +0 -372
- package/dist/server/diff/types.js +0 -1
- package/dist/server/editor/attach.js +0 -86
- package/dist/server/editor/bridge.js +0 -260
- package/dist/server/editor/clipboard.js +0 -189
- package/dist/server/editor/commands.js +0 -728
- package/dist/server/editor/component-runtime.js +0 -20
- package/dist/server/editor/editor.js +0 -256
- package/dist/server/editor/index.js +0 -42
- package/dist/server/editor/keymap-plugin.js +0 -157
- package/dist/server/editor/link-input-rule.js +0 -26
- package/dist/server/editor/milkdown-plugin-runtime.js +0 -43
- package/dist/server/editor/placeholder-security.js +0 -36
- package/dist/server/editor/placeholder.js +0 -56
- package/dist/server/editor/sanitize-html.js +0 -111
- package/dist/server/editor/template-completion-plugin.js +0 -615
- package/dist/server/editor/template-invalid-decoration-plugin.js +0 -155
- package/dist/server/editor/template-placeholders.js +0 -355
- package/dist/server/editor/template-position-utilities.js +0 -63
- package/dist/server/editor/template-render.js +0 -45
- package/dist/server/editor/test-utilities.js +0 -93
- package/dist/server/editor/types.js +0 -8
- package/dist/server/index.server-25wmev4e.js +0 -2
- package/dist/server/index.server-2c56kqws.js +0 -187
- package/dist/server/index.server-45n4s30n.js +0 -35
- package/dist/server/index.server-4jkqgp17.js +0 -1026
- package/dist/server/index.server-8nm871y8.js +0 -176
- package/dist/server/index.server-d04aj37r.js +0 -62
- package/dist/server/index.server-dg19y3m7.js +0 -9
- package/dist/server/index.server-g3726bja.js +0 -9
- package/dist/server/index.server-gyzmkrnz.js +0 -2
- package/dist/server/index.server-jp19145t.js +0 -9
- package/dist/server/index.server-n4jxy52q.js +0 -2
- package/dist/server/index.server-sghkqw5x.js +0 -421
- package/dist/server/index.server-w6am2dxc.js +0 -12
- package/dist/server/index.server-x66zvjfc.js +0 -1163
- package/dist/server/index.server-zdhv33ph.js +0 -124
- package/dist/server/index.server-zke5zt13.js +0 -9
- package/dist/server/markdown/diff/compute.js +0 -250
- package/dist/server/markdown/diff/frontmatter.js +0 -135
- package/dist/server/markdown/diff/index.js +0 -28
- package/dist/server/markdown/diff/line-diff.js +0 -1
- package/dist/server/markdown/diff/positions.js +0 -147
- package/dist/server/markdown/diff/types.js +0 -7
- package/dist/server/markdown/index.js +0 -8
- package/dist/server/markdown/pipeline/ast.js +0 -417
- package/dist/server/markdown/pipeline/errors.js +0 -49
- package/dist/server/markdown/pipeline/frontmatter.js +0 -438
- package/dist/server/markdown/pipeline/index.js +0 -40
- package/dist/server/markdown/pipeline/parser.js +0 -106
- package/dist/server/markdown/pipeline/serializer.js +0 -78
- package/dist/server/markdown/pipeline/strip-positions.js +0 -28
- package/dist/server/markdown/pipeline/types.js +0 -8
- package/dist/server/markdown/rendering/extract-code-blocks.js +0 -27
- package/dist/server/markdown/rendering/highlighter.js +0 -251
- package/dist/server/markdown/rendering/index.js +0 -46
- package/dist/server/markdown/rendering/mermaid-cache.js +0 -123
- package/dist/server/markdown/rendering/rehype-shiki-sync.js +0 -354
- package/dist/server/markdown/rendering/render-async.js +0 -114
- package/dist/server/markdown/rendering/render-streaming.js +0 -123
- package/dist/server/markdown/rendering/render-worker.js +0 -35
- package/dist/server/markdown/rendering/render.js +0 -477
- package/dist/server/markdown/rendering/sanitize-schema.js +0 -105
- package/dist/server/markdown/rendering/transform-urls.js +0 -51
- package/dist/server/markdown/rendering/types.js +0 -8
- package/dist/server/markdown/rendering/worker-dom-shim.js +0 -50
- package/dist/server/markdown/utilities/safe-url.js +0 -236
- package/dist/server/markdown/utilities/sort-keys.js +0 -33
- package/src/components/diff-viewer/diff-controller.svelte.ts +0 -250
- package/src/components/diff-viewer/diff-front-matter.svelte +0 -52
- package/src/components/diff-viewer/diff-line.svelte +0 -340
- package/src/components/diff-viewer/diff-summary-bar.svelte +0 -106
- package/src/components/diff-viewer/diff-toolbar.svelte +0 -182
- package/src/components/diff-viewer/diff-viewer.examples.json +0 -25
- package/src/components/diff-viewer/diff-viewer.schema.json +0 -61
- package/src/components/diff-viewer/diff-viewer.schema.ts +0 -70
- package/src/components/diff-viewer/diff-viewer.svelte +0 -400
- package/src/components/diff-viewer/diff-viewer.types.ts +0 -56
- package/src/components/diff-viewer/front-matter-header.svelte +0 -137
- package/src/components/diff-viewer/index.ts +0 -5
- package/src/components/markdown-editor/editor-skeleton.svelte +0 -85
- package/src/components/markdown-editor/editor-toolbar/editor-toolbar.svelte +0 -318
- package/src/components/markdown-editor/editor-toolbar/index.ts +0 -18
- package/src/components/markdown-editor/editor-toolbar/link-popover.svelte +0 -314
- package/src/components/markdown-editor/editor-toolbar/toolbar-button.svelte +0 -97
- package/src/components/markdown-editor/editor-toolbar/toolbar-dropdown.svelte +0 -106
- package/src/components/markdown-editor/editor-toolbar/toolbar-separator.svelte +0 -30
- package/src/components/markdown-editor/editor-toolbar/types.ts +0 -15
- package/src/components/markdown-editor/index.ts +0 -10
- package/src/components/markdown-editor/markdown-editor.examples.json +0 -19
- package/src/components/markdown-editor/markdown-editor.schema.json +0 -111
- package/src/components/markdown-editor/markdown-editor.schema.ts +0 -122
- package/src/components/markdown-editor/markdown-editor.svelte +0 -872
- package/src/components/markdown-editor/markdown-editor.types.ts +0 -124
- package/src/components/markdown-editor/markdown-editor.variables.json +0 -1
- package/src/components/markdown-editor/markdown-editor.variables.ts +0 -3
- package/src/components/markdown-editor/prosemirror.css +0 -76
- package/src/components/review-editor/comment-composer.svelte +0 -271
- package/src/components/review-editor/comment-list.svelte +0 -311
- package/src/components/review-editor/comment-sidebar.svelte +0 -449
- package/src/components/review-editor/export-actions.svelte +0 -188
- package/src/components/review-editor/focus-navigation.ts +0 -220
- package/src/components/review-editor/front-matter-fields.svelte +0 -159
- package/src/components/review-editor/index.ts +0 -59
- package/src/components/review-editor/live-region.svelte +0 -109
- package/src/components/review-editor/review-editor-anchors.svelte.ts +0 -219
- package/src/components/review-editor/review-editor-controls.svelte +0 -201
- package/src/components/review-editor/review-editor-exports.ts +0 -145
- package/src/components/review-editor/review-editor-front-matter.ts +0 -237
- package/src/components/review-editor/review-editor-impl.svelte +0 -1509
- package/src/components/review-editor/review-editor-selection-geometry.ts +0 -31
- package/src/components/review-editor/review-editor-selection-types.ts +0 -68
- package/src/components/review-editor/review-editor-selection.svelte.ts +0 -292
- package/src/components/review-editor/review-editor-state.svelte.ts +0 -117
- package/src/components/review-editor/review-editor-threads.svelte.ts +0 -435
- package/src/components/review-editor/review-editor.css +0 -273
- package/src/components/review-editor/review-editor.examples.json +0 -19
- package/src/components/review-editor/review-editor.schema.json +0 -83
- package/src/components/review-editor/review-editor.schema.ts +0 -88
- package/src/components/review-editor/review-editor.svelte +0 -18
- package/src/components/review-editor/review-editor.types.ts +0 -92
- package/src/components/review-editor/review-editor.variables.json +0 -1
- package/src/components/review-editor/review-editor.variables.ts +0 -3
- package/src/components/review-editor/thread-popover.svelte +0 -261
- /package/dist/components/{review-editor/review-editor.css.d.ts → json-editor/json-editor.css.d.ts} +0 -0
- /package/dist/components/{diff-viewer/diff-viewer.schema.d.ts → json-editor/json-editor.schema.d.ts} +0 -0
- /package/dist/components/{diff-viewer/diff-viewer.variables.d.ts → json-editor/json-editor.variables.d.ts} +0 -0
- /package/src/components/{diff-viewer/diff-viewer.variables.json → json-editor/json-editor.variables.json} +0 -0
- /package/src/components/{diff-viewer/diff-viewer.variables.ts → json-editor/json-editor.variables.ts} +0 -0
|
@@ -1,477 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Markdown to HTML rendering pipeline.
|
|
3
|
-
*
|
|
4
|
-
* DEP-49: Chat markdown rendering pipeline + sanitization.
|
|
5
|
-
*
|
|
6
|
-
* This module provides a lightweight, SSR-safe rendering pipeline that:
|
|
7
|
-
* - Parses CommonMark + GFM using the existing document pipeline
|
|
8
|
-
* - Sanitizes HTML output via rehype-sanitize (no DOMParser dependency)
|
|
9
|
-
* - Sanitizes URLs during mdast traversal
|
|
10
|
-
* - Extracts code block metadata for copy hooks
|
|
11
|
-
* - Preserves raw Markdown for copy/export
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```ts
|
|
15
|
-
* import { renderMarkdown } from '$lib/document/rendering';
|
|
16
|
-
*
|
|
17
|
-
* const result = renderMarkdown('# Hello\n\n```js\nconsole.log("hi");\n```');
|
|
18
|
-
* console.log(result.html); // '<h1>Hello</h1>...'
|
|
19
|
-
* console.log(result.codeBlocks[0]); // { language: 'js', value: '...', ... }
|
|
20
|
-
* console.log(result.rawMarkdown); // Original input preserved
|
|
21
|
-
* ```
|
|
22
|
-
*
|
|
23
|
-
* @module
|
|
24
|
-
*/
|
|
25
|
-
import rehypeSanitize from 'rehype-sanitize';
|
|
26
|
-
import rehypeStringify from 'rehype-stringify';
|
|
27
|
-
import remarkGfm from 'remark-gfm';
|
|
28
|
-
import remarkParse from 'remark-parse';
|
|
29
|
-
import remarkRehype from 'remark-rehype';
|
|
30
|
-
import { unified } from 'unified';
|
|
31
|
-
import { visit } from 'unist-util-visit';
|
|
32
|
-
// rehype-katex and remark-math are loaded lazily via mathPluginLoader
|
|
33
|
-
// below — they only enter the graph when probablyHasMath() returns true
|
|
34
|
-
// for a given input. Static imports here would defeat the lazy split.
|
|
35
|
-
// NOTE: KaTeX requires its CSS to be loaded by the consuming application for
|
|
36
|
-
// correct visual rendering. Import the stylesheet in your app entry point:
|
|
37
|
-
// import 'katex/dist/katex.min.css';
|
|
38
|
-
// In SvelteKit this typically goes in src/app.css or a layout component.
|
|
39
|
-
import { extractCodeBlocks } from './extract-code-blocks.js';
|
|
40
|
-
import { getHighlighterSync } from './highlighter.js';
|
|
41
|
-
import { rehypeShikiSync } from './rehype-shiki-sync.js';
|
|
42
|
-
import { createSanitizeSchema } from './sanitize-schema.js';
|
|
43
|
-
import { transformUrls } from './transform-urls.js';
|
|
44
|
-
/**
|
|
45
|
-
* Math-free rendering parser. Constructed lazily so that the unified
|
|
46
|
-
* pipeline machinery only initializes when something actually renders.
|
|
47
|
-
*
|
|
48
|
-
* Stored as `unknown` because unified's `.use()` return type is a
|
|
49
|
-
* narrowly-parameterised `Processor<P1, P2, ...>` that doesn't extend
|
|
50
|
-
* the zero-arg `Processor` interface. The single cast in `getBaseProcessor`
|
|
51
|
-
* documents the constraint; all consumers get a typed reference.
|
|
52
|
-
*/
|
|
53
|
-
let baseProcessor = null;
|
|
54
|
-
function getBaseProcessor() {
|
|
55
|
-
if (!baseProcessor)
|
|
56
|
-
baseProcessor = unified().use(remarkParse).use(remarkGfm);
|
|
57
|
-
// eslint-disable-next-line no-unsafe-type-assertion -- unified's `.use()` returns a narrowly-parameterised `Processor<...>` that doesn't structurally extend the zero-arg `Processor`; see the `baseProcessor` doc comment above.
|
|
58
|
-
return baseProcessor;
|
|
59
|
-
}
|
|
60
|
-
let mathPluginLoader = async () => {
|
|
61
|
-
const [remarkMathModule, rehypeKatexModule] = await Promise.all([
|
|
62
|
-
import('remark-math'),
|
|
63
|
-
import('rehype-katex'),
|
|
64
|
-
]);
|
|
65
|
-
return {
|
|
66
|
-
remarkMath: remarkMathModule.default,
|
|
67
|
-
rehypeKatex: rehypeKatexModule.default,
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
|
-
let mathPluginsPromise = null;
|
|
71
|
-
let mathProcessor = null;
|
|
72
|
-
async function ensureMathPipeline() {
|
|
73
|
-
// Guard against caching a rejected promise. Without this, a transient
|
|
74
|
-
// network error on the first dynamic import would permanently prevent
|
|
75
|
-
// math rendering for the page lifetime, because a rejected Promise is
|
|
76
|
-
// not null and ??= would never attempt a retry.
|
|
77
|
-
if (!mathPluginsPromise) {
|
|
78
|
-
mathPluginsPromise = mathPluginLoader().catch((error) => {
|
|
79
|
-
mathPluginsPromise = null; // allow retry on next render
|
|
80
|
-
throw error;
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
const { remarkMath, rehypeKatex } = await mathPluginsPromise;
|
|
84
|
-
if (!mathProcessor) {
|
|
85
|
-
mathProcessor = unified().use(remarkParse).use(remarkGfm).use(remarkMath);
|
|
86
|
-
}
|
|
87
|
-
// eslint-disable-next-line no-unsafe-type-assertion -- same Processor variance constraint as getBaseProcessor; see the `baseProcessor` doc comment above.
|
|
88
|
-
return { processor: mathProcessor, rehypeKatex };
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Test-only override of the math-plugin loader.
|
|
92
|
-
*
|
|
93
|
-
* Replaces `mathPluginLoader` AND clears the dependent singleton state
|
|
94
|
-
* (`mathPluginsPromise`, `mathProcessor`). Without
|
|
95
|
-
* the singleton reset, a stub installed after a real load would never
|
|
96
|
-
* be called because the cached promise would already be resolved.
|
|
97
|
-
*
|
|
98
|
-
* Returns a cleanup function that restores the previous loader and
|
|
99
|
-
* clears the singleton state again, so subsequent tests start fresh.
|
|
100
|
-
*
|
|
101
|
-
* Not re-exported from packages/markdown/src/rendering/index.ts. Test
|
|
102
|
-
* code imports it via the deep specifier `./render.js` from inside the
|
|
103
|
-
* markdown package's tests.
|
|
104
|
-
*/
|
|
105
|
-
export function __setMathPluginLoaderForTests(loader) {
|
|
106
|
-
const previous = mathPluginLoader;
|
|
107
|
-
mathPluginLoader = loader;
|
|
108
|
-
mathPluginsPromise = null;
|
|
109
|
-
mathProcessor = null;
|
|
110
|
-
return () => {
|
|
111
|
-
mathPluginLoader = previous;
|
|
112
|
-
mathPluginsPromise = null;
|
|
113
|
-
mathProcessor = null;
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Cheap pre-check: does this markdown probably contain math?
|
|
118
|
-
*
|
|
119
|
-
* Strips fenced and inline code first (where `$` is not math), then
|
|
120
|
-
* looks for a `$$` display block or a `$…$` inline-math pair. The
|
|
121
|
-
* inline regex requires the body to start AND end with non-whitespace
|
|
122
|
-
* — that lets us reject prose like "$5 today" while still accepting
|
|
123
|
-
* single-character bodies like `$x$`.
|
|
124
|
-
*
|
|
125
|
-
* False positives (extra chunk load) are tolerable; false negatives
|
|
126
|
-
* silently break math rendering, so the regex errs toward `true` when
|
|
127
|
-
* in doubt.
|
|
128
|
-
*/
|
|
129
|
-
export function probablyHasMath(markdown) {
|
|
130
|
-
if (!markdown.includes('$'))
|
|
131
|
-
return false;
|
|
132
|
-
const codeStripped = markdown
|
|
133
|
-
.replace(/```[\s\S]*?```/g, '')
|
|
134
|
-
.replace(/~~~[\s\S]*?~~~/g, '')
|
|
135
|
-
.replace(/`[^`\n]*`/g, '');
|
|
136
|
-
if (codeStripped.includes('$$'))
|
|
137
|
-
return true;
|
|
138
|
-
// Neutralise escaped backslashes (\\) before testing for an escaped dollar
|
|
139
|
-
// (\$). Without this, `\\$x$` — a literal backslash followed by inline
|
|
140
|
-
// math — is incorrectly rejected: the lookbehind sees the second `\` of
|
|
141
|
-
// `\\` and treats the `$` as escaped, producing a false negative.
|
|
142
|
-
const escaped = codeStripped.replace(/\\\\/g, '');
|
|
143
|
-
return /(?<!\\)\$\S(?:[^$\n]*?\S)?\$/.test(escaped);
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* LRU cache for rendered results.
|
|
147
|
-
*
|
|
148
|
-
* Caches rendering results to avoid redundant processing for the same input.
|
|
149
|
-
* Uses a simple Map with manual eviction when size exceeds limit.
|
|
150
|
-
*/
|
|
151
|
-
const CACHE_SIZE = 50;
|
|
152
|
-
const cache = new Map();
|
|
153
|
-
/**
|
|
154
|
-
* Deterministically stringify render options for cache keys.
|
|
155
|
-
*
|
|
156
|
-
* Ensures that semantically equivalent option objects with different
|
|
157
|
-
* property insertion orders produce the same string representation.
|
|
158
|
-
*/
|
|
159
|
-
function stableStringifyOptions(options) {
|
|
160
|
-
const entries = Object.entries(options).toSorted(([a], [b]) => a.localeCompare(b));
|
|
161
|
-
return entries
|
|
162
|
-
.map(([key, value]) => `${key}:${JSON.stringify(value)}`)
|
|
163
|
-
.join('|');
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Generate a cache key from markdown, options, and highlighter state.
|
|
167
|
-
*
|
|
168
|
-
* Includes highlighter availability to prevent caching unhighlighted results
|
|
169
|
-
* during the brief window before the highlighter is initialized.
|
|
170
|
-
*/
|
|
171
|
-
function getCacheKey(markdown, options, hasHighlighter) {
|
|
172
|
-
return `${markdown}::${stableStringifyOptions(options)}::hl:${hasHighlighter}`;
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Clone a RenderResult to prevent cache corruption from caller mutations.
|
|
176
|
-
*
|
|
177
|
-
* Returns a shallow clone with a new codeBlocks array. The CodeBlockInfo
|
|
178
|
-
* objects themselves are not cloned since they are value objects that
|
|
179
|
-
* callers have no reason to mutate.
|
|
180
|
-
*/
|
|
181
|
-
function cloneResult(result) {
|
|
182
|
-
return {
|
|
183
|
-
rawMarkdown: result.rawMarkdown,
|
|
184
|
-
html: result.html,
|
|
185
|
-
codeBlocks: [...result.codeBlocks],
|
|
186
|
-
hadUnsafeContent: result.hadUnsafeContent,
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Remove raw HTML nodes from mdast.
|
|
191
|
-
*
|
|
192
|
-
* Raw HTML in markdown (e.g., `<script>alert(1)</script>`) is represented
|
|
193
|
-
* as `html` type nodes. We remove these entirely to prevent injection.
|
|
194
|
-
*
|
|
195
|
-
* Uses a Set for O(1) lookup when filtering children arrays.
|
|
196
|
-
*
|
|
197
|
-
* @returns Whether any HTML nodes were removed
|
|
198
|
-
*/
|
|
199
|
-
function removeRawHtmlNodes(root) {
|
|
200
|
-
// Collect nodes to remove using Set for O(1) lookup (can't remove during visit)
|
|
201
|
-
const nodesToRemove = new Set();
|
|
202
|
-
visit(root, 'html', (node) => {
|
|
203
|
-
nodesToRemove.add(node);
|
|
204
|
-
});
|
|
205
|
-
// Remove collected nodes by filtering children
|
|
206
|
-
if (nodesToRemove.size > 0) {
|
|
207
|
-
visit(root, (node) => {
|
|
208
|
-
if ('children' in node && Array.isArray(node.children)) {
|
|
209
|
-
node.children = node.children.filter((child) => !nodesToRemove.has(child));
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
return nodesToRemove.size > 0;
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Strip link nodes from mdast, replacing them with their children (link text).
|
|
217
|
-
*
|
|
218
|
-
* This prevents nested anchor tags when rendering markdown inside anchor elements.
|
|
219
|
-
* The link text is preserved, but the wrapping `<a>` tag is removed.
|
|
220
|
-
*
|
|
221
|
-
* Handles both:
|
|
222
|
-
* - Inline links: `[text](url)`
|
|
223
|
-
* - Reference-style links: `[text][ref]` with `[ref]: url` definitions
|
|
224
|
-
*
|
|
225
|
-
* Note: Only removes definitions that are used by linkReference nodes, not those
|
|
226
|
-
* used by imageReference nodes, to preserve reference-style images.
|
|
227
|
-
*
|
|
228
|
-
* @param root - The mdast root node to transform
|
|
229
|
-
*/
|
|
230
|
-
function stripLinkNodes(root) {
|
|
231
|
-
// Collect identifiers used by linkReference nodes (to remove their definitions)
|
|
232
|
-
const linkRefIdentifiers = new Set();
|
|
233
|
-
visit(root, 'linkReference', (node) => {
|
|
234
|
-
linkRefIdentifiers.add(node.identifier);
|
|
235
|
-
});
|
|
236
|
-
// Also collect identifiers used by imageReference nodes (to preserve their definitions)
|
|
237
|
-
const imageRefIdentifiers = new Set();
|
|
238
|
-
visit(root, 'imageReference', (node) => {
|
|
239
|
-
imageRefIdentifiers.add(node.identifier);
|
|
240
|
-
});
|
|
241
|
-
// Remove definitions that are ONLY used by linkReference nodes, not imageReference.
|
|
242
|
-
// If a definition is shared by both a link and an image, keep it for the image.
|
|
243
|
-
if (linkRefIdentifiers.size > 0) {
|
|
244
|
-
const definitionsToRemove = new Set();
|
|
245
|
-
visit(root, 'definition', (node) => {
|
|
246
|
-
// Only remove if used by a link reference AND NOT by an image reference
|
|
247
|
-
if (linkRefIdentifiers.has(node.identifier) && !imageRefIdentifiers.has(node.identifier)) {
|
|
248
|
-
definitionsToRemove.add(node);
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
if (definitionsToRemove.size > 0) {
|
|
252
|
-
visit(root, (node) => {
|
|
253
|
-
if ('children' in node && Array.isArray(node.children)) {
|
|
254
|
-
node.children = node.children.filter((child) => !definitionsToRemove.has(child));
|
|
255
|
-
}
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
// Then handle link and linkReference nodes
|
|
260
|
-
visit(root, (node, index, parent) => {
|
|
261
|
-
if (parent && typeof index === 'number') {
|
|
262
|
-
if (node.type === 'link') {
|
|
263
|
-
const linkNode = node;
|
|
264
|
-
const parentNode = parent;
|
|
265
|
-
// Replace link node with its children (the link text)
|
|
266
|
-
parentNode.children.splice(index, 1, ...linkNode.children);
|
|
267
|
-
// Return index to revisit the same position since we replaced nodes
|
|
268
|
-
return index;
|
|
269
|
-
}
|
|
270
|
-
if (node.type === 'linkReference') {
|
|
271
|
-
const linkRefNode = node;
|
|
272
|
-
const parentNode = parent;
|
|
273
|
-
// Replace linkReference node with its children (the link text)
|
|
274
|
-
parentNode.children.splice(index, 1, ...linkRefNode.children);
|
|
275
|
-
return index;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
return undefined;
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* Internal core that does the rendering work, given a parsed mdast and an
|
|
283
|
-
* already-loaded rehype-katex (or null for the no-math path). Shared by
|
|
284
|
-
* the sync `renderMarkdown` and async `renderMarkdownWithMath` entry points
|
|
285
|
-
* so the pipeline only lives in one place.
|
|
286
|
-
*/
|
|
287
|
-
function renderFromMdast(markdown, options, mdast, rehypeKatex) {
|
|
288
|
-
// Remove raw HTML nodes
|
|
289
|
-
const hadHtmlNodes = removeRawHtmlNodes(mdast);
|
|
290
|
-
// Sanitize URLs
|
|
291
|
-
const { hadUnsafeUrls } = transformUrls(mdast, {
|
|
292
|
-
allowDataImages: options.allowDataImages ?? false,
|
|
293
|
-
});
|
|
294
|
-
// Strip links if requested (to prevent nested anchors)
|
|
295
|
-
if (options.stripLinks) {
|
|
296
|
-
stripLinkNodes(mdast);
|
|
297
|
-
}
|
|
298
|
-
// Extract code block metadata before conversion
|
|
299
|
-
const codeBlocks = extractCodeBlocks(mdast);
|
|
300
|
-
// Create sanitization schema
|
|
301
|
-
const schema = createSanitizeSchema({
|
|
302
|
-
allowDataImages: options.allowDataImages ?? false,
|
|
303
|
-
});
|
|
304
|
-
// Convert mdast to hast
|
|
305
|
-
const hast = unified().use(remarkRehype, { allowDangerousHtml: false }).runSync(mdast);
|
|
306
|
-
// Render math nodes (inlineMath / math) to KaTeX HTML, only if the math
|
|
307
|
-
// pipeline has been loaded. rehype-katex defaults: throwOnError=false
|
|
308
|
-
// (invalid LaTeX becomes error markup).
|
|
309
|
-
const mathRenderedHast = rehypeKatex === null
|
|
310
|
-
? hast
|
|
311
|
-
: unified()
|
|
312
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any, no-unsafe-type-assertion -- rehype-katex's plugin signature is opaque after dynamic import; unified's `.use()` can't type-check a runtime-loaded plugin.
|
|
313
|
-
.use(rehypeKatex)
|
|
314
|
-
.runSync(hast);
|
|
315
|
-
// Apply syntax highlighting to code blocks. If the highlighter isn't
|
|
316
|
-
// initialized yet, code blocks are left unhighlighted — the highlighter
|
|
317
|
-
// initializes lazily on first getHighlighter() call.
|
|
318
|
-
const highlightedHast = unified()
|
|
319
|
-
.use(rehypeShikiSync, { theme: 'depict', defaultLanguage: 'plaintext' })
|
|
320
|
-
// eslint-disable-next-line no-unsafe-type-assertion -- unified's `runSync` returns the broad unist `Node`; the remark→rehype pipeline guarantees a hast `Root` here.
|
|
321
|
-
.runSync(mathRenderedHast);
|
|
322
|
-
// Sanitize the hast - MUST use runSync() to execute the transform
|
|
323
|
-
// Note: stringify() only runs the compiler, not transforms, so we need
|
|
324
|
-
// to run sanitization explicitly before stringifying
|
|
325
|
-
const sanitizedHast = unified()
|
|
326
|
-
.use(rehypeSanitize, schema)
|
|
327
|
-
// eslint-disable-next-line no-unsafe-type-assertion -- unified's `runSync` returns the broad unist `Node`; the prior rehype steps guarantee a hast `Root` here.
|
|
328
|
-
.runSync(highlightedHast);
|
|
329
|
-
// Stringify the sanitized hast to HTML.
|
|
330
|
-
// useNamedReferences: true makes rehype-stringify emit & instead of &
|
|
331
|
-
// for & in text nodes. Without this, & in highlighted code (from Shiki's
|
|
332
|
-
// & output decoded back to &) would be re-encoded as & — which
|
|
333
|
-
// browsers render correctly but which is unnecessarily verbose.
|
|
334
|
-
const html = unified()
|
|
335
|
-
.use(rehypeStringify, { characterReferences: { useNamedReferences: true } })
|
|
336
|
-
.stringify(sanitizedHast);
|
|
337
|
-
return {
|
|
338
|
-
rawMarkdown: markdown,
|
|
339
|
-
html: String(html),
|
|
340
|
-
codeBlocks,
|
|
341
|
-
hadUnsafeContent: hadHtmlNodes || hadUnsafeUrls,
|
|
342
|
-
};
|
|
343
|
-
}
|
|
344
|
-
/**
|
|
345
|
-
* Render markdown to sanitized HTML — synchronous, no math.
|
|
346
|
-
*
|
|
347
|
-
* Math syntax (`$…$`, `$$…$$`) passes through as raw text. Callers that
|
|
348
|
-
* need math support must use `renderMarkdownWithMath` instead, which gates
|
|
349
|
-
* the math plugins behind a dynamic import.
|
|
350
|
-
*
|
|
351
|
-
* This is an intentional internal behavior change: before code splitting,
|
|
352
|
-
* sync `renderMarkdown` rendered math eagerly because remark-math and
|
|
353
|
-
* rehype-katex were statically imported. Switching to async shaves ~200 KB
|
|
354
|
-
* off the chat entry chunk for math-free messages, which is the common case.
|
|
355
|
-
*
|
|
356
|
-
* Pipeline:
|
|
357
|
-
* 1. Parse markdown to mdast using CommonMark + GFM (no math)
|
|
358
|
-
* 2. Remove raw HTML nodes (injection prevention)
|
|
359
|
-
* 3. Sanitize URLs in link/image nodes
|
|
360
|
-
* 4. Extract code block metadata
|
|
361
|
-
* 5. Convert mdast to hast via remark-rehype
|
|
362
|
-
* 6. Apply Shiki syntax highlighting (if highlighter is initialized)
|
|
363
|
-
* 7. Sanitize hast via rehype-sanitize
|
|
364
|
-
* 8. Stringify hast to HTML
|
|
365
|
-
*
|
|
366
|
-
* @param markdown - Raw markdown string
|
|
367
|
-
* @param options - Rendering options
|
|
368
|
-
* @returns Render result with HTML, code blocks, and safety flags
|
|
369
|
-
*/
|
|
370
|
-
export function renderMarkdown(markdown, options = {}) {
|
|
371
|
-
// Handle empty/null input
|
|
372
|
-
if (!markdown || typeof markdown !== 'string') {
|
|
373
|
-
return {
|
|
374
|
-
rawMarkdown: markdown ?? '',
|
|
375
|
-
html: '',
|
|
376
|
-
codeBlocks: [],
|
|
377
|
-
hadUnsafeContent: false,
|
|
378
|
-
};
|
|
379
|
-
}
|
|
380
|
-
// Check cache (include highlighter state to prevent caching unhighlighted results)
|
|
381
|
-
const hasHighlighter = getHighlighterSync() !== null;
|
|
382
|
-
const cacheKey = getCacheKey(markdown, options, hasHighlighter);
|
|
383
|
-
const cached = cache.get(cacheKey);
|
|
384
|
-
if (cached) {
|
|
385
|
-
// Move to end (LRU behavior)
|
|
386
|
-
cache.delete(cacheKey);
|
|
387
|
-
cache.set(cacheKey, cached);
|
|
388
|
-
// Return a clone to prevent caller mutations from corrupting the cache
|
|
389
|
-
return cloneResult(cached);
|
|
390
|
-
}
|
|
391
|
-
// Parse markdown to mdast (no math).
|
|
392
|
-
// eslint-disable-next-line no-unsafe-type-assertion -- unified's `parse()` is typed as the broad unist `Node`; a remark-parse processor always yields an mdast `Root`.
|
|
393
|
-
const mdast = getBaseProcessor().parse(markdown);
|
|
394
|
-
const result = renderFromMdast(markdown, options, mdast, null);
|
|
395
|
-
// Add to cache (with LRU eviction)
|
|
396
|
-
if (cache.size >= CACHE_SIZE) {
|
|
397
|
-
// Delete oldest entry (first key in Map iteration order)
|
|
398
|
-
const firstKey = cache.keys().next().value;
|
|
399
|
-
if (firstKey !== undefined) {
|
|
400
|
-
cache.delete(firstKey);
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
cache.set(cacheKey, result);
|
|
404
|
-
// Return a clone to prevent caller mutations from corrupting the cache
|
|
405
|
-
// (same protection as cache-hit path)
|
|
406
|
-
return cloneResult(result);
|
|
407
|
-
}
|
|
408
|
-
/**
|
|
409
|
-
* Render markdown to sanitized HTML — async, with math support.
|
|
410
|
-
*
|
|
411
|
-
* Behaves identically to `renderMarkdown` for math-free input. When the
|
|
412
|
-
* input contains `$…$` or `$$…$$`, dynamically imports `remark-math` and
|
|
413
|
-
* `rehype-katex` (one-time, cached for the page lifetime), parses with
|
|
414
|
-
* the math-aware processor, and renders math nodes via KaTeX.
|
|
415
|
-
*
|
|
416
|
-
* This is the entry point chat / preview surfaces should call when math
|
|
417
|
-
* may be in the content. The dynamic import is what keeps the math
|
|
418
|
-
* pipeline out of the initial bundle.
|
|
419
|
-
*
|
|
420
|
-
* @param markdown - Raw markdown string
|
|
421
|
-
* @param options - Rendering options
|
|
422
|
-
* @returns Promise resolving to a render result
|
|
423
|
-
*/
|
|
424
|
-
export async function renderMarkdownWithMath(markdown, options = {}) {
|
|
425
|
-
if (!markdown || typeof markdown !== 'string') {
|
|
426
|
-
return {
|
|
427
|
-
rawMarkdown: markdown ?? '',
|
|
428
|
-
html: '',
|
|
429
|
-
codeBlocks: [],
|
|
430
|
-
hadUnsafeContent: false,
|
|
431
|
-
};
|
|
432
|
-
}
|
|
433
|
-
// Fast path: no math → use the sync, no-math pipeline. The caller still
|
|
434
|
-
// pays the await/microtask cost but no math chunk loads.
|
|
435
|
-
if (!probablyHasMath(markdown)) {
|
|
436
|
-
return renderMarkdown(markdown, options);
|
|
437
|
-
}
|
|
438
|
-
const { processor, rehypeKatex } = await ensureMathPipeline();
|
|
439
|
-
// Sample hasHighlighter AFTER the math-pipeline await. If the Shiki
|
|
440
|
-
// highlighter initialised during that await, the cache key must reflect the
|
|
441
|
-
// post-await state so that the stored result matches what renderFromMdast
|
|
442
|
-
// actually produced. Sampling before the await would key the result as
|
|
443
|
-
// "unhighlighted" even when the render was highlighted, causing a stale
|
|
444
|
-
// cache hit on the next pre-init call and a spurious cache miss on the
|
|
445
|
-
// first post-init call.
|
|
446
|
-
const hasHighlighter = getHighlighterSync() !== null;
|
|
447
|
-
// Use a null-byte separator (\0) to prevent the math-path key from
|
|
448
|
-
// colliding with the sync-path key for markdown that starts with "math::".
|
|
449
|
-
// Null bytes cannot appear in user-supplied markdown strings, so \0math\0
|
|
450
|
-
// is a guaranteed-disjoint namespace from the bare getCacheKey() keys used
|
|
451
|
-
// by renderMarkdown.
|
|
452
|
-
const cacheKey = `\0math\0${getCacheKey(markdown, options, hasHighlighter)}`;
|
|
453
|
-
const cached = cache.get(cacheKey);
|
|
454
|
-
if (cached) {
|
|
455
|
-
cache.delete(cacheKey);
|
|
456
|
-
cache.set(cacheKey, cached);
|
|
457
|
-
return cloneResult(cached);
|
|
458
|
-
}
|
|
459
|
-
// eslint-disable-next-line no-unsafe-type-assertion -- unified's `parse()` is typed as the broad unist `Node`; a remark-parse processor always yields an mdast `Root`.
|
|
460
|
-
const mdast = processor.parse(markdown);
|
|
461
|
-
const result = renderFromMdast(markdown, options, mdast, rehypeKatex);
|
|
462
|
-
if (cache.size >= CACHE_SIZE) {
|
|
463
|
-
const firstKey = cache.keys().next().value;
|
|
464
|
-
if (firstKey !== undefined)
|
|
465
|
-
cache.delete(firstKey);
|
|
466
|
-
}
|
|
467
|
-
cache.set(cacheKey, result);
|
|
468
|
-
return cloneResult(result);
|
|
469
|
-
}
|
|
470
|
-
/**
|
|
471
|
-
* Clear the render cache.
|
|
472
|
-
*
|
|
473
|
-
* Useful for testing or memory management.
|
|
474
|
-
*/
|
|
475
|
-
export function clearRenderCache() {
|
|
476
|
-
cache.clear();
|
|
477
|
-
}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sanitization schema for rehype-sanitize.
|
|
3
|
-
*
|
|
4
|
-
* DEP-49: SSR-safe HTML sanitization for chat markdown rendering.
|
|
5
|
-
*
|
|
6
|
-
* This schema matches the behavior of `src/lib/editor/sanitize-html.ts`
|
|
7
|
-
* but operates on the hast AST instead of using DOMParser, making it SSR-safe.
|
|
8
|
-
*
|
|
9
|
-
* @module
|
|
10
|
-
*/
|
|
11
|
-
import { defaultSchema } from 'hast-util-sanitize';
|
|
12
|
-
/**
|
|
13
|
-
* Protocols allowed in href/src attributes.
|
|
14
|
-
*/
|
|
15
|
-
const ALLOWED_PROTOCOLS = ['http', 'https', 'mailto', 'tel'];
|
|
16
|
-
/**
|
|
17
|
-
* Tags that are explicitly blocked (dangerous for XSS).
|
|
18
|
-
*/
|
|
19
|
-
const BLOCKED_TAGS = ['script', 'style', 'iframe', 'object', 'embed', 'link', 'meta'];
|
|
20
|
-
/**
|
|
21
|
-
* MathML element names produced by KaTeX's MathML output layer.
|
|
22
|
-
*
|
|
23
|
-
* KaTeX renders math in two passes: an HTML pass (for visual layout) and a
|
|
24
|
-
* MathML pass (for accessibility/screen readers). Both must be allowed through
|
|
25
|
-
* sanitization or the output will be stripped.
|
|
26
|
-
*/
|
|
27
|
-
const KATEX_MATHML_TAGS = [
|
|
28
|
-
'math',
|
|
29
|
-
'semantics',
|
|
30
|
-
'mrow',
|
|
31
|
-
'mi',
|
|
32
|
-
'mo',
|
|
33
|
-
'mn',
|
|
34
|
-
'msup',
|
|
35
|
-
'msub',
|
|
36
|
-
'mfrac',
|
|
37
|
-
'mtext',
|
|
38
|
-
'annotation',
|
|
39
|
-
'mover',
|
|
40
|
-
'munder',
|
|
41
|
-
'munderover',
|
|
42
|
-
'msqrt',
|
|
43
|
-
'mroot',
|
|
44
|
-
'mpadded',
|
|
45
|
-
'mphantom',
|
|
46
|
-
'mtable',
|
|
47
|
-
'mtr',
|
|
48
|
-
'mtd',
|
|
49
|
-
'mspace',
|
|
50
|
-
];
|
|
51
|
-
/**
|
|
52
|
-
* Create a sanitization schema for rehype-sanitize.
|
|
53
|
-
*
|
|
54
|
-
* @param options - Configuration options
|
|
55
|
-
* @returns Schema compatible with rehype-sanitize
|
|
56
|
-
*/
|
|
57
|
-
export function createSanitizeSchema(options = {}) {
|
|
58
|
-
const { allowDataImages = false } = options;
|
|
59
|
-
// Build protocol list for images (optionally include data:)
|
|
60
|
-
const imageProtocols = allowDataImages ? [...ALLOWED_PROTOCOLS, 'data'] : ALLOWED_PROTOCOLS;
|
|
61
|
-
return {
|
|
62
|
-
...defaultSchema,
|
|
63
|
-
// Explicitly block dangerous tags, and add KaTeX MathML elements
|
|
64
|
-
tagNames: [
|
|
65
|
-
...(defaultSchema.tagNames ?? []).filter((tag) => !BLOCKED_TAGS.includes(tag)),
|
|
66
|
-
...KATEX_MATHML_TAGS,
|
|
67
|
-
],
|
|
68
|
-
// Strip all attributes by default, then allowlist specific ones
|
|
69
|
-
attributes: {
|
|
70
|
-
...defaultSchema.attributes,
|
|
71
|
-
// Allow class for styling (used by code blocks and KaTeX spans)
|
|
72
|
-
'*': ['className'],
|
|
73
|
-
// Links: allow href with safe protocols
|
|
74
|
-
// Note: target/rel intentionally omitted to prevent tabnapping attacks
|
|
75
|
-
a: ['href', 'title'],
|
|
76
|
-
// Images: allow src with safe protocols (optionally data:)
|
|
77
|
-
img: ['src', 'alt', 'title', 'width', 'height'],
|
|
78
|
-
// Code blocks: allow language class, style (for Shiki highlighting), and data-language
|
|
79
|
-
// Note: style is limited to Shiki's color/background-color output by the highlighter
|
|
80
|
-
code: ['className', 'style'],
|
|
81
|
-
pre: ['className', 'style', 'dataLanguage', 'tabIndex'],
|
|
82
|
-
// Spans: allow style for Shiki token colors and KaTeX sizing/spacing
|
|
83
|
-
span: ['className', 'style'],
|
|
84
|
-
// Tables
|
|
85
|
-
table: ['className'],
|
|
86
|
-
th: ['align', 'valign', 'scope'],
|
|
87
|
-
td: ['align', 'valign'],
|
|
88
|
-
// KaTeX MathML: math element needs xmlns for proper MathML rendering
|
|
89
|
-
math: ['xmlns', 'display'],
|
|
90
|
-
// KaTeX MathML: annotation carries the original LaTeX source for copy/accessibility
|
|
91
|
-
annotation: ['encoding'],
|
|
92
|
-
},
|
|
93
|
-
// Protocol allowlists
|
|
94
|
-
protocols: {
|
|
95
|
-
href: ALLOWED_PROTOCOLS,
|
|
96
|
-
src: imageProtocols,
|
|
97
|
-
},
|
|
98
|
-
// Strip dangerous tags entirely
|
|
99
|
-
strip: BLOCKED_TAGS,
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Default sanitization schema (no data: URLs for images).
|
|
104
|
-
*/
|
|
105
|
-
export const sanitizeSchema = createSanitizeSchema();
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* URL sanitization transform for mdast.
|
|
3
|
-
*
|
|
4
|
-
* DEP-49: Sanitize URLs during mdast traversal before conversion to hast.
|
|
5
|
-
*
|
|
6
|
-
* This integrates with the existing `src/lib/utilities/safe-url.ts` utilities
|
|
7
|
-
* to catch dangerous URLs at the source level.
|
|
8
|
-
*
|
|
9
|
-
* @module
|
|
10
|
-
*/
|
|
11
|
-
import { visit } from 'unist-util-visit';
|
|
12
|
-
import { isSafeUrl } from '../utilities/safe-url.js';
|
|
13
|
-
/**
|
|
14
|
-
* Sanitize URLs in link, image, and definition nodes.
|
|
15
|
-
*
|
|
16
|
-
* - For unsafe links: replaces URL with `#` (link becomes inert)
|
|
17
|
-
* - For unsafe images: replaces URL with `''` (shows alt text only)
|
|
18
|
-
* - For unsafe definitions: replaces URL with `#` (reference-style links become inert)
|
|
19
|
-
*
|
|
20
|
-
* Definition nodes are used for reference-style links like `[text][ref]` with
|
|
21
|
-
* `[ref]: javascript:alert(1)`. These must be sanitized at the mdast level
|
|
22
|
-
* to correctly set the hadUnsafeUrls flag.
|
|
23
|
-
*
|
|
24
|
-
* @param root - mdast Root node
|
|
25
|
-
* @param options - URL validation options
|
|
26
|
-
* @returns Transform result with hadUnsafeUrls flag
|
|
27
|
-
*/
|
|
28
|
-
export function transformUrls(root, options = {}) {
|
|
29
|
-
let hadUnsafeUrls = false;
|
|
30
|
-
visit(root, 'link', (node) => {
|
|
31
|
-
if (!isSafeUrl(node.url, options)) {
|
|
32
|
-
node.url = '#';
|
|
33
|
-
hadUnsafeUrls = true;
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
visit(root, 'image', (node) => {
|
|
37
|
-
if (!isSafeUrl(node.url, options)) {
|
|
38
|
-
node.url = '';
|
|
39
|
-
hadUnsafeUrls = true;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
// Handle reference-style links: [text][ref] with [ref]: url
|
|
43
|
-
// The URL is stored in a definition node, not the link node itself
|
|
44
|
-
visit(root, 'definition', (node) => {
|
|
45
|
-
if (!isSafeUrl(node.url, options)) {
|
|
46
|
-
node.url = '#';
|
|
47
|
-
hadUnsafeUrls = true;
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
return { root, hadUnsafeUrls };
|
|
51
|
-
}
|