Commit 7eac9610f25b563106240cb97750fd27e660a643
Handle highlighting failure
Charles Lehner committed on 4/2/2016, 2:27:51 AMParent: cfc5b28733448e844b57db879704bbe89187d7b7
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -36,11 +36,17 @@ | ||
36 | 36 | return (/\.([^.]+)$/.exec(filename) || [,filename])[1] |
37 | 37 | } |
38 | 38 | |
39 | 39 | function highlight(code, lang) { |
40 | - return lang | |
41 | - ? Highlight.highlight(lang, code).value | |
42 | - : Highlight.highlightAuto(code).value | |
40 | + try { | |
41 | + return lang | |
42 | + ? Highlight.highlight(lang, code).value | |
43 | + : Highlight.highlightAuto(code).value | |
44 | + } catch(e) { | |
45 | + if (/^Unknown language/.test(e.message)) | |
46 | + return escapeHTML(code) | |
47 | + throw e | |
48 | + } | |
43 | 49 | } |
44 | 50 | |
45 | 51 | marked.setOptions({ |
46 | 52 | gfm: true, |
Built with git-ssb-web