Skip to content

Instantly share code, notes, and snippets.

View kirpichev's full-sized avatar

Maxim Kirpichev kirpichev

View GitHub Profile
@Munawwar
Munawwar / html-validator.js
Last active April 18, 2022 07:38
Unbalanced HTML markup detection
/**
* Detect unsafe (and potentially unsafe) unbalanced tags in a given HTML snippet.
* Hints taken from an html parse (https://gist.github.com/cburgmer/2877758).
*
* Example:
* An unclosed div tag is considered unsafe, because if the snippet is pasted in between two div tags
* then it could end up breaking the HTML document.
* Self closing tags (tags that you can intentioanlly leave open like <table><tr><td>some text</table>) are also considered unsafe, for the same reason.
* However an unclosed void tag (like meta tag) is safe, because browsers will ignore it without any side effects.
*