Skip to content

Commit 7a1b627

Browse files
authoredJun 3, 2020
housekeeping: remarkable (#6073)
Refs: #6050
1 parent 607c0fd commit 7a1b627

File tree

4 files changed

+260
-83
lines changed

4 files changed

+260
-83
lines changed
 

‎package-lock.json

+231-54
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
"react-redux": "^4.x.x",
7979
"redux": "^3.x.x",
8080
"redux-immutable": "3.1.0",
81-
"remarkable": "^1.7.4",
81+
"remarkable": "^2.0.1",
8282
"reselect": "^4.0.0",
8383
"serialize-error": "^2.1.0",
8484
"sha.js": "^2.4.11",

‎src/core/components/providers/markdown.jsx

+27-27
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from "react"
22
import PropTypes from "prop-types"
3-
import Remarkable from "remarkable"
3+
import { Remarkable } from "remarkable"
4+
import { linkify } from "remarkable/linkify"
45
import DomPurify from "dompurify"
56
import cx from "classnames"
67

@@ -16,35 +17,34 @@ DomPurify.addHook("beforeSanitizeElements", function (current, ) {
1617
})
1718

1819
function Markdown({ source, className = "" }) {
19-
if (typeof source !== "string") {
20-
return null
21-
}
22-
23-
const md = new Remarkable({
24-
html: true,
25-
typographer: true,
26-
breaks: true,
27-
linkify: true,
28-
linkTarget: "_blank"
29-
})
30-
31-
md.core.ruler.disable(["replacements", "smartquotes"])
32-
33-
const html = md.render(source)
34-
const sanitized = sanitizer(html)
35-
36-
if ( !source || !html || !sanitized ) {
37-
return null
38-
}
39-
40-
return (
41-
<div className={cx(className, "markdown")} dangerouslySetInnerHTML={{ __html: sanitized }}></div>
42-
)
20+
if (typeof source !== "string") {
21+
return null
22+
}
23+
24+
const md = new Remarkable({
25+
html: true,
26+
typographer: true,
27+
breaks: true,
28+
linkTarget: "_blank"
29+
}).use(linkify)
30+
31+
md.core.ruler.disable(["replacements", "smartquotes"])
32+
33+
const html = md.render(source)
34+
const sanitized = sanitizer(html)
35+
36+
if (!source || !html || !sanitized) {
37+
return null
38+
}
39+
40+
return (
41+
<div className={cx(className, "markdown")} dangerouslySetInnerHTML={{ __html: sanitized }}></div>
42+
)
4343
}
4444

4545
Markdown.propTypes = {
46-
source: PropTypes.string.isRequired,
47-
className: PropTypes.string
46+
source: PropTypes.string.isRequired,
47+
className: PropTypes.string
4848
}
4949

5050
export default Markdown

‎src/core/plugins/oas3/wrap-components/markdown.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from "react"
22
import PropTypes from "prop-types"
33
import cx from "classnames"
4-
import Remarkable from "remarkable"
4+
import { Remarkable } from "remarkable"
55
import { OAS3ComponentWrapFactory } from "../helpers"
66
import { sanitizer } from "core/components/providers/markdown"
77

0 commit comments

Comments
 (0)
Please sign in to comment.