sublime icon indicating copy to clipboard operation
sublime copied to clipboard

Inside HTML chunks, some javascript syntax highlighting rules still apply

Open jessep opened this issue 12 years ago • 4 comments

Seems like js parsing rules are still applying inside html chunks, which makes writing html really hard. I've highlighted a few issues below:

  1. JS keywords are highlighted in html, which is confusing, but not terrible.
  2. Adding 'get' removes syntax highlighting from all remaining code in a fn
  3. Adding a single ' makes the rest of the file look like it is inside a string. That's kinda inconvenient.

image

jessep avatar Dec 06 '13 01:12 jessep

Ping

dvdplm avatar Dec 23 '13 08:12 dvdplm

I'm seeing this too. No idea how to fix it though. :(

bslatkin avatar May 01 '14 01:05 bslatkin

10980f017151844767941a9e2ff04917200f00a6 fixes the common case where quotes surrounded by letters are interpreted as strings:

var component = <div>Hello, y'all!</div>; // Should now work.

Unfortunately, syntax highlighting uses regular expressions for speed reasons, and JavaScript (including JSX) are not regular languages. (Still, we can probably do better, but not without significantly refactoring the language file.)

To work around this at Facebook (when it comes up), we've been using expression interpolation:

var component = <div>All of my friends{"'"} photos are cooler than mine.</div>;

Kind of lame, but not the end of the world. I hope this helps, and I welcome any PRs that attempt to provide a better solution.

yungsters avatar May 01 '14 02:05 yungsters

It's working! Thank you!

bslatkin avatar May 01 '14 04:05 bslatkin