-
Notifications
You must be signed in to change notification settings - Fork 23
/
Highlight.js
40 lines (35 loc) · 891 Bytes
/
Highlight.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { findDOMNode } from 'react-dom'
import highlight from 'highlight.js'
export default class Highlight extends Component {
static propTypes = {
children: PropTypes.node.isRequired,
className: PropTypes.string,
language: PropTypes.string,
style: PropTypes.object
}
componentDidMount () {
highlight.highlightBlock(findDOMNode(this.refs.code))
}
componentDidUpdate () {
highlight.initHighlighting.called = false
highlight.highlightBlock(findDOMNode(this.refs.code))
}
render () {
const { children, className, language, style } = this.props
return (
<pre
className={className}
style={style}
>
<code
className={language}
ref='code'
>
{children}
</code>
</pre>
)
}
}