Types: - NoteType: 'daily' ajouté - PROPERTY_TYPES: 'relation' ajouté - SlashItem: isFavorite? ajouté - SuggestChartsResponse: error? ajouté Fixes propres: - import/route: Date | null → ?? undefined (3 occ) - notes/route: JSON.stringify sur checkItems/labels - user/export: b.title → b.seedIdea, Buffer → Uint8Array - study-plan: language column inexistante → défaut 'fr' - notebooks/[id]: parentId → parent connect/disconnect - brainstorm convert/finalize: async callback - next.config: @ts-expect-error inutile supprimé - ai-settings: revalidateTag(tag, 'default') Casts (TipTap/Prisma, safe at runtime): - tiptap-chart/math extensions: InputRule/options as any - chat/route: system messages as any - note-graph-view: ForceGraph2D as any - property-value-editor: relation comparison - sanitize-content: TrustedHTML cast
56 lines
2.2 KiB
TypeScript
56 lines
2.2 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 as any) as unknown as string
|
|
}
|
|
|
|
export function sanitizeRichHtml(html: string): string {
|
|
if (!html) return ''
|
|
return DOMPurify.sanitize(html, { USE_PROFILES: { html: true } })
|
|
}
|
|
|
|
/** Sanitisation pages publiées — préserve le HTML généré par KaTeX (MathML + spans). */
|
|
const KATEX_MATH_TAGS = [
|
|
'math', 'semantics', 'mrow', 'mi', 'mo', 'mn', 'msup', 'msub', 'mfrac', 'msqrt',
|
|
'mroot', 'mtext', 'mspace', 'mstyle', 'mpadded', 'mphantom', 'menclose',
|
|
'mover', 'munder', 'munderover', 'mtable', 'mtr', 'mtd', 'mlabeledtr',
|
|
'annotation', 'maligngroup', 'malignmark',
|
|
] as const
|
|
|
|
const KATEX_MATH_ATTR = [
|
|
'xmlns', 'display', 'mathvariant', 'mathsize', 'mathcolor', 'dir',
|
|
'columnalign', 'rowalign', 'columnspacing', 'rowspacing', 'stretchy',
|
|
'symmetric', 'maxsize', 'minsize', 'largeop', 'movablelimits', 'accent',
|
|
'accentunder', 'fence', 'separator', 'lspace', 'rspace', 'depth', 'height',
|
|
'width', 'displaystyle', 'scriptlevel', 'class', 'style', 'aria-hidden',
|
|
'encoding', 'data-latex',
|
|
] as const
|
|
|
|
export function sanitizePublishedHtml(html: string): string {
|
|
if (!html) return ''
|
|
return DOMPurify.sanitize(html, {
|
|
USE_PROFILES: { html: true },
|
|
ADD_TAGS: [...KATEX_MATH_TAGS],
|
|
ADD_ATTR: [...KATEX_MATH_ATTR],
|
|
})
|
|
}
|