Add getHtmlAttributeRe helper for creating a RegExp to match an HTML attribute name/value.

This commit is contained in:
David Anson 2023-10-18 23:45:39 -07:00
parent 531e58ed9a
commit 06466905a5
4 changed files with 36 additions and 15 deletions

View file

@ -126,6 +126,16 @@ function cloneIfUrl(url) {
}
module.exports.cloneIfUrl = cloneIfUrl;
/**
* Gets a Regular Expression for matching the specified HTML attribute.
*
* @param {string} name HTML attribute name.
* @returns {RegExp} Regular Expression for matching.
*/
module.exports.getHtmlAttributeRe = function getHtmlAttributeRe(name) {
return new RegExp(`\\s${name}\\s*=\\s*['"]?([^'"\\s>]*)`, "iu");
};
/**
* Returns true iff the input line is blank (contains nothing, whitespace, or
* comments (unclosed start/end comments allowed)).