jsvine / notebookjs

Render Jupyter/IPython notebooks on the fly, in the browser. (Or on the command line, if you'd like.)
MIT License
278 stars 47 forks source link

'<' and '>' gets escaped twice when used with Prismjs #30

Open uadarsh opened 4 years ago

uadarsh commented 4 years ago

I am trying to use the library along with Prism highlighting to render a notebook's content. It seems like the notebookjs library html-escapes the '<' and '>' characters before passing it to the highlighter. The highlighter treats it as the actual code and renders it as such by tokenising < and >

Anyway to disable escaping or any recommended way to handle this situation?

I am using the code given on the site to use prism highlighting. ie

`var Prism = require('prismjs');

var highlighter = function(code, lang) { if (typeof lang === 'undefined') lang = 'markup';

if (!Prism.languages.hasOwnProperty(lang)) {
    try {
        require('prismjs/components/prism-' + lang + '.js');
    } catch (e) {
        console.warn('** failed to load Prism lang: ' + lang);
        Prism.languages[lang] = false;
    }
}
return Prism.languages[lang] ? Prism.highlight(code, Prism.languages[lang]) : code;

}; var nb = require("notebookjs"); nb.highlighter = function(text, pre, code, lang) { var language = lang || 'text'; pre.className = 'language-' + language; if (typeof code != 'undefined') { code.className = 'language-' + language; } return highlighter(text, language); };`

jsvine commented 4 years ago

Hi @uadarsh and thanks for your interest in this repository. Could you provide a simple, reproducible example that demonstrates the issue you're encountering? That would include a specific notebook as well as the code to render it.