Created
April 16, 2020 01:16
-
-
Save liuyxpp/a7dd2a1744d661cc2dc7daaf41cd05a0 to your computer and use it in GitHub Desktop.
VS Code Markdown Preview Enhanced: Extend Parser for syntax highlight of Jekyll/Liquid code blocks
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
// For Markdown Preview Enhanced | |
// In VS Code, press Cmd+shift+p, select Markdown Preview Enhanced | |
// file path (MacOS): ~/.mume/parser.js | |
// Convert {% highlight lang option %} [code blocks] {% endhighlight %} | |
// to ```julia [code blocks] ``` | |
module.exports = { | |
onWillParseMarkdown: function(markdown) { | |
return new Promise((resolve, reject)=> { | |
markdown = markdown.replace( | |
/{%\s*highlight\s*([\w]*)\s*([\w]*)\s*%}\n([\w\W]+?)\n{%\s*endhighlight\s*%}/g, | |
(whole, lang, opt, content) => ` | |
\`\`\`${lang} | |
${content} | |
\`\`\` | |
`, | |
); | |
return resolve(markdown) | |
}) | |
}, | |
onDidParseMarkdown: function(html) { | |
return new Promise((resolve, reject)=> { | |
return resolve(html) | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment