Vim 语法文件对 HTML 语法更加严格

发布于 2024-11-05 03:41:43 字数 427 浏览 6 评论 0原文

我刚刚遇到了一个错误,

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

它不是

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

Vim 的 html 语法突出显示并没有区分两者。我可以从某处获得更严格的语法文件吗?

(对于讨厌者:vim 问题属于 stackoverflow,而不是超级用户

I just got bit by a bug that 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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

合久必婚 2024-11-12 03:41:43

作为权宜之计,我将 $VIMRUNTIME/syntax/html.vim 的副本放在 ~/.vim/syntax/html.vim 中并进行了修改

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

:只是捕获这个特定的错误(引号不匹配),所以我仍然对严格 html 的更好语法文件非常感兴趣。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文