Minimalistic and ultra-fast HTML parser & matcher
npm install @emmetio/html-matcherFinds matching opening and closing tag pair for given location in HTML/XML source:
``js
import match from '@emmetio/html-matcher';
const content = '
';// Find tag pair at character 35
const tag = match(content, 35);
console.log(tag.name); // Name of matched tag: "a"
console.log(tag.open); // Range of opening tag: [5, 31]
console.log(tag.end); // Range of closing tag: [38, 42]
// List of attributes found in opening tag
console.log(tag.attributes);
`
By default, matcher works in HTML, which means if it finds tag name which is known to be empty (for example, ) it will not search for it’s closing part. However, such behavior might be unexpected for XML syntaxes where all tags should be either self-closed or provide closing part. In this case, you should pass xml: true option to properly handle XML mode:
`js
import match from '@emmetio/html-matcher';
const content = '
console.log(html.name); // "img"
console.log(html.open); // [5, 10]
console.log(html.close); // undefined
console.log(xml.name); // "img"
console.log(xml.open); // [5, 10]
console.log(xml.close); // [17, 23]
`
In HTML, some tags has special meaning. For example, a tag. But, if