@@ -2378,20 +2378,27 @@ import { bindMenuDismiss, dismissOrRemove } from './escMenuStack.js';
23782378 }
23792379
23802380 // ── WYSIWYG email body helpers ──
2381+ function _emailPlainTextToHtml ( text ) {
2382+ const d = document . createElement ( 'div' ) ;
2383+ d . textContent = text == null ? '' : String ( text ) ;
2384+ return d . innerHTML . replace ( / \n / g, '<br>' ) ;
2385+ }
2386+
23812387 function _emailBodyToHtml ( text ) {
23822388 const t = ( text || '' ) . trim ( ) ;
23832389 if ( ! t ) return '' ;
23842390 // If it already contains a formatting/structural HTML tag, it's a saved
2385- // WYSIWYG body — use it verbatim . (Checking a leading '<' isn't enough: a
2391+ // WYSIWYG body — sanitize it before rendering . (Checking a leading '<' isn't enough: a
23862392 // rich body often starts with plain text, e.g. "Hi <b>there</b>".)
2387- if ( / < \/ ? ( b | i | u | s | s t r o n g | e m | d e l | s t r i k e | a | p | d i v | b r | u l | o l | l i | h [ 1 - 3 ] | b l o c k q u o t e | s p a n | c o d e | p r e ) \b [ ^ > ] * > / i. test ( t ) ) return t ;
2393+ if ( / < \/ ? ( b | i | u | s | s t r o n g | e m | d e l | s t r i k e | a | p | d i v | b r | u l | o l | l i | h [ 1 - 3 ] | b l o c k q u o t e | s p a n | c o d e | p r e ) \b [ ^ > ] * > / i. test ( t ) ) {
2394+ return markdownModule . sanitizeAllowedHtml
2395+ ? markdownModule . sanitizeAllowedHtml ( t )
2396+ : _emailPlainTextToHtml ( t ) ;
2397+ }
23882398 // Email body: keep author-typed `:shortcode:` text literal. Issue #345
23892399 // (shortcode → emoji) is scoped to chat; do not rewrite colons in mail.
23902400 try { return markdownModule . mdToHtml ( text , { shortcodes : false } ) ; }
2391- catch ( _ ) {
2392- const d = document . createElement ( 'div' ) ; d . textContent = text ;
2393- return d . innerHTML . replace ( / \n / g, '<br>' ) ;
2394- }
2401+ catch ( _ ) { return _emailPlainTextToHtml ( text ) ; }
23952402 }
23962403 // Mirror the rich body's plain text into the hidden textarea so the existing
23972404 // send / draft / change-detection plumbing (which reads the textarea) stays
0 commit comments