philipwalton/html-inspector

Feature Request: Check for unclosed tags

nychng opened this issue · 4 comments

I really like this. Would be super awesome if it can also check for unclosed HTML tags like missing divs.

Unfortunately this is not as easy as it looks.

Since HTML Inspector runs in the browser on live DOM, it's inspecting elements that have already been parsed and altered by the browser. That means that if the browser has corrected some of your unclosed tags, HTML Inspector sees them as properly closed.

The only way to actually validate raw markup from inside the browser would be to do an AJAX request for the content and parse the returned text yourself, which would be a lot of work and, at this point, is not something I'm planning on doing with HTML Inspector.

But who knows, maybe I'll change my mind in the future. Anyway, thanks for the suggestion.

@nychng You could do that with an HTML validator (which you pass the original/source HTML as text).

Hey @philipwalton,

I reckon I could help you implement this. As you said, the raw HTML could be accessed by sending an Ajax request to the URL of the current page.

I wouldn't go and reinvent the wheel by parsing the returned text, but instead POST it to http://validator.nu. I know from experience that validator.nu supports CORS, so we would be able to make the request from the page being tested and get a response. This would be similar to what I did in http://validator.keegan.st

We would probably then need to parse the errors returned from validator.nu and give the user a way to filter out the errors they don't care about. Again I would be able to leverage some of the code I wrote for validator.keegan.st

Do you think this would be useful?

Cheers

@keeganstreet I like this idea a lot. I actually had the same thought when I was pondering how to detect closing tags. But I'm worried it might introduce too much disconnect from HTML Inspector's current scope.

HTML Inspector's main selling point is it works on live DOM. That means it can check your HTML after your backbone views have been rendered and after your jQuery plugins have finished thrashing your initial DOM.

If we introduced pre-browser parsed validation, we'd either have to filter out most of those errors or live with duplicates. It would also not respect the config options like which node to start from or which subtrees to exclude, so that might introduce some confusion.

Anyway, I want to think about it a bit more before deciding against it, but those are my initial thoughts on the idea.