Skip to content
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

CSS syntax highlighting for lit-element styles? #70

Open
chase-moskal opened this issue Apr 18, 2019 · 9 comments
Open

CSS syntax highlighting for lit-element styles? #70

chase-moskal opened this issue Apr 18, 2019 · 9 comments

Comments

@chase-moskal
Copy link

✔️ i've found that the extension works great to bring syntax highlighting to my lit-html render blocks:

render() {
  return html`<div awesome>cool!</div>`
}

❓ however i was surprised that we don't have syntax highlighting for lit-element css styles

get styles() {
  return css`.system { display: flex; }`
}

is there a way i can get the syntax highlighting for lit-element styles?

👋 cheers

@chase-moskal
Copy link
Author

i find it very interesting that github markdown has highlighted the above html code, but not the css code

@chase-moskal chase-moskal changed the title Syntax highlighting for lit-element styles? CSS syntax highlighting for lit-element styles? Apr 18, 2019
@wolojo
Copy link

wolojo commented Apr 30, 2019

Maybe not the answer you were waiting for, but if you include your styles in HTML the syntax highlighting will work:

get styles() {
  return html`
     <style>
         .system { display: flex; }
     </style>

}`

@chase-moskal
Copy link
Author

@wolojoli — hey that's a nice workaround :)

since the css tagged-template function comes with lit-html, i say it's in-scope for this extension

@mjbvz — let us know if you have any advice on how we might implement this css-highlighting feature

@nalply
Copy link

nalply commented Dec 31, 2019

However lit-element says in https://lit-element.polymer-project.org/guide/styles#add-styles: "For optimal performance, define scoped styles in a static styles property."

@PeteX
Copy link

PeteX commented Jan 3, 2020

Another workaround if you are using Webpack is to put your styles in a separate file, then use raw-loader to bring them in as a string. This also has the advantage that you can use Sass or other preprocessors on the styles if you want.

webpack.config.js:

module: {
  rules: [
    {
      test: /\.css$/,
      loader: 'raw-loader'
    }, {
      test: /\.s[ac]ss$/,
      use: [
        'raw-loader',
        'sass-loader'
      ]
    }
  ]
}

whatever.ts:

import styles from './whatever.scss';

...

export class Whatever extends LitElement {
  static styles = unsafeCSS(styles);

  ...
}

@pepoospina
Copy link

VScode has https://marketplace.visualstudio.com/items?itemName=runem.lit-plugin

@realh
Copy link

realh commented Mar 4, 2020

I'm using lit-plugin, which does include css support. However, it seems to make Code lag noticeably more than when using lit-html, and I can't turn off certain unwanted warnings, so it would be good if lit-html could support css.

@muleyprasad
Copy link

VScode has https://marketplace.visualstudio.com/items?itemName=runem.lit-plugin

Thanks for posting this! Intellisense for css is working as well.

@rwalle
Copy link

rwalle commented Aug 24, 2023

This can be easily supported by adding a file in syntaxes/ folder and adding the info the package.json. Basically you take what is in lit-html-svg.json, tweak a few things for css and you have it. I would love to create a pull request, but given that the author does not seem to be actively reviewing and merging requests, not sure I should bother that.

Alternatively, one is able to patch the installed version of the extension (under ~/.vscode/extensions/bierner.lit-html-1.11.1) get this feature. I can write down some instructions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants