开发者

Vim syntax file to be stricter about HTML syntax

I just got bit by a bug tha开发者_如何学Ct was

 <link rel=stylesheet" type="text/css" href="stylesheet.css" media="all">

rather than

 <link rel="stylesheet" type="text/css" href="stylesheet.css" media="all">

It seems like vim's syntax highlighting for html doesn't differentiate between the two. Is there a stricter syntax file I can get from somewhere?

(and for the haters: vim questions belong on stackoverflow, not superuser)


As a stop-gap measure, I put a copy of $VIMRUNTIME/syntax/html.vim in ~/.vim/syntax/html.vim and modified it:

38c38
< syn match   htmlValue    contained "=[\t ]*[^'" \t>][^ \t>]*"hs=s+1   contains=javaScriptExpression,@htmlPreproc
---
> syn match   htmlValue    contained /=[\t ]*\%('\%(\\.\|[^\\']\)*'\|"\%(\\.\|[^\\"]\)*\|[^'" \t>]*\)/hs=s+1   contains=htmlString,javaScriptExpression,@htmlPreproc
40c40
< syn region  htmlTag                start=+<[^/]+   end=+>+ contains=htmlTagN,htmlString,htmlArg,htmlValue,htmlTagError,htmlEvent,htmlCssDefinition,@htmlPreproc,@htmlArgCluster
---
> syn region  htmlTag                start=+<[^/]+   end=+>+ contains=htmlTagN,htmlArg,htmlValue,htmlTagError,htmlEvent,htmlCssDefinition,@htmlPreproc,@htmlArgCluster
43a44
> syn match   htmlTagError contained /['"].*/
168c169
<   syn region  htmlScriptTag     contained start=+<script+ end=+>+       contains=htmlTagN,htmlString,htmlArg,htmlValue,htmlTagError,htmlEvent
---
>   syn region  htmlScriptTag     contained start=+<script+ end=+>+       contains=htmlTagN,htmlArg,htmlValue,htmlTagError,htmlEvent

This just catches this particular error (mismatched quotes), so I'm still very interested in a better syntax file for strict html.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜