mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-05 10:57:53 +02:00
Use RegExp with global flag to ensure all fenced code blocks have the hljs class applied
This commit is contained in:
parent
fb294ab845
commit
9bb4f906fc
1 changed files with 13 additions and 12 deletions
|
@ -20,17 +20,6 @@ function anchors(md) {
|
||||||
}
|
}
|
||||||
|
|
||||||
class Remarkable extends React.Component {
|
class Remarkable extends React.Component {
|
||||||
|
|
||||||
render() {
|
|
||||||
var Container = this.props.container;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Container>
|
|
||||||
{this.content()}
|
|
||||||
</Container>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
componentWillUpdate(nextProps, nextState) {
|
componentWillUpdate(nextProps, nextState) {
|
||||||
if (nextProps.options !== this.props.options) {
|
if (nextProps.options !== this.props.options) {
|
||||||
this.md = new Markdown(nextProps.options);
|
this.md = new Markdown(nextProps.options);
|
||||||
|
@ -87,10 +76,22 @@ class Remarkable extends React.Component {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const html = this.md.render(source);
|
||||||
|
|
||||||
// Ensure fenced code blocks use Highlight.js hljs class
|
// Ensure fenced code blocks use Highlight.js hljs class
|
||||||
// https://github.com/jonschlinkert/remarkable/issues/224
|
// 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>
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Remarkable.defaultProps = {
|
Remarkable.defaultProps = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue