New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing error when using highlight.js #311

Closed
dyzdyz010 opened this Issue Dec 17, 2013 · 5 comments

Comments

Projects
None yet
5 participants
@dyzdyz010
Copy link

dyzdyz010 commented Dec 17, 2013

I'm using marked with Angular.js. When I create a code block, if I type the language wrong like this:

```wrongLanguage
print "Hello"
```

Then an error will occur:

2013-12-17 17 02 39

@Feder1co5oave

This comment has been minimized.

Copy link
Contributor

Feder1co5oave commented Dec 24, 2013

highlight.js does not like 'undefined' languages. I solved this by writing

if (typeof hljs != 'undefined')
  marked.setOptions({
    highlight: function (code, lang) {
      if (lang && hljs.LANGUAGES.hasOwnProperty(lang))
        return hljs.highlight(lang, code).value;
      else
        return code;
    }
  });
@dyzdyz010

This comment has been minimized.

Copy link
Author

dyzdyz010 commented Dec 25, 2013

Thanks this solved the problem :)

@ChrisWren

This comment has been minimized.

Copy link
Contributor

ChrisWren commented Dec 28, 2013

Closing this since it is solved.

@ChrisWren ChrisWren closed this Dec 28, 2013

@shuhei

This comment has been minimized.

Copy link

shuhei commented Sep 21, 2015

For someone visiting here later, I had to write !!(lang && hljs.getLanguage(lang)) for the condition with highlight.js 8.8.0 because it no longer has LANGUAGES property.

@JimmyLv

This comment has been minimized.

Copy link

JimmyLv commented Mar 4, 2016

@shuhei Cool~ Thanks very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment