I am working on a language extension for vscode. I defined a tmLanguage file and everything works nicely. In the hover feature, using vscode.MarkdownString.appendCodeblock()
the markdown is being interpreted correctly and syntax highlighting for my custom language just works out of the box, by doing something like:
const content = new MarkdownString("", true)
content.appendMarkdown("## Examples: \n")
content.appendCodeblock(examples, "lmps")
where examples
contains some example code in my custom language and "lmps"
is my language identifier.
(Example Image Hover)
I wonder if there is a way to achieve the same thing in a webview. I succeeded displaying the content
in a webview, compiling the markdownString into html:
async function set_doc_panel_content(panel: DocPanel | undefined, md_content: vscode.MarkdownString) {
const html: string = await vscode.commands.executeCommand('markdown.api.render', md_content.value) as string;
panel!.webview.html = html;
}
So far so good, but in this way, markdown doesn't know my custom language and doesn't do any syntax highlighting. (Example image Webview) Now, I understand that adding language-support to the Markdown extension can be achieved by contributing a markdown-it plugin by returning an object in the activation function.
export function activate(context: vscode.ExtensionContext) {
...
return {
extendMarkdownIt(md: any) {
return md.use(require('markdown-it-emoji'));
}
}
However, this requires actually developing a dedicated markdown-it plugin if I see that right. I wonder if there is an easier way to integrate my language into the markdown api. Since vscode can obviously do it natively in hover and completion suggestions already. Can I somehow use this functionality in a webview maybe? Alternatively, is there a way to generate a markdown-it plugin from a tmLanguage-file without having to learn markdown-it plugin development in depth? Perhaps someone has pointers to projects where something like this was done?