lib-react-components
Advanced tools
Comparing version 0.0.22 to 0.0.23
@@ -90,4 +90,18 @@ 'use strict'; | ||
var _html = _prismjs2.default.highlight(this.props.children, _prismjs2.default.languages[lang], lang); | ||
var grammar = _prismjs2.default.languages[lang]; | ||
var _html = this.rootNode.textContent; | ||
if (grammar) { | ||
try { | ||
_html = _prismjs2.default.highlight(_html, grammar, lang); | ||
} catch (err) { | ||
console.warn('React Components Highlighter: There is an error highlighting lang ' + lang, err); | ||
} | ||
} else { | ||
_html = _html.replace(/[<>]/g, function (s) { | ||
return '&#' + s.charCodeAt(0) + ';'; | ||
}); | ||
} | ||
// Treat iOS whie-space: pre; behavior | ||
this.rootNode.innerHTML = _html.replace(/\n/g, '<br>').replace(/<br>[ ]+/g, function (str) { | ||
@@ -94,0 +108,0 @@ return '<br>' + ' '.repeat(str.length - 5); |
@@ -57,4 +57,16 @@ import React, { Component } from 'react'; | ||
const { lang } = this.props; | ||
const _html = Prism.highlight(this.props.children, Prism.languages[lang], lang); | ||
const grammar = Prism.languages[lang]; | ||
let _html = this.rootNode.textContent; | ||
if (grammar) { | ||
try { | ||
_html = Prism.highlight(_html, grammar, lang); | ||
} catch (err) { | ||
console.warn(`React Components Highlighter: There is an error highlighting lang ${lang}`, err); | ||
} | ||
} else { | ||
_html = _html.replace(/[<>]/g, s => `&#${s.charCodeAt(0)};`); | ||
} | ||
// Treat iOS whie-space: pre; behavior | ||
this.rootNode.innerHTML = _html | ||
@@ -61,0 +73,0 @@ .replace(/\n/g, '<br>') |
{ | ||
"name": "lib-react-components", | ||
"version": "0.0.22", | ||
"version": "0.0.23", | ||
"description": "React components", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
451476
10724