Skip to content

Commit 6272ba8

Browse files
committed
Updated component and demo to fix a regression where changing language or content did not update the rendered/styled text
1 parent a22251f commit 6272ba8

5 files changed

Lines changed: 19 additions & 8 deletions

File tree

src/Highlight.example.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,9 @@
22
white-space: pre;
33
font-family: monospace;
44
}
5+
6+
pre,
7+
.pre {
8+
background: #222;
9+
border: none;
10+
}

src/Highlight.example.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ export default class HighlightDemoDemo extends Component {
5555
onChange={event => this._debouncedSetState('content', event.target.value)} />
5656
</div>
5757
<label>Output</label>
58-
<Highlight language={language}>
58+
<Highlight
59+
className={styles.pre}
60+
language={language}
61+
>
5962
{content}
6063
</Highlight>
6164
</div>

src/Highlight.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,23 @@ export default class Highlight extends Component {
99
}
1010

1111
componentDidMount () {
12-
highlight.initHighlightingOnLoad()
13-
highlight.highlightBlock(findDOMNode(this))
12+
highlight.highlightBlock(findDOMNode(this.refs.code))
1413
}
1514

1615
componentDidUpdate () {
1716
highlight.initHighlighting.called = false
18-
highlight.initHighlighting()
17+
highlight.highlightBlock(findDOMNode(this.refs.code))
1918
}
2019

2120
render () {
2221
const { children, language } = this.props
2322

2423
return (
25-
<pre>
26-
<code className={language}>
24+
<pre {...this.props}>
25+
<code
26+
className={language}
27+
ref='code'
28+
>
2729
{children}
2830
</code>
2931
</pre>

website/Application.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default class Application extends React.Component {
2525
</Highlight>
2626
<p>Choose a highlight.js theme and make sure it's included in your index file.</p>
2727
<Highlight language='html'>
28-
<link rel='stylesheet' href='https://highlightjs.org/static/demo/styles/railscasts.css' />
28+
{`<link rel='stylesheet' href='https://highlightjs.org/static/demo/styles/railscasts.css' />`}
2929
</Highlight>
3030
<p>And then use react-highlight.js to display your text like so:</p>
3131
<Highlight language='html'>

website/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<title>react-highlight.js</title>
55
<meta charset="utf-8">
6-
<link rel='stylesheet' href='https://highlightjs.org/static/demo/styles/tomorrow-night.css'/>
6+
<link rel='stylesheet' href='https://highlightjs.org/static/demo/styles/railscasts.css'/>
77
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css'/>
88
</head>
99
<body>

0 commit comments

Comments
 (0)