File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change 1
1
import { marked } from 'marked'
2
2
import DOMPurify from 'dompurify'
3
3
4
+
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
+ // 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;
8
+
4
9
marked . setOptions ( {
5
10
// marked sanitize is deprecated, using DOMPurify
6
11
// sanitize: true,
@@ -48,7 +53,7 @@ export function sanitizeHTML(text = '') {
48
53
* @returns {string } resulting sanitized HTML
49
54
*/
50
55
export function renderMarkdown ( text = '' ) {
51
- return marked . parse ( sanitizeHTML ( text . replace ( / \u2028 / g , "\n" ) ) )
56
+ return marked . parse ( sanitizeHTML ( text . replace ( LINE_SEPARATOR , "\n" ) ) )
52
57
}
53
58
54
59
/**
@@ -71,6 +76,8 @@ export function formatMessage(text = '') {
71
76
node . innerHTML = marked . parse ( sanitizeHTML ( textWithSymbol ) )
72
77
73
78
const textWithoutHtml = node . textContent || node . innerText || ''
74
- const styledText = textWithoutHtml . replace ( / ↵ / g, '<span class="arrow-return">↵</span>' )
75
- return styledText
79
+
80
+ return textWithoutHtml
81
+ . replace ( LINE_SEPARATOR , '↵' )
82
+ . replace ( / ↵ / g, '<span class="arrow-return">↵</span>' )
76
83
}
You can’t perform that action at this time.
0 commit comments