How can I highlight unmatched HTML tags in Emacs?

对着背影说爱祢 提交于 2019-12-24 04:56:18

问题


I'd really like to catch unbalanced HTML tags as I edit HTML snippets inside Emacs. For example, JSFiddle offers this:

I've found that there's also a wrapper for weblint but that only support HTML 4.

flycheck support HTML checking using tidy, but that assumes the current buffer is a complete HTML page. I often edit templates which are included in other templates, so my buffer rarely has a <html> or a <head> in it.

How can I highlight unbalanced HTML tags, without writing full HTML documents?


回答1:


EDIT: To avoid concurrent versions the code is maintained only at:

http://www.emacswiki.org/emacs/html-check-frag.el

Please, apologize for any inconveniences caused by this decision.


The old description was: Edit: I did some bug-fixing, and I've also uploaded the file to emacswiki.

You can try the following. New and surely buggy. But, maybe it is better than nothing. Execute the lisp code, switch to the buffer with the html-fragment and activate the minor mode html-check-frag-mode.

... And here was the outdated code. ...




回答2:


If flycheck+tidy works for full pages then you can write an elisp function which is called when the file is saved, so that it pops up a temporary buffer with your file contents and with <head> and other necessary stuff added to it and then turns on flycheck in that temporary buffer, so you can see if there are unmatched tags.

It's not instant on the fly error highlighting, but at least you'll see the errors when you save the file.



来源:https://stackoverflow.com/questions/19363837/how-can-i-highlight-unmatched-html-tags-in-emacs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!