Skip to content

Commit 0e783e9

Browse files
committed
fix: add LINE_BREAK_VISUAL const
1 parent dd34907 commit 0e783e9

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/lib/markdown.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import DOMPurify from 'dompurify'
44

55
// The U+2028 character (LINE SEPARATOR) is sometimes used as a line break, but it is treated as a space in some web environments,
66
// 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 = '↵ '
812

913
marked.setOptions({
1014
// marked sanitize is deprecated, using DOMPurify
@@ -73,14 +77,12 @@ export function removeFormats(text = '') {
7377
export function formatMessage(text = '') {
7478
const node = document.createElement('div')
7579

76-
const replaceValue = '↵ '
77-
78-
const textWithSymbol = text.replace(/\n/g, replaceValue)
80+
const textWithSymbol = text.replace(/\n/g, LINE_BREAK_VISUAL)
7981
node.innerHTML = marked.parse(sanitizeHTML(textWithSymbol))
8082

8183
const textWithoutHtml = node.textContent || node.innerText || ''
8284

8385
return textWithoutHtml
84-
.replace(LINE_SEPARATOR, replaceValue)
86+
.replace(LINE_SEPARATOR, LINE_BREAK_VISUAL)
8587
.replace(//g, '<span class="arrow-return">↵</span>')
8688
}

0 commit comments

Comments
 (0)