| 117 | | var named = {}, |
| 118 | | numeric = [], |
| 119 | | pattern, match; |
| 120 | | |
| 121 | | // This regular expression is reused from `shortcode_parse_atts()` |
| 122 | | // in `wp-includes/shortcodes.php`. |
| 123 | | // |
| 124 | | // Capture groups: |
| 125 | | // |
| 126 | | // 1. An attribute name, that corresponds to... |
| 127 | | // 2. a value in double quotes. |
| 128 | | // 3. An attribute name, that corresponds to... |
| 129 | | // 4. a value in single quotes. |
| 130 | | // 5. An attribute name, that corresponds to... |
| 131 | | // 6. an unquoted value. |
| 132 | | // 7. A numeric attribute in double quotes. |
| 133 | | // 8. An unquoted numeric attribute. |
| 134 | | pattern = /(\w+)\s*=\s*"([^"]*)"(?:\s|$)|(\w+)\s*=\s*\'([^\']*)\'(?:\s|$)|(\w+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|(\S+)(?:\s|$)/g; |
| 135 | | |
| 136 | | // Map zero-width spaces to actual spaces. |
| 137 | | text = text.replace( /[\u00a0\u200b]/g, ' ' ); |
| 138 | | |
| 139 | | // Match and normalize attributes. |
| 140 | | while ( (match = pattern.exec( text )) ) { |
| 141 | | if ( match[1] ) { |
| 142 | | named[ match[1].toLowerCase() ] = match[2]; |
| 143 | | } else if ( match[3] ) { |
| 144 | | named[ match[3].toLowerCase() ] = match[4]; |
| 145 | | } else if ( match[5] ) { |
| 146 | | named[ match[5].toLowerCase() ] = match[6]; |
| 147 | | } else if ( match[7] ) { |
| 148 | | numeric.push( match[7] ); |
| 149 | | } else if ( match[8] ) { |
| 150 | | numeric.push( match[8] ); |
| 151 | | } |
| 152 | | } |
| 153 | | |
| 154 | | return { |
| 155 | | named: named, |
| 156 | | numeric: numeric |
| 157 | | }; |
| | 117 | return wp.html._attrs( text, { dashesInNames: false } ); |
| | 242 | |
| | 243 | _attrs: function( text, options ) { |
| | 244 | var named = {}, |
| | 245 | numeric = [], |
| | 246 | pattern, match, namePattern; |
| | 247 | |
| | 248 | options = options || {}; |
| | 249 | _.defaults( options, { |
| | 250 | dashesInNames: true |
| | 251 | } ); |
| | 252 | |
| | 253 | // This regular expression is reused from `shortcode_parse_atts()` |
| | 254 | // in `wp-includes/shortcodes.php`. |
| | 255 | // |
| | 256 | // Capture groups: |
| | 257 | // |
| | 258 | // 1. An attribute name, that corresponds to... |
| | 259 | // 2. a value in double quotes. |
| | 260 | // 3. An attribute name, that corresponds to... |
| | 261 | // 4. a value in single quotes. |
| | 262 | // 5. An attribute name, that corresponds to... |
| | 263 | // 6. an unquoted value. |
| | 264 | // 7. A numeric attribute in double quotes. |
| | 265 | // 8. An unquoted numeric attribute. |
| | 266 | namePattern = options.dashesInNames ? '[\\w\\-]' : '\\w'; |
| | 267 | pattern = new RegExp( '('+namePattern+'+)\\s*=\\s*"([^"]*)"(?:\\s|$)|(\\w+)\\s*=\\s*\'([^\']*)\'(?:\\s|$)|(\\w+)\\s*=\\s*([^\\s\'"]+)(?:\\s|$)|"([^"]*)"(?:\\s|$)|(\\S+)(?:\\s|$)', 'g' ); |
| | 268 | |
| | 269 | // Map zero-width spaces to actual spaces. |
| | 270 | text = text.replace( /[\u00a0\u200b]/g, ' ' ); |
| | 271 | |
| | 272 | // Match and normalize attributes. |
| | 273 | while ( (match = pattern.exec( text )) ) { |
| | 274 | if ( match[1] ) { |
| | 275 | named[ match[1].toLowerCase() ] = match[2]; |
| | 276 | } else if ( match[3] ) { |
| | 277 | named[ match[3].toLowerCase() ] = match[4]; |
| | 278 | } else if ( match[5] ) { |
| | 279 | named[ match[5].toLowerCase() ] = match[6]; |
| | 280 | } else if ( match[7] ) { |
| | 281 | numeric.push( match[7] ); |
| | 282 | } else if ( match[8] ) { |
| | 283 | numeric.push( match[8] ); |
| | 284 | } |
| | 285 | } |
| | 286 | |
| | 287 | return { |
| | 288 | named: named, |
| | 289 | numeric: numeric |
| | 290 | }; |
| | 291 | }, |
| | 292 | |