-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Improve example for invoking highlight.js #1603
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
Conversation
|
This pull request is being automatically deployed with ZEIT Now (learn more). 🔍 Inspect: https://zeit.co/markedjs/markedjs/6rqwcwe36 |
2b9aa11 to
6472717
Compare
styfle
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks!
Marked version: 0.8.0
Markdown flavor: n/a
Description
The
markeddocs show this usage for invokinghighlight.jsto perform syntax highlighting of code blocks:The markdown code blocks to be highlighted might look like these examples:
The documented usage has several serious flaws:
The code language (e.g.
sql) is completely ignored; it is not passed tohighlight.jsThe
highlightAuto()API causeshighlight.jsto perform the entire highlighting algorithm 184 times -- once for each supported language -- in order to determine the "best match." This is a potentially expensive approach which doesn't make sense as a recommended or default behavior.As a result, the code block
This is plain textgets wrongly highlighted asapplescript(sinceisandtextare keywords in that language). That's NOT what a typical Markdown author would expect.This PR updates the docs to honor the requested language, and fall back to
plaintextotherwise. Note that thehighlight()API throws an error for an unrecognized language, so the fallback needs to be implemented manually.Contributor
Committer
In most cases, this should be a different person than the contributor.