Help with a language definition for Node.js REPL interactions?

36 views
Skip to first unread message

Axel Rauschmayer

unread,
Jul 23, 2017, 6:19:28 PM7/23/17
to highlight.js
Node.js REPL interactions are pretty easy to highlight:
  • A line starting with > is input.
  • All other lines are output.
  • Additionally, I’m coloring comments at the end of input lines differently.
I’ve written a language definition, but it sends Highlight.js into an infinite loop if it encounters an empty line:

const hljs = require('highlight.js');

hljs.registerLanguage('repl',
    hljs => ({
        contains: [
            { begin: '^> ', end: '$', // input
                contains: [
                    { className: 'comment', begin: '//', end: '$' },
                ],
            },
            { className: 'meta', begin: '^', end: '$' }, // output
        ],
    }));

const txt = `
> foo(true) // call foo
'abc'

> 3 + 3
6
`.trim();
console.log(hljs.highlight('repl', txt).value);

Any idea how to fix that?

It feels like I’m triggering a Highlight.js bug. I’ve created a GitHub issue here: https://github.com/isagalaev/highlight.js/issues/1573
Reply all
Reply to author
Forward
0 new messages