const RICH_TEXT_TAG = /<(?:p|h[1-6]|ul|ol|li|blockquote|strong|em|u|s|a|br|hr|span)\b/i export function escapeRichText(value: string) { return value .replaceAll('&', '&') .replaceAll('<', '<') .replaceAll('>', '>') .replaceAll('"', '"') .replaceAll("'", ''') } export function toEditorHtml(value: string) { if (!value.trim()) return '
' if (RICH_TEXT_TAG.test(value)) return value return value .split(/\n{2,}/) .map(paragraph => `${escapeRichText(paragraph).replaceAll('\n', '
')}