char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

Aleksander Grygierui: Constants refactor (#26908)e21152dc9

char/aliceai-t5-moe
734 B22 linesraw
1import { SVG } from '$lib/constants';
2import DOMPurify from 'dompurify';
3
4/**
5 * Sanitizes a raw svg string for safe inline rendering.
6 * Returns the cleaned svg markup, or an empty string when the input is not a
7 * usable svg, exceeds the size ceiling, or sanitizes to nothing. An empty
8 * return tells the caller to keep the raw code block instead of rendering.
9 */
10export function sanitizeSvg(source: string): string {
11	const trimmed = source.trim();
12
13	if (!trimmed || trimmed.length > SVG.MAX_BYTES) return '';
14
15	if (!trimmed.startsWith(SVG.TAG_PREFIX)) return '';
16
17	const clean = DOMPurify.sanitize(trimmed, SVG.SANITIZE_CONFIG) as unknown as string;
18
19	if (!clean || !clean.includes(SVG.TAG_PREFIX)) return '';
20
21	return clean;
22}