@@ -4,7 +4,11 @@ import DOMPurify from 'dompurify'
4
4
5
5
// The U+2028 character (LINE SEPARATOR) is sometimes used as a line break, but it is treated as a space in some web environments,
6
6
// causing unexpected rendering issues. To avoid this, it's recommended to replace it with a standard line break character such as `\n`.
7
- const LINE_SEPARATOR = / \u2028 / g;
7
+ const LINE_SEPARATOR = / \u2028 / g
8
+
9
+ // LINE_BREAK_VISUAL is used for formatting when the message is displayed as a single line in a preview.
10
+ // It replaces line breaks with a visual symbol (↵) to indicate where new lines exist in the original text.
11
+ const LINE_BREAK_VISUAL = '↵ '
8
12
9
13
marked . setOptions ( {
10
14
// marked sanitize is deprecated, using DOMPurify
@@ -72,12 +76,13 @@ export function removeFormats(text = '') {
72
76
73
77
export function formatMessage ( text = '' ) {
74
78
const node = document . createElement ( 'div' )
75
- const textWithSymbol = text . replace ( / \n / g, '↵ ' )
79
+
80
+ const textWithSymbol = text . replace ( / \n / g, LINE_BREAK_VISUAL )
76
81
node . innerHTML = marked . parse ( sanitizeHTML ( textWithSymbol ) )
77
82
78
83
const textWithoutHtml = node . textContent || node . innerText || ''
79
84
80
85
return textWithoutHtml
81
- . replace ( LINE_SEPARATOR , '↵' )
86
+ . replace ( LINE_SEPARATOR , LINE_BREAK_VISUAL )
82
87
. replace ( / ↵ / g, '<span class="arrow-return">↵</span>' )
83
88
}
0 commit comments