ravenq / markdown-it-vue

The vue lib for markdown-it.
MIT License
347 stars 68 forks source link

Issue with fenced syntax highlighting #28

Closed jshook closed 4 years ago

jshook commented 4 years ago

With the highlighting module included, any time there is a fenced block which is not qualified with a language, I would expect highlighting to fall back to being disabled for that block. However, I've started seeing an error like Could not find the language '', did you forget to load/include a language module? which suggest that the matching expression for enabling highlighting on a provided fenced syntax name is matching as an empty string, which triggers the logic for "I have been given a syntax, let me load that language, but I can't find it."

This seems like a new or recent bug. It could be confusion about what class names to match, but the error message doesn't share any of these details to help with diagnosis.

[edit] I suspect the error is in the matching below, but a guard condition on a non-empty string would probably fix it.

   function blockLanguage(block) {
    var match;
    var classes = block.className + ' ';

    classes += block.parentNode ? block.parentNode.className : '';

    // language-* takes precedence over non-prefixed class names.
    match = options.languageDetectRe.exec(classes);
    if (match) {
      var language = getLanguage(match[1]);
      if (!language) {
        console.warn(LANGUAGE_NOT_FOUND.replace("{}", match[1]));
        console.warn("Falling back to no-highlight mode for this block.", block);
      }
      return language ? match[1] : 'no-highlight';
    }
cyberfly commented 4 years ago

@jshook Hi I have the same problem, did you figure it out? Thanks

jshook commented 4 years ago

I did not figure it out. Instead for now, I just added qualifiers to all fenced sections, but this is a bit of a nuisance.