Styled-jsx: vim syntax highlighting?

Created on 4 May 2017  ·  6Comments  ·  Source: vercel/styled-jsx

Would be great to have docs on supporting syntax highlighting in vim 😄

help wanted syntax highlighing

Most helpful comment

🙌

I got it working and pushed it to a new repo: alampros/vim-styled-jsx

Screenshot:

screen shot 2017-06-15 at 9 47 39 am

All 6 comments

I use this for jsx. Has been working fine with styled-jsx too:

https://github.com/heavenshell/vim-prettier

@pak11273 that plugin just runs prettier doesn't it? I don't see how/why it would add syntax highlighting?

no syntax highlighting. I thought it did at first because I put the css values in quotes. But I just found out those values don't need quotes. I guess we have to wait til someone builds a plugin for it.

I'm _horrible_ with vim syntax, but I started messing around with the vim-jsx syntax and made a tiny amount of progress on this. Here's what I modified:

diff --git after/syntax/jsx.vim after/syntax/jsx.vim
index 5813a67..69d6f9c 100644
--- after/syntax/jsx.vim
+++ after/syntax/jsx.vim
@@ -40,6 +40,11 @@ syn region xmlString contained start=+{+ end=++ contains=jsBlock,javascriptBlock
 syn region jsxChild contained start=+{+ end=++ contains=jsBlock,javascriptBlock
   \ extend

+syn include @CssSyntax $VIMRUNTIME/syntax/css.vim
+
+syn region styledJsxTag start=/<style.*jsx>/ end=+</style>+ containedin=jsxRegion contains=@CssSyntax,jsxCssTemplateString transparent
+syn region jsxCssTemplateString start=+`+ end=+`+ containedin=styledJsxTag contains=@CssSyntax
+
 " Highlight JSX regions as XML; recursively match.
 "
 " Note that we prohibit JSX tags from having a < or word character immediately

With this change, the syntax was identified correctly as a jsxCssTemplateString, but I couldn't get it to recognize the contents as CSS. 🤷‍♂️

screen shot 2017-06-14 at 4 33 24 pm

Anybody have any ideas as to how I might get this working?

Hmmm... might be able to take a page from the vim-styled-components plugin. They have to detect an import of their module, while here we would only have to detect the jsx attribute on the <style> tag.

🙌

I got it working and pushed it to a new repo: alampros/vim-styled-jsx

Screenshot:

screen shot 2017-06-15 at 9 47 39 am

Was this page helpful?
0 / 5 - 0 ratings

Related issues

davibe picture davibe  ·  5Comments

ryandeussing picture ryandeussing  ·  3Comments

corysimmons picture corysimmons  ·  4Comments

stevensacks picture stevensacks  ·  4Comments

etiennejcharles picture etiennejcharles  ·  3Comments