html_re.mjs 992 B

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