260803_01_ENH: 에디터에 QR 코드 삽입 추가

This commit is contained in:
2026-08-03 15:15:04 +09:00
parent 605d2dba49
commit a28981099f
18 changed files with 665 additions and 38 deletions

View File

@@ -2,27 +2,41 @@
import DOMPurify from "dompurify";
const HTML_PROFILE = {
USE_PROFILES: {
html: true,
},
} as const;
export type SanitizeHtmlOptions = {
tags?: string[];
attributes?: string[];
};
export function sanitizeHtml(
input: string,
options?: SanitizeHtmlOptions,
): string {
if (!input) {
return "";
}
// DOMPurify는 window/document가 있어야 동작한다. Next.js는 "use client" 컴포넌트도
// 최초 HTML을 만들 때 서버에서 한 번 실행하므로, SSR 단계에서는 sanitize를 건너뛴다.
// (이 값은 하이드레이션 후 클라이언트에서 다시 렌더링되며 정상적으로 sanitize된다.)
if (typeof window === "undefined") {
return input;
}
return DOMPurify.sanitize(
input,
HTML_PROFILE,
{
USE_PROFILES: {
html: true,
},
ADD_TAGS: options?.tags ?? [],
ADD_ATTR: options?.attributes ?? [],
},
);
}
export function sanitizeHtmlForPreview(
input: string,
options?: SanitizeHtmlOptions,
): string {
return sanitizeHtml(input);
return sanitizeHtml(input, options);
}