Treat json5 as json in the markdown preview

This commit is contained in:
Matt Bierner
2018-10-05 13:06:26 -07:00
parent bb59097ab8
commit f87369e1af

View File

@@ -39,11 +39,14 @@ export class MarkdownEngine {
const mdnh = await import('markdown-it-named-headers');
this.md = (await import('markdown-it'))({
html: true,
highlight: (str: string, lang: string) => {
highlight: (str: string, lang?: string) => {
// Workaround for highlight not supporting tsx: https://github.com/isagalaev/highlight.js/issues/1155
if (lang && ['tsx', 'typescriptreact'].indexOf(lang.toLocaleLowerCase()) >= 0) {
lang = 'jsx';
}
if (lang && lang.toLocaleLowerCase() === 'json5') {
lang = 'json';
}
if (lang && hljs.getLanguage(lang)) {
try {
return `<div>${hljs.highlight(lang, str, true).value}</div>`;