Skip to content

Commit

Permalink
Avoid errors when the language is not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
Angel M De Miguel committed Jun 26, 2017
1 parent 9fdfed0 commit 819b5c3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
13 changes: 7 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ exports.default = function (languageDefinitions) {

var language = className.split('-')[1] || '';
var value = children[0] || '';
var props = { language: language, value: value, inline: true };
var props = { value: value, inline: true };

return language ? _react2.default.createElement(_reactLowlight2.default, props) : _react2.default.createElement(
'code',
null,
value
);
if (Object.keys(languageDefinitions).indexOf(language) > -1) {
// Include the language only if it was previously registered
props.language = language;
}

return _react2.default.createElement(_reactLowlight2.default, props);
};
Code.propTypes = {
className: _react2.default.PropTypes.string,
Expand Down
9 changes: 7 additions & 2 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ export default (languageDefinitions) => {
const Code = ({ className = '', children }) => {
const language = className.split('-')[1] || '';
const value = children[0] || '';
const props = { language, value, inline: true };
const props = { value, inline: true };

return language ? <Lowlight {...props} /> : <code>{ value }</code>;
if (Object.keys(languageDefinitions).indexOf(language) > -1) {
// Include the language only if it was previously registered
props.language = language;
}

return <Lowlight {...props} /> ;
};
Code.propTypes = {
className: React.PropTypes.string,
Expand Down

0 comments on commit 819b5c3

Please sign in to comment.