Search code examples
htmlemacselispflymake

How can I highlight unmatched HTML tags in Emacs?


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

jsfiddle highlighting tags

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?


Solution

  • 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. ...