Skip to content

Commit

Permalink
Add highlight.js language autodetection
Browse files Browse the repository at this point in the history
Using better version from @stephanebachelier
  • Loading branch information
mnewt committed May 9, 2014
1 parent 0f7469f commit a91007f
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/plugins/markdown.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,12 @@ parseMarkdownSync = (content, baseUrl, options) ->
url.resolve baseUrl, uri

options.highlight = (code, lang) ->
try
lang = 'cpp' if lang is 'c'
return hljs.highlight(lang, code).value
try
result = if lang and hljs.getLanguage(lang) then hljs.highlight(lang, code) else hljs.highlightAuto(code)
return result.value
catch error
# if lang is unrecognized or nonexistent try to autodetect language
try
hljs.highlightAuto(code).value
catch error
return code

return code

marked.setOptions options
return marked content

Expand Down

0 comments on commit a91007f

Please sign in to comment.