notebookjs icon indicating copy to clipboard operation
notebookjs copied to clipboard

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

Open uadarsh opened this issue 5 years ago • 1 comments

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); };`

uadarsh avatar Oct 08 '20 17:10 uadarsh

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.

jsvine avatar Nov 10 '20 04:11 jsvine