headwind icon indicating copy to clipboard operation
headwind copied to clipboard

Support for Svelte Sass tags.

Open braebo opened this issue 4 years ago • 7 comments

Is your feature request related to a problem? Please describe. Headwind cannot detect Tailwind classes in <style lang="sass"> tags in Svelte components.

Describe the solution you'd like It would be awesome if I could use Headwind in Svelte components using Sass.

Describe alternatives you've considered Getting better at Regex to add my own fix / reaching out to Svelte-Preprocess or Svelte-VSCode devs for a fix.

Additional context Not detected by headwind: Screenshot 2020-09-30 at 2 00 44 PM

Let me know the best route for me to take in order to get this working (reaching out to the other projects mentioned / implementing my own fix).

braebo avatar Sep 30 '20 18:09 braebo

I've never used Svelte, nor did I handle a lot of the regex stuff this extension uses so I can't help you here unfortunately. If you figure something out feel free to share so I can add support.

heybourn avatar Oct 06 '20 11:10 heybourn

The problem is that Svelte does single file components, so css and html are in one place (that's possible for html, too, btw). So what would be needed is some kind of advanced regex which in addition to the html class regex also checks if we are in a style tag, and if yes, apply the css regex.

dummdidumm avatar Oct 16 '20 10:10 dummdidumm

@FractalHQ

add following lines in .vscode/settings.json

    "headwind.classRegex": {
        "css": "\\B@apply\\s+([_a-zA-Z0-9\\s\\-\\:\\/]+);",
        "html": "\\bclass\\s*=\\s*[\\\"\\']([_a-zA-Z0-9\\s\\-\\:\\/]+)[\\\"\\']",
        "javascript": "(?:\\bclassName\\s*=\\s*[\\\"\\']([_a-zA-Z0-9\\s\\-\\:\\/]+)[\\\"\\'])|(?:\\btw\\s*`([_a-zA-Z0-9\\s\\-\\:\\/]*)`)",
        "javascriptreact": "(?:\\bclassName\\s*=\\s*[\\\"\\']([_a-zA-Z0-9\\s\\-\\:\\/]+)[\\\"\\'])|(?:\\btw\\s*`([_a-zA-Z0-9\\s\\-\\:\\/]*)`)",
        "svelte": "\\B@apply\\s+([_a-zA-Z0-9\\s\\-\\:\\/]+)",
        "typescript": "(?:\\bclassName\\s*=\\s*[\\\"\\']([_a-zA-Z0-9\\s\\-\\:\\/]+)[\\\"\\'])|(?:\\btw\\s*`([_a-zA-Z0-9\\s\\-\\:\\/]*)`)",
        "typescriptreact": "(?:\\bclassName\\s*=\\s*[\\\"\\']([_a-zA-Z0-9\\s\\-\\:\\/]+)[\\\"\\'])|(?:\\btw\\s*`([_a-zA-Z0-9\\s\\-\\:\\/]*)`)"
    },

this works for me.

tshemeng avatar Dec 09 '20 02:12 tshemeng

@tshemeng would you happen to have a REGEX I could use for Pug?

heybourn avatar Dec 09 '20 02:12 heybourn

@tshemeng would you happen to have a REGEX I could use for Pug?

what do you mean Pug ?

tshemeng avatar Dec 09 '20 02:12 tshemeng

@heybourn I think Pug's syntax prevented solving it with simple REGEX, I'm no idea for this.

tshemeng avatar Dec 09 '20 02:12 tshemeng

The regex works but only when triggered manually. Is there a way to apply it on save?

pikeas avatar Apr 08 '21 19:04 pikeas