3

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...?

Topher Hunt
  • 4,404
  • 2
  • 27
  • 51
  • Don't know if you're using the Monokai theme or that it occurs on all themes? But anyway, you could use the entity name, so `&` instead of just `&` – Nick R Jul 05 '13 at 14:36

2 Answers2

5

Within an href attribute, ampersand characters should be represented by its HTML entity &amp;, 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...>?

Community
  • 1
  • 1
Marcel Korpel
  • 21,536
  • 6
  • 60
  • 80
1

While as Marcel Korpel pointed out, its generally a good idea to replace & by &amp;, 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>&amp;</string>
    <key>name</key>
    <string>invalid.illegal.bad-ampersand.html</string>
</dict>

Restart sublime to see the effect. Tested on Sublime Text 3

Bhavin
  • 61
  • 1
  • 4