It is a function which detects, does given string resemble XHTML or HTML. Practically, it affects closing slashes and singleton tags in the markup.
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
You can import
The algorithm is the following:
- Look for
doctype. If recognised, Bob's your uncle, here's your answer.
- IF there's no
doctypeor it's messed up beyond recognition, DO scan all singleton tags (
<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
- If (there are no tags in the input) OR (there are no doctype tags and no singleton tags), return