Improve example for invoking highlight.js#1603
Merged
styfle merged 1 commit intomarkedjs:masterfrom Feb 14, 2020
Merged
Conversation
|
This pull request is being automatically deployed with ZEIT Now (learn more). 🔍 Inspect: https://zeit.co/markedjs/markedjs/6rqwcwe36 |
UziTech
approved these changes
Feb 13, 2020
2b9aa11 to
6472717
Compare
This was referenced Mar 21, 2020
This was referenced Mar 30, 2020
This was referenced Apr 9, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.