Skip to content

Expose theme name in webviews#98128

Merged
mjbvz merged 2 commits intomicrosoft:masterfrom
mjbvz:webview-data-theme
May 20, 2020
Merged

Expose theme name in webviews#98128
mjbvz merged 2 commits intomicrosoft:masterfrom
mjbvz:webview-data-theme

Conversation

@mjbvz
Copy link
Copy Markdown
Collaborator

@mjbvz mjbvz commented May 19, 2020

Fixes #97663

Adds a data attribute data-vsccode-theme to webviews with the current theme name. This is lets extensions write theme specific css for webviews, for example:

body[data-vscode-theme-name="One Dark Pro"] {
    background: red;
}

Fixes microsoft#97663

Adds a data attribute to webviews with the theme name. This is lets extensions write theme specific css for webviews
@mjbvz mjbvz requested a review from aeschli May 19, 2020 03:36
@mjbvz mjbvz self-assigned this May 19, 2020
@mjbvz mjbvz added this to the May 2020 milestone May 19, 2020
@aeschli
Copy link
Copy Markdown
Contributor

aeschli commented May 19, 2020

There are hundreds of existing themes out there and they can be updated anytime. I don't see how a webview provider could keep track with that.
It were better if views don't define theme specific colors, but that an existing color of a theme is used (or a derivative of it (darker/lighter/mix).

Can you explain the use case?

@Binaryify
Copy link
Copy Markdown

Binaryify commented May 19, 2020

here is the origin issue, Binaryify/OneDark-Pro#388
and this is the feature request #97663
I want custom markdown preview color highlight to make markdown style have more consistent with theme, so I write some css with the "markdown.previewStyles" in the package.json, but then I found it also actived in other themes too, this cause some problems, and don't have any way to limit that

Here's a comparison with custom markdown preview
image
image
image

@aeschli
Copy link
Copy Markdown
Contributor

aeschli commented May 19, 2020

Ok, I see a theme wants to style the markdown preview through markdown.styles.
@mjbvz If it's just for that background color, can't the Markdown define a new color so that all themes can easily theme it? That's more in the spirit of theming.

@Binaryify
Copy link
Copy Markdown

Binaryify commented May 19, 2020

@aeschli no just for background color, include the code highlight and the elements style
image

image

@mjbvz
Copy link
Copy Markdown
Collaborator Author

mjbvz commented May 19, 2020

@aeschli Extensions should use the normal theme color variables in almost all cases. We also already expose the theme kind (light, dark, high contrast)

The theme name is helpful if you want to write CSS that is only enabled in one specific theme. For example, the official GitHub theme may contribute CSS rules to the markdown preview that are only enabled when the GitHub theme is active

vscode-theme-kind is generic kind: light, dark, high contrast. We already expose this as a classname but for conistency also want to have it as an attribute
@mjbvz mjbvz merged commit 210167b into microsoft:master May 20, 2020
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

support limit markdown.styles active in single theme

3 participants