Highlight.js: `highlightAuto` with language subset doesn't appear to be working

Created on 14 Oct 2018  路  7Comments  路  Source: highlightjs/highlight.js

Hello,

Re:

Spec:

$ node -v
v10.12.0

NOTES:

  • https://openuserjs.org/…#comment-16627b793f6 (fixed this one to be a named fence to ensure correct library is being loaded and it is along with the CSS we inject... so it is currently working with named ones just not automatic detection).
  • All languages are available for named fences however we have had to limit unnamed fences since auto-detection doesn't always pin the right language. Been through a few revisions and landed on this methodology as the best available for our use cases.
  • Same issue in development. Clean package installs, etc.
  • We use ES5 syntax as a default and minimal to none ES6+.

Thanks for the look.

Most helpful comment

Ah, I see. It doesn't accept aliases (and never did), so use xquery instead.
Please leave the issue open, we'll need to rethink this. Probably we should accept aliases as well.

All 7 comments

Hi @Martii
The problem is in xpath. There is no such language in highlightjs:

  highlight: function (aCode, aLang) {
    var obj = null;
    var lang = [ // NOTE: More likely to less likely
      'javascript', 'xpath', 'xml',         // <------- remove xpath
        'css', 'less', 'scss',
          'json',
            'diff',
              'shell',
                'bash', 'dos',
                  'vbscript'
];

In 9.12 this fact was silently ignored, but now we throw an error. Probably we should not.
So, quick fix for you is to remove xpath from the list of languages.

@egor-rogov

The problem is in xpath. There is no such language in highlightjs

That did the trick. Will push to dev. Thank you! Could have sworn that I validated all the language names but I'm only human. ;) :)

In 9.12 this fact was silently ignored, but now we throw an error.

Looks like I'll need to add a few more dev console messages to track this. :) Good to know.

Thanks a bazillion!

Hmm just trapped on local dev and nothing thrown. : Oh well... I'm ready for rest and will tackle our issue later.

Okay I'm stubborn... trapped every layer of our code, and several hard refreshes of my browser, and got this:

TypeError: Cannot read property 'disableAutodetect' of undefined
    at autoDetection (~/repo/git/OpenUserJS.org/martii/OpenUserJS.org/node_modules/highlight.js/lib/highlight.js:711:29)
    at Array.filter (<anonymous>)
    at Object.highlightAuto (~/repo/git/OpenUserJS.org/martii/OpenUserJS.org/node_modules/highlight.js/lib/highlight.js:572:40)
    at Object.highlight (~/repo/git/OpenUserJS.org/martii/OpenUserJS.org/libs/markdown.js:261:21)
    at Renderer.code (~/repo/git/OpenUserJS.org/martii/OpenUserJS.org/node_modules/marked/lib/marked.js:920:28)
    at Parser.tok (~/repo/git/OpenUserJS.org/martii/OpenUserJS.org/node_modules/marked/lib/marked.js:1199:28)
    at Parser.parse (~/repo/git/OpenUserJS.org/martii/OpenUserJS.org/node_modules/marked/lib/marked.js:1144:17)
    at Function.Parser.parse (~/repo/git/OpenUserJS.org/martii/OpenUserJS.org/node_modules/marked/lib/marked.js:1126:17)
    at marked (~/repo/git/OpenUserJS.org/martii/OpenUserJS.org/node_modules/marked/lib/marked.js:1533:19)
    at exports.renderMd (~/repo/git/OpenUserJS.org/martii/OpenUserJS.org/libs/markdown.js:285:10)
    at exports.renderComment (~/repo/git/OpenUserJS.org/martii/OpenUserJS.org/libs/modelParser.js:719:30)
    at Function._.map._.collect (~/repo/git/OpenUserJS.org/martii/OpenUserJS.org/node_modules/underscore/underscore.js:205:24)
    at preRender (~/repo/git/OpenUserJS.org/martii/OpenUserJS.org/controllers/issue.js:240:13)
    at asyncComplete (~/repo/git/OpenUserJS.org/martii/OpenUserJS.org/controllers/issue.js:254:11)
    at ~/repo/git/OpenUserJS.org/martii/OpenUserJS.org/node_modules/async/dist/async.js:3888:9
    at ~/repo/git/OpenUserJS.org/martii/OpenUserJS.org/node_modules/async/dist/async.js:473:16

... that's not quite the stack trace I was thinking I was going to get... disableAutodetect of undefined.


Anyhow... removing the xpath seems to do the trick for now.

The problem is in xpath. There is no such language in highlightjs

There should be... it's listed at the tail end of https://github.com/highlightjs/highlight.js/blob/82c22c6da9f591510f041d2047c0a5b7e9886370/docs/css-classes-reference.rst#language-names-and-aliases.

See XQuery | xpath, xq.

I'm going to reopen this as this is darn peculiar.

Ah, I see. It doesn't accept aliases (and never did), so use xquery instead.
Please leave the issue open, we'll need to rethink this. Probably we should accept aliases as well.

Okay, basically we have two options here:

1. Update the docs to reflect the current behavior (i. e. that highlightAuto() and configure() don't accept aliases). Previously aliases were accepted but ignored (that's too bad), now an error occurs. This change appeared quite accidentally, it wasn't planned.

  1. Tweak the code to actually accept aliases along with language names.

(2) is doable but seems not worth the effort. It shouldn't be a big problem for the caller to specify a right name. So I'm inclined to (1).
@marcoscaceres what do you think?

I'm wrong, sorry for the buzz. That's my bug :( Will fix it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

goloroden picture goloroden  路  3Comments

Rarst picture Rarst  路  8Comments

gskinner picture gskinner  路  4Comments

OrbintSoft picture OrbintSoft  路  8Comments

ghost picture ghost  路  3Comments