-
-
Notifications
You must be signed in to change notification settings - Fork 145
Refactor markdown syntax highlighting. #720
Changes from all commits
9d9aa6e
103fcb5
f679951
cc70aed
6c98c28
f80bf28
b2893ed
b679a6a
dff9f8c
6bad06d
37d34eb
3ca7aa2
a3fb701
3ebf656
78aaeda
0fd28a0
a2ba931
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,18 @@ import React, {Component} from 'react'; | |
import {type} from 'ramda'; | ||
import Markdown from 'react-markdown'; | ||
|
||
import MarkdownHighlighter from '../utils/MarkdownHighlighter'; | ||
import {propTypes, defaultProps} from '../components/Markdown.react'; | ||
import '../components/css/highlight.css'; | ||
|
||
export default class DashMarkdown extends Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
if (MarkdownHighlighter.isReady !== true) { | ||
MarkdownHighlighter.isReady.then(() => { | ||
this.setState({}); | ||
}); | ||
} | ||
this.highlightCode = this.highlightCode.bind(this); | ||
this.dedent = this.dedent.bind(this); | ||
} | ||
|
@@ -21,15 +27,15 @@ export default class DashMarkdown extends Component { | |
} | ||
|
||
highlightCode() { | ||
if (!window.hljs) { | ||
// skip highlighting if highlight.js isn't found | ||
return; | ||
} | ||
if (this.mdContainer) { | ||
const nodes = this.mdContainer.querySelectorAll('pre code'); | ||
|
||
for (let i = 0; i < nodes.length; i++) { | ||
window.hljs.highlightBlock(nodes[i]); | ||
if (MarkdownHighlighter.hljs) { | ||
for (let i = 0; i < nodes.length; i++) { | ||
MarkdownHighlighter.hljs.highlightBlock(nodes[i]); | ||
} | ||
} else { | ||
MarkdownHighlighter.loadhljs(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the existing implementation does not take full advantage of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Issue created: #724, will not be addressed as part of this PR. |
||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉