Skip to content

Commit

Permalink
Merge pull request #117 from gnarf/highlighters
Browse files Browse the repository at this point in the history
Pass the langauge class in code for Prism highlights
  • Loading branch information
Muhammed Thanish authored Dec 4, 2016
2 parents 24f9e45 + adba83e commit c50edfe
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/components/markdown/code.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
import React from 'react';

export class Code extends React.Component {

componentDidMount() {
this.highlight()
}

componentDidUpdate() {
this.highlight()
}

highlight() {
if (typeof Prism !== 'undefined') {
Prism.highlightAll()
}
}

render() {
const codeStyle = {
fontFamily: 'Menlo, Monaco, "Courier New", monospace',
Expand All @@ -15,9 +30,11 @@ export class Code extends React.Component {
overflowX: 'scroll',
};

const className = this.props.language ? `language-${this.props.language}` : '';

return (
<pre style={preStyle}>
<code style={codeStyle}>
<pre style={preStyle} className={className}>
<code style={codeStyle} className={className}>
{ this.props.code }
</code>
</pre>
Expand Down

0 comments on commit c50edfe

Please sign in to comment.