Reputation: 4803
I'm writing what I understand to be pretty standard PHP/HTML code. Imitating a rough RESTful architecture, inspired by Rails, in PHP. My pages contain lots of dynamically generated links that are structured like this:
<a href='objects_list.php?coursekey=<? echo $coursekey; ?>&delete_section=<?
echo $row['key']; ?>'>delete</a>
As you can see, the link has two URL variables, each of which is set based on PHP variables that the page knows about. Pretty common, right?
I recently moved to Sublime Text 2 as my primary development environment. I think it's fantastic and my development process is much improved. But Sublime's syntax highlighting seems to get confused by the ampersands (&) that separate URL variables in any links. It highlights each ampersand in red as though thinking I made an error.
Any idea why? Any way to make Sublime recognize that links often need to have ampersands in them?
EDIT: This happens whether or not PHP fragments are contained in the link href. Sublime just seems to mistrust ampersands in links...?
Upvotes: 3
Views: 1147
Reputation: 71
While as Marcel Korpel pointed out, its generally a good idea to replace &
by &
, its a pain when using something like angular. You can remove the rule to highlight illegal ampersands by editing sublime_directory/Packages/HTML.sublime-package/HTML.tmLanguage
and commenting these lines (searching for ampersand
should do the trick)
<dict>
<key>match</key>
<string>&</string>
<key>name</key>
<string>invalid.illegal.bad-ampersand.html</string>
</dict>
Restart sublime to see the effect. Tested on Sublime Text 3
Upvotes: 1
Reputation: 21763
Within an href
attribute, ampersand characters should be represented by its HTML entity &
, otherwise the HTML validator will complain. Sublime Text correctly marks a single &
without an entity as erroneous.
See also What other characters beside ampersand (&) should be encoded in HTML href/src attributes? and Do I encode ampersands in <a href...>?
Upvotes: 5