260803_02_ENH: kri editor에서 preview에서도 줄바꿈 보여지게 수정
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "kri-ui-registry",
|
||||
"version": "0.9.8",
|
||||
"version": "0.9.9",
|
||||
"private": true,
|
||||
"description": "KRI internal shadcn UI registry",
|
||||
"scripts": {
|
||||
|
||||
@@ -26,6 +26,7 @@ import { FontSize } from "./extensions/font-size";
|
||||
import { Div } from "./extensions/div";
|
||||
import { compressImage } from "./utils/imageCompression";
|
||||
import { sanitizeHtml } from "./utils/sanitizeHtml";
|
||||
import { preserveEmptyParagraphs } from "./utils/emptyParagraph";
|
||||
import { applyLinkPreviewClass, KRI_EDITOR_LINK_CLASS } from "./utils/linkPreview";
|
||||
import { Toolbar } from "./toolbar/Toolbar";
|
||||
import { useDebouncedChange } from "./hooks/useDebouncedChange";
|
||||
@@ -192,7 +193,7 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
|
||||
if (viewRef.current === "html") return;
|
||||
const nextHtml = editor.getHTML();
|
||||
setPreviewSource(nextHtml);
|
||||
scheduleChange(nextHtml);
|
||||
scheduleChange(preserveEmptyParagraphs(nextHtml));
|
||||
},
|
||||
|
||||
editorProps: {
|
||||
@@ -444,7 +445,7 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
|
||||
const safe = sanitizeHtmlOpt ? sanitizeHtml(raw, allowedCustomHtml) : raw;
|
||||
|
||||
editor.commands.setContent(safe, { emitUpdate: false, parseOptions: { preserveWhitespace: "full" } });
|
||||
flushChange(editor.getHTML());
|
||||
flushChange(preserveEmptyParagraphs(editor.getHTML()));
|
||||
setView("wysiwyg");
|
||||
}, [allowedCustomHtml, editor, flushChange, sanitizeHtmlOpt]);
|
||||
|
||||
@@ -506,8 +507,8 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
|
||||
if (!editor) return;
|
||||
|
||||
const onBlur = () => {
|
||||
if (viewRef.current === "html") flushChange(htmlDraftRef.current);
|
||||
else flushChange(editor.getHTML());
|
||||
if (viewRef.current === "html") flushChange(preserveEmptyParagraphs(htmlDraftRef.current));
|
||||
else flushChange(preserveEmptyParagraphs(editor.getHTML()));
|
||||
};
|
||||
|
||||
editor.on("blur", onBlur);
|
||||
@@ -542,7 +543,7 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
|
||||
if (!editor) return;
|
||||
restoreSelection();
|
||||
editor.chain().focus().insertContent(text).run();
|
||||
flushChange(editor.getHTML());
|
||||
flushChange(preserveEmptyParagraphs(editor.getHTML()));
|
||||
},
|
||||
}),
|
||||
[editor, restoreSelection, flushChange, insertTextareaText]
|
||||
@@ -563,7 +564,8 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
|
||||
}, [command, editor, props.onCommandReady]);
|
||||
|
||||
const previewHtml = useMemo(() => {
|
||||
const sanitized = sanitizeHtmlOpt ? sanitizeHtml(previewSource, allowedCustomHtml) : previewSource;
|
||||
const preserved = preserveEmptyParagraphs(previewSource);
|
||||
const sanitized = sanitizeHtmlOpt ? sanitizeHtml(preserved, allowedCustomHtml) : preserved;
|
||||
const withLinkStyle = applyLinkPreviewClass(sanitized);
|
||||
return transformPreviewHtml ? transformPreviewHtml(withLinkStyle) : withLinkStyle;
|
||||
}, [allowedCustomHtml, previewSource, sanitizeHtmlOpt, transformPreviewHtml]);
|
||||
|
||||
9
registry/components/kri-editor/utils/emptyParagraph.ts
Normal file
9
registry/components/kri-editor/utils/emptyParagraph.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
const EMPTY_PARAGRAPH_PATTERN = /<p((?:\s+[^>]*)?)>\s*<\/p>/gi;
|
||||
|
||||
/**
|
||||
* TipTap이 빈 줄을 <p></p>로 직렬화하면 이메일 클라이언트에서 margin collapse로 사라진다.
|
||||
* 눈에 보이지 않는 콘텐츠( )를 채워 실제 발송 HTML에서도 빈 줄이 유지되게 한다.
|
||||
*/
|
||||
export function preserveEmptyParagraphs(html: string): string {
|
||||
return html.replace(EMPTY_PARAGRAPH_PATTERN, (_match, attrs: string) => `<p${attrs}> </p>`);
|
||||
}
|
||||
@@ -412,11 +412,21 @@
|
||||
"type": "registry:component",
|
||||
"target": "@components/kri-editor/utils/editorTypeGuards.ts"
|
||||
},
|
||||
{
|
||||
"path": "kri-editor/utils/emptyParagraph.ts",
|
||||
"type": "registry:component",
|
||||
"target": "@components/kri-editor/utils/emptyParagraph.ts"
|
||||
},
|
||||
{
|
||||
"path": "kri-editor/utils/imageCompression.ts",
|
||||
"type": "registry:component",
|
||||
"target": "@components/kri-editor/utils/imageCompression.ts"
|
||||
},
|
||||
{
|
||||
"path": "kri-editor/utils/linkPreview.ts",
|
||||
"type": "registry:component",
|
||||
"target": "@components/kri-editor/utils/linkPreview.ts"
|
||||
},
|
||||
{
|
||||
"path": "kri-editor/utils/sanitizeHtml.ts",
|
||||
"type": "registry:component",
|
||||
|
||||
Reference in New Issue
Block a user