-
Notifications
You must be signed in to change notification settings - Fork 30.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[api] Allow extensions to use the syntax highlighter #56356
Comments
In what format would we give the syntax highlighted code give back? |
Anything to work with would be great. My first intention was to search for an API that could resolve a This way markdown content could be rendered as well. Currently extension have to ship their own markdown parser (which VS Code already ships with at least two I know of) and if they want to provide highlighted code something like highlight.js and separate definitions for the language (or somehow integrate vscode-textmate). Before posting the issue here I asked it on the Gitter channel and another user indicated that they actually do it like so in their extension. I also noted that the syntax color scheme of the currently activated theme is not available in the webview and cannot be accessed by extensions either. |
So, just to add this, all I would need would be a rendered html string. |
Adding @mjbvz as the webview expert. |
@aeschli To get vscode-like syntax highlighting in a webview we would need an api like @sebastian-lenz proposes. For the markdown preview specifically, since many websites use highlightjs for highlighting code anyways, using highlightjs in the markdown preview isn't to much of a problem imo |
You might be interested in http://shiki.matsu.io/. It doesn't use oniguruma so no native dependecy, should be quite easy to integrate into your extension. |
Can |
/cc @mjbvz |
Thanks for the tip, but my core issue is the fact that when including a syntax highlighter in an extension, the results are not visually consistent within VS Code. Although Shiki will use the same specification, we cannot access the theme colors the user has picked. |
We have a similar issues within the python extension |
The token colors aren't even exposed as CSS variables... over 400 variables and the tokens are missing? |
Thought I'd mention this (even though it has been mentioned before #56356 (comment)) @octref thanks for the wonderful package |
Isn't this also a little related with the question here on StackOverflow? If VSCode would provide the possibility to use the editor object - perhaps including some options like |
@DonJayamanne Would you elaborate on that a little? I don't see how Shiki solves for this (other than by coincidentally supporting themes that may or may not match a user's visual config). |
I also require this feature to be implemented, Currently unable to use themes for my extension Thunder Client in the response syntax highlighting |
Sorry I missed this. I had to write code to load the theme files into Shiki. |
The mermaid markdown example by @mjbvz shows where to plug in custom syntax highlighting in markdown preview. And vscode-textmate can be used to adapt tokens to hljs class names. It would be nice if vscode did this automatically, but it's possible to wire up manually at this point. And this works better than shiki for multiple reasons, including because hljs class names pick up matching theme colors automatically. |
Any progress on this? Take a look at this generic Sticky Note which allows codeblocks to be created by copying a selection. Even after copying in the base css files like markdown.css and highlight.css, there's a lot of inconsistency between the note and the actual file. |
May I ask how you could make shiki work on an vscode webview extension (that uses webpack)? VSCode webview extensions are not able to make requests which seems necessary for the onig.wasm to be loaded and same for the themes. Themes can be solved somehow but i really wonder to know how you make the shiki work? |
@aeschli @alexdima For webviews and notebook renderers, we'd like an API where we can give VS Code a string of code and a language identifier, and get back html+css with syntax highlighting for that code. This would work similarly to the existing Some use cases:
|
Hi @mjbvz ! Do you know how GitHub Copilot Chat works? Since its codeblock can be adapted to the theme user selected. |
They have two different things, in the chat window they are not 100% matching the editor colors. However for the big answer blocks they are using a new editor tab which already has the editor colors as i've seen. |
Any updates on this? Will this feature request be considered or has it been abandoned? |
I think this would be a great feature to add! |
tokens may be provided when TreeSitter is fully implemented
otherwise you'll need to implement your own parser with like vscode-textmate or tree-sitter etc |
It would be great if the extension API would offer a way to access the syntax highlighter of VS Code.
I am currently building an extension that offers an inline help system, I use a WebviewPanel to display the help in the editor. For consistency it would be great if we could format code samples the same way the editor does but I currently see no way to do that.
The text was updated successfully, but these errors were encountered: