Use RegExp with global flag to ensure all fenced code blocks have the hljs class applied

This commit is contained in:
Hector Ramos 2017-10-26 12:14:46 -07:00
parent fb294ab845
commit 9bb4f906fc

View file

@ -20,17 +20,6 @@ function anchors(md) {
}
class Remarkable extends React.Component {
render() {
var Container = this.props.container;
return (
<Container>
{this.content()}
</Container>
);
}
componentWillUpdate(nextProps, nextState) {
if (nextProps.options !== this.props.options) {
this.md = new Markdown(nextProps.options);
@ -87,9 +76,21 @@ class Remarkable extends React.Component {
}
const html = this.md.render(source);
// Ensure fenced code blocks use Highlight.js hljs class
// https://github.com/jonschlinkert/remarkable/issues/224
return this.md.render(source).replace('<pre><code>','<pre><code class="hljs">');
return html.replace(/<pre><code>/g,'<pre><code class="hljs">');
}
render() {
var Container = this.props.container;
return (
<Container>
{this.content()}
</Container>
);
}
}