Skip to content

Commit e038ec0

Browse files
authored
Merge pull request #730 from Adamant-im/chore/update-marked-lib-to-v15
chore: update marked and dompurify versions and verify functionality
2 parents 5a71808 + 06bbf14 commit e038ec0

File tree

3 files changed

+27
-21
lines changed

3 files changed

+27
-21
lines changed

package-lock.json

Lines changed: 17 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"dayjs": "^1.11.13",
6464
"deepmerge": "^4.3.1",
6565
"detect-browser": "^5.3.0",
66-
"dompurify": "^3.1.6",
66+
"dompurify": "^3.2.4",
6767
"ecpair": "^2.1.0",
6868
"ed2curve": "^0.3.0",
6969
"emoji-mart": "^5.6.0",
@@ -75,7 +75,7 @@
7575
"js-base64": "^3.7.7",
7676
"js-md5": "^0.8.3",
7777
"lodash": "^4.17.21",
78-
"marked": "^14.1.0",
78+
"marked": "^15.0.7",
7979
"mitt": "^3.0.1",
8080
"multiformats": "^13.3.2",
8181
"notifyjs": "^3.0.0",

src/lib/markdown.js renamed to src/lib/markdown.ts

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

44
// The U+2028 character (LINE SEPARATOR) is sometimes used as a line break, but it is treated as a space in some web environments,
@@ -9,6 +9,8 @@ const LINE_SEPARATOR = /\u2028/g
99
// It replaces line breaks with a visual symbol (↵) to indicate where new lines exist in the original text.
1010
const LINE_BREAK_VISUAL = '↵ '
1111

12+
const marked = new Marked()
13+
1214
marked.setOptions({
1315
// marked sanitize is deprecated, using DOMPurify
1416
// sanitize: true,
@@ -18,11 +20,11 @@ marked.setOptions({
1820

1921
const renderer = new marked.Renderer()
2022

21-
renderer.image = function ({ _href, _title, _text }) {
23+
renderer.image = function () {
2224
return ''
2325
}
2426

25-
renderer.link = function ({ href, _title, text }) {
27+
renderer.link = function ({ href, text }) {
2628
const linkPattern = /^(eth|bch|bitcoin|https?|s?ftp|magnet|tor|onion|tg):(.*)$/i
2729
const emailPattern = /^(mailto):[^@]+@[^@]+\.[^@]+$/i
2830

@@ -56,7 +58,7 @@ export function sanitizeHTML(text = '') {
5658
* @returns {string} resulting sanitized HTML
5759
*/
5860
export function renderMarkdown(text = '') {
59-
return marked.parse(sanitizeHTML(text.replace(LINE_SEPARATOR, '\n')))
61+
return marked.parse(sanitizeHTML(text.replace(LINE_SEPARATOR, '\n')), { async: false })
6062
}
6163

6264
/**
@@ -68,7 +70,7 @@ export function renderMarkdown(text = '') {
6870
export function removeFormats(text = '') {
6971
const node = document.createElement('div')
7072
const textWithSymbol = text.replace(/\n/g, '↵ ')
71-
node.innerHTML = marked.parse(sanitizeHTML(textWithSymbol))
73+
node.innerHTML = marked.parse(sanitizeHTML(textWithSymbol), { async: false })
7274

7375
return node.textContent || node.innerText || ''
7476
}
@@ -77,7 +79,7 @@ export function formatMessage(text = '') {
7779
const node = document.createElement('div')
7880

7981
const textWithSymbol = text.replace(/\n/g, LINE_BREAK_VISUAL)
80-
node.innerHTML = marked.parse(sanitizeHTML(textWithSymbol))
82+
node.innerHTML = marked.parse(sanitizeHTML(textWithSymbol), { async: false })
8183

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

0 commit comments

Comments
 (0)