Skip to content

Commit d703e10

Browse files
committed
Re-highlights dcc.Markdown after it is updated
1 parent bbd013c commit d703e10

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

components/dash-core-components/src/fragments/Markdown.react.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,20 @@ export default class DashMarkdown extends Component {
3232
}
3333

3434
highlightCode() {
35+
const isHighlighted = node => {
36+
// a highlighted node will have <span> children which are what color the text
37+
return node.children.length > 0;
38+
};
39+
3540
if (this.mdContainer) {
3641
const nodes = this.mdContainer.querySelectorAll('pre code');
3742

3843
if (MarkdownHighlighter.hljs) {
3944
for (let i = 0; i < nodes.length; i++) {
40-
MarkdownHighlighter.hljs.highlightElement(nodes[i]);
45+
if (!isHighlighted(nodes[i])) {
46+
nodes[i].removeAttribute('data-highlighted');
47+
MarkdownHighlighter.hljs.highlightElement(nodes[i]);
48+
}
4149
}
4250
} else {
4351
MarkdownHighlighter.loadhljs();

0 commit comments

Comments
 (0)