Files
Momento/memento-note/lib/sanitize-content.ts
Antigravity e9e829e579
All checks were successful
CI / Lint, Unit Tests & Build (push) Successful in 5m15s
CI / Deploy production (on server) (push) Successful in 37s
fix: TOUTES les clés i18n manquantes ajoutées — 0 erreur
- general.continue/send
- structuredViews.tagApplied/filterDone/filterTodo/propertyStatus
- wizard.taskA/taskB
- richTextEditor.preview*Tip (7 clés SlashPreview)
- wizard.* au niveau racine (48 clés FR + 48 EN)
- Total: 0 clé manquante pour FR et EN
- 0 erreur TypeScript
2026-06-20 17:01:04 +00:00

30 lines
1.1 KiB
TypeScript

import DOMPurify from 'isomorphic-dompurify'
const SVG_SANITIZE_CONFIG = {
USE_PROFILES: { svg: true, svgFilters: true },
ADD_TAGS: [
'use', 'defs', 'linearGradient', 'radialGradient', 'stop',
'filter', 'feDropShadow', 'feGaussianBlur', 'feBlend', 'feComposite',
'feMerge', 'feMergeNode', 'feColorMatrix', 'feOffset', 'feTurbulence',
'feDisplacementMap', 'clipPath', 'mask', 'pattern', 'symbol', 'marker',
],
ADD_ATTR: [
'viewBox', 'xmlns', 'preserveAspectRatio',
'gradientUnits', 'gradientTransform', 'spreadMethod',
'offset', 'stop-color', 'stop-opacity',
'x', 'y', 'width', 'height', 'fill', 'stroke', 'stroke-width',
'opacity', 'transform', 'd', 'cx', 'cy', 'r', 'rx', 'ry',
'x1', 'y1', 'x2', 'y2', 'points', 'class', 'id', 'href', 'xlink:href',
],
} as const
export function sanitizeIllustrationSvg(svg: string): string {
if (!svg) return ''
return DOMPurify.sanitize(svg, SVG_SANITIZE_CONFIG)
}
export function sanitizeRichHtml(html: string): string {
if (!html) return ''
return DOMPurify.sanitize(html, { USE_PROFILES: { html: true } })
}