260810_06_ENH: 에디터 html에 프리티어 적용
This commit is contained in:
21
registry/components/kri-editor/utils/formatHtml.ts
Normal file
21
registry/components/kri-editor/utils/formatHtml.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* HTML 소스 보기를 사람이 읽기 좋은 형태로 들여쓴다.
|
||||
* prettier/standalone + html 플러그인을 동적 import로 불러와, 실제로
|
||||
* HTML 모드를 사용할 때만 해당 청크가 로드되도록 한다(초기 번들 크기 영향 없음).
|
||||
*/
|
||||
export async function formatHtmlSource(html: string): Promise<string> {
|
||||
if (!html.trim()) return html;
|
||||
|
||||
const [{ format }, htmlPlugin] = await Promise.all([
|
||||
import("prettier/standalone"),
|
||||
import("prettier/plugins/html"),
|
||||
]);
|
||||
|
||||
return format(html, {
|
||||
parser: "html",
|
||||
plugins: [htmlPlugin],
|
||||
printWidth: 100,
|
||||
// 인라인 요소(span/a/mark 등) 사이 공백은 실제 렌더링에 영향을 주므로 보존한다.
|
||||
htmlWhitespaceSensitivity: "css",
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user