html_re.js 1.0 KB

12345678910111213141516171819202122232425262728
  1. // Regexps to match html elements
  2. 'use strict';
  3. var attr_name = '[a-zA-Z_:][a-zA-Z0-9:._-]*';
  4. var unquoted = '[^"\'=<>`\\x00-\\x20]+';
  5. var single_quoted = "'[^']*'";
  6. var double_quoted = '"[^"]*"';
  7. var attr_value = '(?:' + unquoted + '|' + single_quoted + '|' + double_quoted + ')';
  8. var attribute = '(?:\\s+' + attr_name + '(?:\\s*=\\s*' + attr_value + ')?)';
  9. var open_tag = '<[A-Za-z][A-Za-z0-9\\-]*' + attribute + '*\\s*\\/?>';
  10. var close_tag = '<\\/[A-Za-z][A-Za-z0-9\\-]*\\s*>';
  11. var comment = '<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->';
  12. var processing = '<[?].*?[?]>';
  13. var declaration = '<![A-Z]+\\s+[^>]*>';
  14. var cdata = '<!\\[CDATA\\[[\\s\\S]*?\\]\\]>';
  15. var HTML_TAG_RE = new RegExp('^(?:' + open_tag + '|' + close_tag + '|' + comment +
  16. '|' + processing + '|' + declaration + '|' + cdata + ')');
  17. var HTML_OPEN_CLOSE_TAG_RE = new RegExp('^(?:' + open_tag + '|' + close_tag + ')');
  18. module.exports.HTML_TAG_RE = HTML_TAG_RE;
  19. module.exports.HTML_OPEN_CLOSE_TAG_RE = HTML_OPEN_CLOSE_TAG_RE;