Skip to content

Commit 82373a1

Browse files
authored
Merge pull request #708 from Adamant-im/fix/markdown-message-preview
fix: markdown-message-preview
2 parents c9e4936 + 05c792b commit 82373a1

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/lib/markdown.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { marked } from 'marked'
22
import DOMPurify from 'dompurify'
33

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+
49
marked.setOptions({
510
// marked sanitize is deprecated, using DOMPurify
611
// sanitize: true,
@@ -48,7 +53,7 @@ export function sanitizeHTML(text = '') {
4853
* @returns {string} resulting sanitized HTML
4954
*/
5055
export function renderMarkdown(text = '') {
51-
return marked.parse(sanitizeHTML(text.replace(/\u2028/g, "\n")))
56+
return marked.parse(sanitizeHTML(text.replace(LINE_SEPARATOR, "\n")))
5257
}
5358

5459
/**
@@ -71,6 +76,8 @@ export function formatMessage(text = '') {
7176
node.innerHTML = marked.parse(sanitizeHTML(textWithSymbol))
7277

7378
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>')
7683
}

0 commit comments

Comments
 (0)