简体   繁体   English

Sublime Text:在带有PHP片段的HTML链接中,&符号突出显示为红色?

[英]Sublime Text: in HTML links having PHP snippets, ampersands highlight red?

I'm writing what I understand to be pretty standard PHP/HTML code. 我正在编写我理解为非常标准的PHP / HTML代码。 Imitating a rough RESTful architecture, inspired by Rails, in PHP. 在PHP中模仿一个粗略的RESTful架构,受Rails的启发。 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. 如您所见,该链接有两个URL变量,每个变量都是根据页面知道的PHP变量设置的。 Pretty common, right? 很常见,对吗?

I recently moved to Sublime Text 2 as my primary development environment. 我最近转向Sublime Text 2作为我的主要开发环境。 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. 但Sublime的语法突出显示似乎被在任何链接中分隔URL变量的&符号(&)弄糊涂了。 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? 有什么方法可以让Sublime认识到链接通常需要在其中加上&符号?

EDIT : This happens whether or not PHP fragments are contained in the link href. 编辑 :无论PHP片段是否包含在链接href中,都会发生这种情况。 Sublime just seems to mistrust ampersands in links...? Sublime似乎在链接中不信任&符号......?

Within an href attribute, ampersand characters should be represented by its HTML entity &amp; href属性中,&符号应由其HTML实体&amp;表示&amp; , otherwise the HTML validator will complain. 否则HTML验证器会抱怨。 Sublime Text correctly marks a single & without an entity as erroneous. Sublime Text正确地将单个&没有实体标记为错误。

See also What other characters beside ampersand (&) should be encoded in HTML href/src attributes? 另请参见&amp;(&)旁边的其他字符应该在HTML href / src属性中编码? and Do I encode ampersands in <a href...>? 我在<a href...>中编码&符号吗?

While as Marcel Korpel pointed out, its generally a good idea to replace & by &amp; 虽然马塞尔Korpel指出,其通常是一个好主意,以取代&&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) 您可以通过编辑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>

Restart sublime to see the effect. 重新启动sublime以查看效果。 Tested on Sublime Text 3 在Sublime Text 3上测试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM