Installation
Quick Take
Purpose
It is a function which detects, does given string resemble XHTML or HTML. Practically, it affects closing slashes and singleton tags in the markup.
API — detectIsItHTMLOrXhtml()
The main function detectIsItHTMLOrXhtml()
is imported like this:
It’s a function which takes one argument:
If the input is not String type, this package will throw an error. If the input is missing completely, it will return null
.
API — version
You can import version
:
Under the hood
The algorithm is the following:
- Look for
doctype
. If recognised, Bob’s your uncle, here’s your answer. - IF there’s no
doctype
or it’s messed up beyond recognition, DO scan all singleton tags (<img>
,<br>
and<hr>
) and see which type the majority is (closed or not closed). - In a rare case when there is an equal amount of both closed and unclosed tags, lean for
html
. - If (there are no tags in the input) OR (there are no doctype tags and no singleton tags), return
null
.