wp/wp-includes/js/shortcode.js
author ymh <ymh.work@gmail.com>
Tue, 15 Dec 2020 13:49:49 +0100
changeset 16 a86126ab1dd4
parent 9 177826044cd9
permissions -rw-r--r--
update enmi-conf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
     1
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
     2
 * Utility functions for parsing and handling shortcodes in JavaScript.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
     3
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
     4
 * @output wp-includes/js/shortcode.js
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
     5
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
     7
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
     8
 * Ensure the global `wp` object exists.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
     9
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    10
 * @namespace wp
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    11
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
window.wp = window.wp || {};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
(function(){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
	wp.shortcode = {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    16
		/*
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    17
		 * ### Find the next matching shortcode.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    18
		 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    19
		 * Given a shortcode `tag`, a block of `text`, and an optional starting
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    20
		 * `index`, returns the next matching shortcode or `undefined`.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    21
		 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    22
		 * Shortcodes are formatted as an object that contains the match
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    23
		 * `content`, the matching `index`, and the parsed `shortcode` object.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    24
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
		next: function( tag, text, index ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
			var re = wp.shortcode.regexp( tag ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
				match, result;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
			re.lastIndex = index || 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
			match = re.exec( text );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    32
			if ( ! match ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
				return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    34
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
			// If we matched an escaped shortcode, try again.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    37
			if ( '[' === match[1] && ']' === match[7] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
				return wp.shortcode.next( tag, text, re.lastIndex );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    39
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
			result = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
				index:     match.index,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
				content:   match[0],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
				shortcode: wp.shortcode.fromMatch( match )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
			};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
			// If we matched a leading `[`, strip it from the match
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
			// and increment the index accordingly.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
			if ( match[1] ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    50
				result.content = result.content.slice( 1 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
				result.index++;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
			// If we matched a trailing `]`, strip it from the match.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    55
			if ( match[7] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    56
				result.content = result.content.slice( 0, -1 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    57
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
			return result;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    62
		/*
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    63
		 * ### Replace matching shortcodes in a block of text.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    64
		 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    65
		 * Accepts a shortcode `tag`, content `text` to scan, and a `callback`
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    66
		 * to process the shortcode matches and return a replacement string.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    67
		 * Returns the `text` with all shortcodes replaced.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    68
		 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    69
		 * Shortcode matches are objects that contain the shortcode `tag`,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    70
		 * a shortcode `attrs` object, the `content` between shortcode tags,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    71
		 * and a boolean flag to indicate if the match was a `single` tag.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    72
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
		replace: function( tag, text, callback ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    74
			return text.replace( wp.shortcode.regexp( tag ), function( match, left, tag, attrs, slash, content, closing, right ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
				// If both extra brackets exist, the shortcode has been
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
				// properly escaped.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    77
				if ( left === '[' && right === ']' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
					return match;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    79
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
				// Create the match object and pass it through the callback.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
				var result = callback( wp.shortcode.fromMatch( arguments ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
				// Make sure to return any of the extra brackets if they
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
				// weren't used to escape the shortcode.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
				return result ? left + result + right : match;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    90
		/*
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    91
		 * ### Generate a string from shortcode parameters.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    92
		 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    93
		 * Creates a `wp.shortcode` instance and returns a string.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    94
		 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    95
		 * Accepts the same `options` as the `wp.shortcode()` constructor,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    96
		 * containing a `tag` string, a string or object of `attrs`, a boolean
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    97
		 * indicating whether to format the shortcode using a `single` tag, and a
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    98
		 * `content` string.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    99
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
		string: function( options ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
			return new wp.shortcode( options ).string();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   104
		/*
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   105
		 * ### Generate a RegExp to identify a shortcode.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   106
		 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   107
		 * The base regex is functionally equivalent to the one found in
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   108
		 * `get_shortcode_regex()` in `wp-includes/shortcodes.php`.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   109
		 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   110
		 * Capture groups:
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   111
		 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   112
		 * 1. An extra `[` to allow for escaping shortcodes with double `[[]]`.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   113
		 * 2. The shortcode name.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   114
		 * 3. The shortcode argument list.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   115
		 * 4. The self closing `/`.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   116
		 * 5. The content of a shortcode when it wraps some content.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   117
		 * 6. The closing tag.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   118
		 * 7. An extra `]` to allow for escaping shortcodes with double `[[]]`.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   119
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
		regexp: _.memoize( function( tag ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
			return new RegExp( '\\[(\\[?)(' + tag + ')(?![\\w-])([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*(?:\\[(?!\\/\\2\\])[^\\[]*)*)(\\[\\/\\2\\]))?)(\\]?)', 'g' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
		}),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   125
		/*
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   126
		 * ### Parse shortcode attributes.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   127
		 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   128
		 * Shortcodes accept many types of attributes. These can chiefly be
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   129
		 * divided into named and numeric attributes:
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   130
		 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   131
		 * Named attributes are assigned on a key/value basis, while numeric
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   132
		 * attributes are treated as an array.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   133
		 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   134
		 * Named attributes can be formatted as either `name="value"`,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   135
		 * `name='value'`, or `name=value`. Numeric attributes can be formatted
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   136
		 * as `"value"` or just `value`.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   137
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
		attrs: _.memoize( function( text ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
			var named   = {},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
				numeric = [],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
				pattern, match;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   143
			/*
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   144
			 * This regular expression is reused from `shortcode_parse_atts()`
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   145
			 * in `wp-includes/shortcodes.php`.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   146
			 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   147
			 * Capture groups:
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   148
			 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   149
			 * 1. An attribute name, that corresponds to...
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   150
			 * 2. a value in double quotes.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   151
			 * 3. An attribute name, that corresponds to...
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   152
			 * 4. a value in single quotes.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   153
			 * 5. An attribute name, that corresponds to...
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   154
			 * 6. an unquoted value.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   155
			 * 7. A numeric attribute in double quotes.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   156
			 * 8. A numeric attribute in single quotes.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   157
			 * 9. An unquoted numeric attribute.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   158
			 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   159
			pattern = /([\w-]+)\s*=\s*"([^"]*)"(?:\s|$)|([\w-]+)\s*=\s*'([^']*)'(?:\s|$)|([\w-]+)\s*=\s*([^\s'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|'([^']*)'(?:\s|$)|(\S+)(?:\s|$)/g;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
			// Map zero-width spaces to actual spaces.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
			text = text.replace( /[\u00a0\u200b]/g, ' ' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
			// Match and normalize attributes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
			while ( (match = pattern.exec( text )) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
				if ( match[1] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
					named[ match[1].toLowerCase() ] = match[2];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
				} else if ( match[3] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
					named[ match[3].toLowerCase() ] = match[4];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
				} else if ( match[5] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
					named[ match[5].toLowerCase() ] = match[6];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
				} else if ( match[7] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
					numeric.push( match[7] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
				} else if ( match[8] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
					numeric.push( match[8] );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   176
				} else if ( match[9] ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   177
					numeric.push( match[9] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
			return {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
				named:   named,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
				numeric: numeric
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
			};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
		}),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   187
		/*
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   188
		 * ### Generate a Shortcode Object from a RegExp match.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   189
		 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   190
		 * Accepts a `match` object from calling `regexp.exec()` on a `RegExp`
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   191
		 * generated by `wp.shortcode.regexp()`. `match` can also be set
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   192
		 * to the `arguments` from a callback passed to `regexp.replace()`.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   193
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
		fromMatch: function( match ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
			var type;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   197
			if ( match[4] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
				type = 'self-closing';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   199
			} else if ( match[6] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
				type = 'closed';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   201
			} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
				type = 'single';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   203
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
			return new wp.shortcode({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
				tag:     match[2],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
				attrs:   match[3],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
				type:    type,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
				content: match[5]
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
	};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   215
	/*
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   216
	 * Shortcode Objects
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   217
	 * -----------------
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   218
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   219
	 * Shortcode objects are generated automatically when using the main
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   220
	 * `wp.shortcode` methods: `next()`, `replace()`, and `string()`.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   221
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   222
	 * To access a raw representation of a shortcode, pass an `options` object,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   223
	 * containing a `tag` string, a string or object of `attrs`, a string
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   224
	 * indicating the `type` of the shortcode ('single', 'self-closing',
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   225
	 * or 'closed'), and a `content` string.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   226
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
	wp.shortcode = _.extend( function( options ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
		_.extend( this, _.pick( options || {}, 'tag', 'attrs', 'type', 'content' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
		var attrs = this.attrs;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
		// Ensure we have a correctly formatted `attrs` object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
		this.attrs = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
			named:   {},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
			numeric: []
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
		};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   238
		if ( ! attrs ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
			return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   240
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
		// Parse a string of attributes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
		if ( _.isString( attrs ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
			this.attrs = wp.shortcode.attrs( attrs );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
		// Identify a correctly formatted `attrs` object.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   247
		} else if ( _.difference( _.keys( attrs ), [ 'named', 'numeric' ] ).length === 0 ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   248
			this.attrs = _.defaults( attrs, this.attrs );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
		// Handle a flat object of attributes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
			_.each( options.attrs, function( value, key ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
				this.set( key, value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
			}, this );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
	}, wp.shortcode );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
	_.extend( wp.shortcode.prototype, {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   259
		/*
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   260
		 * ### Get a shortcode attribute.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   261
		 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   262
		 * Automatically detects whether `attr` is named or numeric and routes
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   263
		 * it accordingly.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   264
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
		get: function( attr ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
			return this.attrs[ _.isNumber( attr ) ? 'numeric' : 'named' ][ attr ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   269
		/*
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   270
		 * ### Set a shortcode attribute.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   271
		 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   272
		 * Automatically detects whether `attr` is named or numeric and routes
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   273
		 * it accordingly.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   274
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
		set: function( attr, value ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
			this.attrs[ _.isNumber( attr ) ? 'numeric' : 'named' ][ attr ] = value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
			return this;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   280
		// ### Transform the shortcode match into a string.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
		string: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
			var text    = '[' + this.tag;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
			_.each( this.attrs.numeric, function( value ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   285
				if ( /\s/.test( value ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
					text += ' "' + value + '"';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   287
				} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
					text += ' ' + value;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   289
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
			_.each( this.attrs.named, function( value, name ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
				text += ' ' + name + '="' + value + '"';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
			// If the tag is marked as `single` or `self-closing`, close the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
			// tag and ignore any additional content.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   298
			if ( 'single' === this.type ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
				return text + ']';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   300
			} else if ( 'self-closing' === this.type ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
				return text + ' /]';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   302
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
			// Complete the opening tag.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
			text += ']';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   307
			if ( this.content ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
				text += this.content;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   309
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
			// Add the closing tag.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
			return text + '[/' + this.tag + ']';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
}());
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   317
/*
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   318
 * HTML utility functions
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   319
 * ----------------------
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   320
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   321
 * Experimental. These functions may change or be removed in the future.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   322
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
(function(){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
	wp.html = _.extend( wp.html || {}, {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   325
		/*
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   326
		 * ### Parse HTML attributes.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   327
		 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   328
		 * Converts `content` to a set of parsed HTML attributes.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   329
		 * Utilizes `wp.shortcode.attrs( content )`, which is a valid superset of
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   330
		 * the HTML attribute specification. Reformats the attributes into an
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   331
		 * object that contains the `attrs` with `key:value` mapping, and a record
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   332
		 * of the attributes that were entered using `empty` attribute syntax (i.e.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   333
		 * with no value).
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   334
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
		attrs: function( content ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
			var result, attrs;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
			// If `content` ends in a slash, strip it.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   339
			if ( '/' === content[ content.length - 1 ] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
				content = content.slice( 0, -1 );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   341
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
			result = wp.shortcode.attrs( content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
			attrs  = result.named;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
			_.each( result.numeric, function( key ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   347
				if ( /\s/.test( key ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
					return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   349
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
				attrs[ key ] = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
			return attrs;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
		// ### Convert an HTML-representation of an object to a string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
		string: function( options ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
			var text = '<' + options.tag,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
				content = options.content || '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
			_.each( options.attrs, function( value, attr ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
				text += ' ' + attr;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
				// Convert boolean values to strings.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   366
				if ( _.isBoolean( value ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
					value = value ? 'true' : 'false';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   368
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
				text += '="' + value + '"';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
			// Return the result if it is a self-closing tag.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   374
			if ( options.single ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
				return text + ' />';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   376
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
			// Complete the opening tag.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
			text += '>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
			// If `content` is an object, recursively call this function.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
			text += _.isObject( content ) ? wp.html.string( content ) : content;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
			return text + '</' + options.tag + '>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
	});
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   387
}());