Sublime Text 2 HTML5 syntax highlight

Go To StackoverFlow.com

5

Im using sublime to edit html5 docs. But when I started to do quote-free editing like:

<div id=asdf>

instead of

<div id="asdf">

its syntax highlight gone crazy.

enter image description here

Any ideas how to solve this? Is there other up to date parser for sublime?

ty

2012-04-04 08:36
by zsitro
Why would you do quote free editing - red-X 2012-04-04 08:38
I dont want to enter 2 unnecessary chars if its not require - zsitro 2012-04-04 08:50
Were you able to get this going? i'm having the same issu - Hugo Forte 2012-08-02 14:28
switched to phpStorm : - zsitro 2012-08-06 08:24
This is an irritation for me as well. I would love to drop the quotes and not have syntax highlighting go stupid - Nathan Cox 2012-09-13 20:00
Well, it is not required, but highly recommended... http://www.w3schools.com/html/html_attributes.as - Qwerty 2013-02-19 16:55


5

This Sublime Text thread suggests a way to fix it: http://www.sublimetext.com/forum/viewtopic.php?f=3&t=8129

Open up your HTML.tmLanguage (in ~/.config/sublime-text-2/Packages/HTML) and look for this:

  <string>(?&lt;='|")</string>
  <key>name</key>
  <string>meta.attribute-with-value.id.html</string>

Change the first line to

<string>(?&lt;==|='|=")</string>

Your unquoted values won't be highlighted in the same way that quoted values are highlighted, but it will at least prevent the syntax highlighting from completely breaking.

2013-03-21 23:01
by Cory Gagliardi


3

Quote free html is not a good idea. I recommend you to use quotes. The bytes you will save are not worth the aggravation is going to cost you.

2012-04-04 13:50
by Enrique Moreno Tent
Tnaks for your opinion. My question was not related to this answer - zsitro 2012-04-05 07:12
Regardless of whether or not the question was related to @Dbugger's answer, this is important information for anyone else seeking information about this. What you're doing is poor practice and error prone. Especially when multiple classes are used or considering that HTML5 allows single-word attributes without values, like "selected", versus XHTML, "selected="selected". This is just a warning label on your question... I can't even conceive of someone doing this still in 2012 - jonschlinkert 2012-11-29 21:17
@Dbugger: Supporting bad ideas is a bad idea - Josh Campbell 2013-02-01 10:21
If it was that bad it would not have become standard. The editor supporting the standard is a better idea than the editor supporting YOUR standard. God the ignorance. Force someone else onto a certain choice, okay?

There's no reason to consider it a bad idea. It's about as bad as not requiring ';' after statements, often it's great. Python is considered "not a bad idea" by most. If you're not an idiot you'll never do it wrong, it's dead simple - Lodewijk 2013-07-25 20:14



-1

I have to go with Dbugger on this one. I feel compelled not to assist in helping you configure Sublime to "not report" bad HTML practices. With that said, the answer to your question is- typing in the quotations will eliminate the weird highlighting in Sublime.

2012-04-22 03:54
by Josh Campbell
The HTML5 specs clearly state that single word attribute values without quotes is entirely valid, meaning "not bad practice" - Nathan Cox 2012-09-13 19:59
Driving your car into a wall without a seatbelt is entirely valid, just not very smart. If you're going to learn something, learn it right.

XAML: "The attribute name is followed by an assignment operator (=). The attribute value must be a string enclosed within quotes."

XML: "Rule Three - All XML attributes must have quotes around them"

XHTML: "Here are some examples of XHTML rules:... All XHTML attribute values must be quoted. "

HTML5: "Just like in HTML, there are cases where the quotes around the attribute value can be omitted, but doing it blindly will likely result in broken code: - Josh Campbell 2012-10-29 23:02

XHTML isn't HTML5, XML isn't HTML5 either and XAML certainly isn't HTML5. HTML5 allows omission of quotes around attribute values in specific and well-defined cases. To be precise: "A valid unquoted attribute value in HTML is any string of text that is not the empty string and that doesn’t contain spaces, tabs, line feeds, form feeds, carriage returns, ", ', `, =, <, or >." Since this question is about syntax highlighting, the highlighting should work properly when quotes are validly omitted, and indicate situations where it is done invalidly - Zr40 2012-12-28 22:36
XML < JSON. HTML != XML. HTML != JSON. HTML == HTML. Driving your car into a wall with a seatbelt is entirely valid, just not very smart. As long as you do it right, there's no problem. Seatbelts or not. "Government" (HTML5 workgroup) decided to let people choose by themselves because this is nothing like driving cars and it's actually very safe, make the car stop beeping like crazy please - Lodewijk 2013-07-25 20:17
Ads