Splay out attribute recognizer
authorDuncan Beevers <duncan@dweebd.com>
Sat, 26 Jul 2014 21:10:03 +0000 (16:10 -0500)
committerDuncan Beevers <duncan@dweebd.com>
Sat, 26 Jul 2014 21:10:03 +0000 (16:10 -0500)
src/htmlparser.js

index 35435fd..70895b4 100644 (file)
       startTagClose = /\s*(\/?)>/,
       endTag = /^<\/([\w:-]+)[^>]*>/,
       endingSlash = /\/>$/,
-      singleAttr = /([\w:-]+)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|([^>\s]+)))?/,
+      singleAttrIdentifier = /([\w:-]+)/,
+      singleAttrAssign = /=/,
+      singleAttrValues = [
+        /"((?:\\.|[^"])*)"/.source, // attr value double quotes
+        /'((?:\\.|[^'])*)'/.source, // attr value, single quotes
+        /([^>\s]+)/.source          // attr value, no quotes
+      ],
       doctype = /^<!DOCTYPE [^>]+>/i,
       startIgnore = /<(%|\?)/,
       endIgnore = /(%|\?)>/;
   }
 
   function attrForHandler( handler ) {
+    var singleAttr = new RegExp(
+      singleAttrIdentifier.source
+      + '(?:\\s*'
+      + singleAttrAssign.source
+      + '\\s*'
+      + '(?:'
+      + singleAttrValues.join('|')
+      + ')'
+      + ')?'
+    );
+
     if ( handler.customAttrSurround ) {
       var attrClauses = [];
       for ( var i = handler.customAttrSurround.length - 1; i >= 0; i-- ) {