13 lines
732 B
TypeScript
Executable File
13 lines
732 B
TypeScript
Executable File
import { hasRichMarks, sanitizeRich, textToHtml } from "../utils/richtext";
|
||
|
||
/**
|
||
* 正文展示:一律过一遍消毒再注入(内容是用户数据,不能直接 innerHTML)。
|
||
* 旧数据是纯文本,走同一条路(只把换行变成 <br>),所以调用方不用区分。
|
||
* 需要纯文本的地方(关键字高亮、导出、AI)用 utils/richtext 的 richToText。
|
||
*/
|
||
export function RichText({ value, className }: { value?: string | null; className?: string }) {
|
||
const html = hasRichMarks(value) ? sanitizeRich(value) : textToHtml(String(value || ""));
|
||
if (!html) return null;
|
||
return <span className={"rich-view" + (className ? " " + className : "")} dangerouslySetInnerHTML={{ __html: html }} />;
|
||
}
|