Problem with syntax/html.vim

51 views
Skip to first unread message

Gary Johnson

unread,
May 17, 2013, 2:32:36 AM5/17/13
to vim...@googlegroups.com
I was editing an HTML file (the contents of an Outlook message) when
I noticed that the syntax highlighting was messed up in certain
regions. The problem can be seen when the following snippet is
highlighted as HTML.

<html>
<head>

<!--[if gte mso 9]><xml>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
</xml><![endif]-->

</head>
</html>

The highlighting is correct through the '--', but they incorrectly
terminate the comment region. The following '"/' are highlighted as
an error, as are '[endif]', and the </head> and </html> tags are
highlighted as comments.

The problem seems to be this line in $VIMRUNTIME/syntax/html.vim
(dated 2012 Oct 05),

syn region htmlCommentPart contained start=+--+ end=+--\s*+ contains=@htmlPreProc,@Spell

which doesn't account for the possibility of '--' being anywhere
within a string.

I don't know enough about syntax highlighting to know how to fix it,
though, and I would rather help the author with a solution than just
point out the problem, so I thought I'd ask here if anyone knew of a
solution. (I have Bcc'd the author.)

Regards,
Gary

glts

unread,
May 17, 2013, 5:11:51 AM5/17/13
to vim...@googlegroups.com, gary...@spocom.com
Gary,

On Friday, May 17, 2013 8:32:36 AM UTC+2, Gary Johnson wrote:
> The highlighting is correct through the '--', but they incorrectly
> terminate the comment region. The following '"/' are highlighted as
> an error, as are '[endif]', and the </head> and </html> tags are
> highlighted as comments.
>
> The problem seems to be this line in $VIMRUNTIME/syntax/html.vim
> (dated 2012 Oct 05),
>
> syn region htmlCommentPart contained start=+--+ end=+--\s*+ contains=@htmlPreProc,@Spell
>
> which doesn't account for the possibility of '--' being anywhere
> within a string.
>
> I don't know enough about syntax highlighting to know how to fix it,
> though, and I would rather help the author with a solution than just
> point out the problem, so I thought I'd ask here if anyone knew of a
> solution. (I have Bcc'd the author.)

Double dash isn't allowed in XML comments. I think the highlighting is
correct as it is.

Gary Johnson

unread,
May 17, 2013, 2:09:09 PM5/17/13
to vim...@googlegroups.com
Thank you. Your answer prompted me to do a little research which
confirmed it.

http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.4
http://stackoverflow.com/questions/442786/are-nested-html-comments-possible

So, Outlook generates invalid HTML. What a surprise.

I have a workaround, so I'll use that when syntax highlighting
Outlook messages.

Regards,
Gary

Reply all
Reply to author
Forward
0 new messages