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

4

2 回答 2

5

在一个href属性中,和号字符应该由它的 HTML 实体来表示&amp;,否则HTML 验证器会报错。&Sublime Text 正确地将没有实体的单个标记为错误。

另请参阅HTML href/src 属性中除了与号 (&) 之外的哪些其他字符?我是否在 <a href...> 中编码 & 符号

于 2013-07-05T14:44:21.090 回答
1

虽然正如 Marcel Korpel 指出的那样,用 替换它通常是一个好主意&&amp;但在使用 angular 之类的东西时会很痛苦。您可以通过编辑和注释这些行来删除突出显示非法 & 符号的规则sublime_directory/Packages/HTML.sublime-package/HTML.tmLanguage (搜索ampersand应该可以解决问题)

<dict>
    <key>match</key>
    <string>&amp;</string>
    <key>name</key>
    <string>invalid.illegal.bad-ampersand.html</string>
</dict>

重启sublime看看效果。在 Sublime Text 3 上测试

于 2015-04-03T17:17:01.333 回答