-
Notifications
You must be signed in to change notification settings - Fork 29.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
Markdown Preview Extensions Exploration #22916
Comments
Does that mean user stylesheets/theme overrides are coming soon? |
@hoovercj User stylesheets for the markdown preview is already supported: https://code.visualstudio.com/Docs/languages/markdown#_using-your-own-css |
@mjbvz of course, sorry, I forgot the context and got excited about theme overrides. Ignore me :-) |
Some prototype extensions: https://github.com/mjbvz/vscode-markdown-emoji Thoughts on other prototypes to look into:
|
Hello. It is a grate feature! Thank you. I tried this feature and plugins, but it did not work.
|
@h1romas4 It's still an experiment which is why the setting is not publicly documented yet. I've also republished the mermaid vsix. Please give it a try and let me know if you run into any issues: https://github.com/mjbvz/vscode-markdown-mermaid |
@mjbvz Sorry, I was wrong. new vscode-markdown-mermaid is work! Thank you! |
This looks great! I'd be interested in a slight variation of this: in the julia extension we support julia markdown files. They have the file ending |
@davidanthoff Is this the project you are targeting https://github.com/mpastell/Weave.jl ? |
@mjbvz Yes, Weave.jl is the one. Essentially the markdown extension would detect code blocks in the markdown like this:
And then it could insert the results of that julia code into the markdown preview. |
Thanks for the additional info @davidanthoff This feature was not designed with that use case in mind, but I would be very interested to see if the new API would fit your needs as well. Perhaps you could try prototyping something and let me know what sort of problems you run into? The API is still experimental and could certainly be updated based on your feedback. To get started, try taking a look at the prototype mermaid extension: https://github.com/mjbvz/vscode-markdown-mermaid/blob/master/index.js . This extension handles markdown code blocks such as:
and injects a script into the preview to actually render these as graphs and sequence diagrams. I imagine you should be able to do something similar. Please let me know if you have any questions and please share any feedback about the new API |
Is it possible to add language server support? |
Using your own CSS in markdown preview does not allow extension authors to provide theme specific stylesheets. Are there any plans to support this? |
@vstirbu See the section on |
Keeping this experimental in May with VSCode 1.13. We'll reevaluate this again for the June sprint I'm also planning to tweak the API slightly. The original proposed API defined style contributions using: "contributes": {
"markdown.preview": {
"styles": ["./my_custom_style.css"],
"scripts": ["./custom_script.js"]
}
} For consistency with other contributions, this will be changed to: "contributes": {
"markdown.previewStyles": [ "./my_custom_style.css"],
"markdown.previewScripts": ["./custom_script.js"]
} This will break some of the experimental extensions. I'll try to update the examples I've posted once the API change goes in |
@mjbvz I looked at this again. I think the biggest issue I have right now is that I actually don't want to modify the behavior of the preview for normal markdown files at all. I think really what I would need is an API exposed by the markdown preview that allows me to configure the markdown preview extension from my julia extension. For example, that API would have a function like |
Good news, everyone! VSCode 1.15 insiders now has markdown extensions enabled by default. The API has changed slightly since the initial proposal. The most up to date documentation is now in a pre-release version the VS Code docs: https://github.com/Microsoft/vscode-docs/blob/vnext/docs/extensionAPI/api-markdown.md I've also tried to update most the example extensions to use the new API. These will be published to the marketplace after 1.15 ships Please give the API a try and let me know if you run into any problems |
From #22836
Feature
Allow extensions to enhance to VSCode's builtin markdown preview, such as adding math support for example
Working Draft of API
Extensions can enhance VSCode's markdown preview by:
Changing the Styling of the Markdown Preview
To change the styling of markdown preview page, just add a
markdown.preview
entry to thecontributes
section of your extension'spackage.json
, like so:styles
should be an array of extension relative paths to CSS files. These stylesheets will be included on the markdown preview page, and will be included after the default markdown preview stylings but before the user's custom stylesheets.Using Markdown-It Plugins to Support New Markdown Syntax
To support new markdown syntax, first add
markdown-it.plugins
entry in the extension'spackage.json
This tells VSCode that your extension provides markdown-it plugins and that it should be activated before the markdown preview is shown.
To register the plugins themselves, in your extension's
activate
function, just return an object with anextendMarkdownIt
method. This method takes a markdown-it instance and must return a modified version of that instance.VSCode's markdown extension will invoke
extendMarkdownIt
when the markdown preview is shown for the first time.Adding a Script that is Run in the Markdown Preview
If you need further customization, you can also inject a script into the markdown preview page:
scripts
should be an array of extension relative paths to javascript files. These scripts will be included on the markdown preview page. Scripts should only be used if a common mark plugin will not workThe text was updated successfully, but these errors were encountered: