4 * Duck-punched by WordPress core to support a sane schema superset.
6 * Copyright, Moxiecode Systems AB
7 * Released under LGPL License.
9 * License: http://www.tinymce.com/license
10 * Contributing: http://www.tinymce.com/contributing
14 var mapCache = {}, makeMap = tinymce.makeMap, each = tinymce.each;
16 function split(str, delim) {
17 return str.split(delim || ',');
21 * Unpacks the specified lookup and string data it will also parse it into an object
22 * map with sub object for it's children. This will later also include the attributes.
24 function unpack(lookup, data) {
25 var key, elements = {};
27 function replace(value) {
28 return value.replace(/[A-Z]+/g, function(key) {
29 return replace(lookup[key]);
35 if (lookup.hasOwnProperty(key))
36 lookup[key] = replace(lookup[key]);
39 // Unpack and parse data into object map
40 replace(data).replace(/#/g, '#text').replace(/(\w+)\[([^\]]+)\]\[([^\]]*)\]/g, function(str, name, attributes, children) {
41 attributes = split(attributes, '|');
44 attributes : makeMap(attributes),
45 attributesOrder : attributes,
46 children : makeMap(children, '|', {'#comment' : {}})
54 * Returns the HTML5 schema and caches it in the mapCache.
57 var html5 = mapCache.html5;
60 html5 = mapCache.html5 = unpack({
61 A : 'accesskey|class|contextmenu|dir|draggable|dropzone|hidden|id|inert|itemid|itemprop|itemref|itemscope|itemtype|lang|spellcheck|style|tabindex|title|translate|item|role|subject|onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup',
62 B : '#|a|abbr|area|audio|b|bdi|bdo|br|button|canvas|cite|code|command|data|datalist|del|dfn|em|embed|i|iframe|img|input|ins|kbd|keygen|label|link|map|mark|math|meta|meter|noscript|object|output|progress|q|ruby|s|samp|script|select|small|span|strong|sub|sup|svg|textarea|time|u|var|video|wbr',
63 C : '#|a|abbr|area|address|article|aside|audio|b|bdi|bdo|blockquote|br|button|canvas|cite|code|command|data|datalist|del|details|dfn|dialog|div|dl|em|embed|fieldset|figure|footer|form|h1|h2|h3|h4|h5|h6|header|hgroup|hr|i|iframe|img|input|ins|kbd|keygen|label|link|map|mark|math|menu|meta|meter|nav|noscript|ol|object|output|p|pre|progress|q|ruby|s|samp|script|section|select|small|span|strong|style|sub|sup|svg|table|textarea|time|u|ul|var|video|wbr'
64 }, 'html[A|manifest][body|head]' +
65 'head[A][base|command|link|meta|noscript|script|style|title]' +
67 'base[A|href|target][]' +
68 'link[A|href|rel|media|type|sizes|crossorigin|hreflang][]' +
69 'meta[A|http-equiv|name|content|charset][]' +
70 'style[A|type|media|scoped][#]' +
71 'script[A|charset|type|src|defer|async|crossorigin][#]' +
73 'body[A|onafterprint|onbeforeprint|onbeforeunload|onblur|onerror|onfocus|onfullscreenchange|onfullscreenerror|onhashchange|onload|onmessage|onoffline|ononline|onpagehide|onpageshow|onpopstate|onresize|onscroll|onstorage|onunload][C]' +
84 'hgroup[A][h1|h2|h3|h4|h5|h6]' +
91 'dialog[A|open][C|dd|dt]' +
92 'blockquote[A|cite][C]' +
93 'ol[A|start|reversed][li]' +
99 'a[A|href|target|download|ping|rel|media|type][C|B]' +
118 'progress[A|value|max][B]' +
119 'meter[A|value|min|max|low|high|optimum][B]' +
120 'time[A|datetime][B]' +
127 'ins[A|cite|datetime][C|B]' +
128 'del[A|cite|datetime][C|B]' +
129 'figure[A][C|legend|figcaption]' +
131 'img[A|alt|src|srcset|crossorigin|usemap|ismap|width|height][]' +
132 'iframe[A|name|src|srcdoc|height|width|sandbox|seamless|allowfullscreen][C|B]' +
133 'embed[A|src|height|width|type][]' +
134 'object[A|data|type|typemustmatch|name|usemap|form|width|height][C|B|param]' +
135 'param[A|name|value][]' +
137 'details[A|open][C|legend|summary]' +
138 'command[A|type|label|icon|disabled|checked|radiogroup|command][]' +
139 'menu[A|type|label][C|li]' +
142 'source[A|src|type|media][]' +
143 'track[A|kind|src|srclang|label|default][]' +
144 'audio[A|src|autobuffer|autoplay|loop|controls|crossorigin|preload|mediagroup|muted][C|source|track]' +
145 'video[A|src|autobuffer|autoplay|loop|controls|width|height|poster|crossorigin|preload|mediagroup|muted][C|source|track]' +
147 'form[A|accept-charset|action|autocomplete|enctype|method|name|novalidate|target][C]' +
148 'fieldset[A|disabled|form|name][C|legend]' +
149 'label[A|form|for][B]' +
150 'input[A|type|accept|alt|autocomplete|autofocus|checked|dirname|disabled|form|formaction|formenctype|formmethod|formnovalidate|formtarget|height|inputmode|list|max|maxlength|min|multiple|name|pattern|placeholder|readonly|required|size|src|step|value|width|files][]' +
151 'button[A|autofocus|disabled|form|formaction|formenctype|formmethod|formnovalidate|formtarget|name|type|value][B]' +
152 'select[A|autofocus|disabled|form|multiple|name|required|size][option|optgroup]' +
154 'datalist[A][B|option]' +
155 'optgroup[A|disabled|label][option]' +
156 'option[A|disabled|selected|label|value][#]' +
157 'textarea[A|autocomplete|autofocus|cols|dirname|disabled|form|inputmode|maxlength|name|placeholder|readonly|required|rows|wrap][#]' +
158 'keygen[A|autofocus|challenge|disabled|form|keytype|name][]' +
159 'output[A|for|form|name][B]' +
160 'canvas[A|width|height][a|button|input]' +
162 'area[A|alt|coords|shape|href|target|download|ping|rel|media|hreflang|type][]' +
165 'table[A][caption|colgroup|thead|tfoot|tbody|tr]' +
167 'colgroup[A|span][col]' +
173 'th[A|headers|rowspan|colspan|scope][C]' +
174 'td[A|headers|rowspan|colspan][C]' +
183 * Returns the HTML4 schema and caches it in the mapCache.
185 function getHTML4() {
186 var html4 = mapCache.html4;
189 // This is the XHTML 1.0 transitional elements with it's attributes and children packed to reduce it's size
190 html4 = mapCache.html4 = unpack({
193 ZG : 'E|span|width|align|char|charoff|valign',
194 X : 'p|T|div|U|W|isindex|fieldset|table',
195 ZF : 'E|align|char|charoff|valign',
196 W : 'pre|hr|blockquote|address|center|noframes',
197 ZE : 'abbr|axis|headers|scope|rowspan|colspan|align|char|charoff|valign|nowrap|bgcolor|width|height',
199 U : 'ul|ol|dl|menu|dir',
200 ZC : 'p|Y|div|U|W|table|br|span|bdo|object|applet|img|map|K|N|Q',
201 T : 'h1|h2|h3|h4|h5|h6',
207 P : 'ins|del|script',
208 O : 'input|select|textarea|label|button',
210 M : 'em|strong|dfn|code|q|samp|kbd|var|cite|abbr|acronym',
213 J : 'tt|i|b|u|s|strike',
214 I : 'big|small|font|basefont',
217 F : 'object|applet|img|map|iframe',
219 D : 'accesskey|tabindex|onfocus|onblur',
220 C : 'onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup',
221 B : 'lang|xml:lang|dir',
222 A : 'id|class|style|title'
223 }, 'script[id|charset|type|language|src|defer|xml:space][]' +
224 'style[B|id|type|media|title|xml:space][]' +
225 'object[E|declare|classid|codebase|data|type|codetype|archive|standby|width|height|usemap|name|tabindex|align|border|hspace|vspace][#|param|Y]' +
226 'param[id|name|value|valuetype|type][]' +
228 'a[E|D|charset|type|name|href|hreflang|rel|rev|shape|coords|target][#|Z]' +
232 'applet[A|codebase|archive|code|object|alt|name|width|height|align|hspace|vspace][#|param|Y]' +
234 'img[E|src|alt|name|longdesc|width|height|usemap|ismap|align|border|hspace|vspace][]' +
235 'map[B|C|A|name][X|form|Q|area]' +
237 'iframe[A|longdesc|name|src|frameborder|marginwidth|marginheight|scrolling|align|width|height][#|Y]' +
247 'font[A|B|size|color|face][#|S]' +
248 'basefont[id|size|color|face][]' +
262 'input[E|D|type|name|value|checked|disabled|readonly|size|maxlength|src|alt|usemap|onselect|onchange|accept|align][]' +
263 'select[E|name|size|multiple|disabled|tabindex|onfocus|onblur|onchange][optgroup|option]' +
264 'optgroup[E|disabled|label][option]' +
265 'option[E|selected|disabled|label|value][]' +
266 'textarea[E|D|name|rows|cols|disabled|readonly|onselect|onchange][]' +
267 'label[E|for|accesskey|onfocus|onblur][#|S]' +
268 'button[E|D|name|value|type|disabled][#|p|T|div|U|W|table|G|object|applet|img|map|K|N|Q]' +
270 'ins[E|cite|datetime][#|Y]' +
272 'del[E|cite|datetime][#|Y]' +
274 'div[E|align][#|Y]' +
275 'ul[E|type|compact][li]' +
276 'li[E|type|value][#|Y]' +
277 'ol[E|type|compact|start][li]' +
278 'dl[E|compact][dt|dd]' +
281 'menu[E|compact][li]' +
282 'dir[E|compact][li]' +
283 'pre[E|width|xml:space][#|ZA]' +
284 'hr[E|align|noshade|size|width][]' +
285 'blockquote[E|cite][#|Y]' +
286 'address[E][#|S|p]' +
289 'isindex[A|B|prompt][]' +
290 'fieldset[E][#|legend|Y]' +
291 'legend[E|accesskey|align][#|S]' +
292 'table[E|summary|width|border|frame|rules|cellspacing|cellpadding|align|bgcolor][caption|col|colgroup|thead|tfoot|tbody|tr]' +
293 'caption[E|align][#|S]' +
295 'colgroup[ZG][col]' +
297 'tr[ZF|bgcolor][th|td]' +
299 'form[E|action|method|name|enctype|onsubmit|onreset|accept|accept-charset|target][#|X|R|Q]' +
304 'area[E|D|shape|coords|href|nohref|alt|target][]' +
305 'base[id|href|target][]' +
306 'body[E|onload|onunload|background|bgcolor|text|link|vlink|alink][#|Y]'
316 * Returns a schema that is the result of a deep merge between the HTML5
319 function getSaneSchema() {
320 var cachedMapCache = mapCache,
324 return mapCache.sane;
326 // Bust the mapCache so we're not dealing with the other schema objects.
330 mapCache = cachedMapCache;
332 each( html4, function( html4settings, tag ) {
333 var html5settings = html5[ tag ],
336 // Merge tags missing in HTML5 mode.
337 if ( ! html5settings ) {
338 html5[ tag ] = html4settings;
342 // Merge attributes missing from this HTML5 tag.
343 each( html4settings.attributes, function( attribute, key ) {
344 if ( ! html5settings.attributes[ key ] )
345 html5settings.attributes[ key ] = attribute;
348 // Merge any missing attributes into the attributes order.
349 each( html4settings.attributesOrder, function( key ) {
350 if ( -1 === tinymce.inArray( html5settings.attributesOrder, key ) )
351 difference.push( key );
354 html5settings.attributesOrder = html5settings.attributesOrder.concat( difference );
356 // Merge children missing from this HTML5 tag.
357 each( html4settings.children, function( child, key ) {
358 if ( ! html5settings.children[ key ] )
359 html5settings.children[ key ] = child;
363 return mapCache.sane = html5;
367 * Schema validator class.
369 * @class tinymce.html.Schema
371 * if (tinymce.activeEditor.schema.isValidChild('p', 'span'))
372 * alert('span is valid child of p.');
374 * if (tinymce.activeEditor.schema.getElementRule('p'))
375 * alert('P is a valid element.');
377 * @class tinymce.html.Schema
382 * Constructs a new Schema instance.
386 * @param {Object} settings Name/value settings object.
388 tinymce.html.Schema = function(settings) {
389 var self = this, elements = {}, children = {}, patternElements = [], validStyles, schemaItems;
390 var whiteSpaceElementsMap, selfClosingElementsMap, shortEndedElementsMap, boolAttrMap, blockElementsMap, nonEmptyElementsMap, customElementsMap = {};
392 // Creates an lookup table map object for the specified option or the default value
393 function createLookupTable(option, default_value, extend) {
394 var value = settings[option];
397 // Get cached default map or make it if needed
398 value = mapCache[option];
401 value = makeMap(default_value, ' ', makeMap(default_value.toUpperCase(), ' '));
402 value = tinymce.extend(value, extend);
404 mapCache[option] = value;
408 value = makeMap(value, ',', makeMap(value.toUpperCase(), ' '));
414 settings = settings || {};
417 * WordPress core uses a sane schema in place of the default "HTML5" schema.
419 schemaItems = settings.schema == "html5" ? getSaneSchema() : getHTML4();
421 // Allow all elements and attributes if verify_html is set to false
422 if (settings.verify_html === false)
423 settings.valid_elements = '*[*]';
426 if (settings.valid_styles) {
429 // Convert styles into a rule list
430 each(settings.valid_styles, function(value, key) {
431 validStyles[key] = tinymce.explode(value);
436 whiteSpaceElementsMap = createLookupTable('whitespace_elements', 'pre script noscript style textarea');
437 selfClosingElementsMap = createLookupTable('self_closing_elements', 'colgroup dd dt li option p td tfoot th thead tr');
438 shortEndedElementsMap = createLookupTable('short_ended_elements', 'area base basefont br col frame hr img input isindex link meta param embed source wbr');
439 boolAttrMap = createLookupTable('boolean_attributes', 'checked compact declare defer disabled ismap multiple nohref noresize noshade nowrap readonly selected autoplay loop controls');
440 nonEmptyElementsMap = createLookupTable('non_empty_elements', 'td th iframe video audio object', shortEndedElementsMap);
441 textBlockElementsMap = createLookupTable('text_block_elements', 'h1 h2 h3 h4 h5 h6 p div address pre form ' +
442 'blockquote center dir fieldset header footer article section hgroup aside nav figure');
443 blockElementsMap = createLookupTable('block_elements', 'hr table tbody thead tfoot ' +
444 'th tr td li ol ul caption dl dt dd noscript menu isindex samp option datalist select optgroup', textBlockElementsMap);
446 // Converts a wildcard expression string to a regexp for example *a will become /.*a/.
447 function patternToRegExp(str) {
448 return new RegExp('^' + str.replace(/([?+*])/g, '.$1') + '$');
451 // Parses the specified valid_elements string and adds to the current rules
452 // This function is a bit hard to read since it's heavily optimized for speed
453 function addValidElements(valid_elements) {
454 var ei, el, ai, al, yl, matches, element, attr, attrData, elementName, attrName, attrType, attributes, attributesOrder,
455 prefix, outputName, globalAttributes, globalAttributesOrder, transElement, key, childKey, value,
456 elementRuleRegExp = /^([#+\-])?([^\[\/]+)(?:\/([^\[]+))?(?:\[([^\]]+)\])?$/,
457 attrRuleRegExp = /^([!\-])?(\w+::\w+|[^=:<]+)?(?:([=:<])(.*))?$/,
458 hasPatternsRegExp = /[*?+]/;
460 if (valid_elements) {
461 // Split valid elements into an array with rules
462 valid_elements = split(valid_elements);
465 globalAttributes = elements['@'].attributes;
466 globalAttributesOrder = elements['@'].attributesOrder;
470 for (ei = 0, el = valid_elements.length; ei < el; ei++) {
471 // Parse element rule
472 matches = elementRuleRegExp.exec(valid_elements[ei]);
474 // Setup local names for matches
476 elementName = matches[2];
477 outputName = matches[3];
478 attrData = matches[4];
480 // Create new attributes and attributesOrder
482 attributesOrder = [];
484 // Create the new element
486 attributes : attributes,
487 attributesOrder : attributesOrder
490 // Padd empty elements prefix
492 element.paddEmpty = true;
494 // Remove empty elements prefix
496 element.removeEmpty = true;
498 // Copy attributes from global rule into current rule
499 if (globalAttributes) {
500 for (key in globalAttributes)
501 attributes[key] = globalAttributes[key];
503 attributesOrder.push.apply(attributesOrder, globalAttributesOrder);
506 // Attributes defined
508 attrData = split(attrData, '|');
509 for (ai = 0, al = attrData.length; ai < al; ai++) {
510 matches = attrRuleRegExp.exec(attrData[ai]);
513 attrType = matches[1];
514 attrName = matches[2].replace(/::/g, ':');
519 if (attrType === '!') {
520 element.attributesRequired = element.attributesRequired || [];
521 element.attributesRequired.push(attrName);
522 attr.required = true;
525 // Denied from global
526 if (attrType === '-') {
527 delete attributes[attrName];
528 attributesOrder.splice(tinymce.inArray(attributesOrder, attrName), 1);
535 if (prefix === '=') {
536 element.attributesDefault = element.attributesDefault || [];
537 element.attributesDefault.push({name: attrName, value: value});
538 attr.defaultValue = value;
542 if (prefix === ':') {
543 element.attributesForced = element.attributesForced || [];
544 element.attributesForced.push({name: attrName, value: value});
545 attr.forcedValue = value;
550 attr.validValues = makeMap(value, '?');
553 // Check for attribute patterns
554 if (hasPatternsRegExp.test(attrName)) {
555 element.attributePatterns = element.attributePatterns || [];
556 attr.pattern = patternToRegExp(attrName);
557 element.attributePatterns.push(attr);
559 // Add attribute to order list if it doesn't already exist
560 if (!attributes[attrName])
561 attributesOrder.push(attrName);
563 attributes[attrName] = attr;
569 // Global rule, store away these for later usage
570 if (!globalAttributes && elementName == '@') {
571 globalAttributes = attributes;
572 globalAttributesOrder = attributesOrder;
575 // Handle substitute elements such as b/strong
577 element.outputName = elementName;
578 elements[outputName] = element;
581 // Add pattern or exact element
582 if (hasPatternsRegExp.test(elementName)) {
583 element.pattern = patternToRegExp(elementName);
584 patternElements.push(element);
586 elements[elementName] = element;
592 function setValidElements(valid_elements) {
594 patternElements = [];
596 addValidElements(valid_elements);
598 each(schemaItems, function(element, name) {
599 children[name] = element.children;
603 // Adds custom non HTML elements to the schema
604 function addCustomElements(custom_elements) {
605 var customElementRegExp = /^(~)?(.+)$/;
607 if (custom_elements) {
608 each(split(custom_elements), function(rule) {
609 var matches = customElementRegExp.exec(rule),
610 inline = matches[1] === '~',
611 cloneName = inline ? 'span' : 'div',
614 children[name] = children[cloneName];
615 customElementsMap[name] = cloneName;
617 // If it's not marked as inline then add it to valid block elements
619 blockElementsMap[name.toUpperCase()] = {};
620 blockElementsMap[name] = {};
623 // Add elements clone if needed
624 if (!elements[name]) {
625 elements[name] = elements[cloneName];
628 // Add custom elements at span/div positions
629 each(children, function(element, child) {
630 if (element[cloneName])
631 element[name] = element[cloneName];
637 // Adds valid children to the schema object
638 function addValidChildren(valid_children) {
639 var childRuleRegExp = /^([+\-]?)(\w+)\[([^\]]+)\]$/;
641 if (valid_children) {
642 each(split(valid_children), function(rule) {
643 var matches = childRuleRegExp.exec(rule), parent, prefix;
648 // Add/remove items from default
650 parent = children[matches[2]];
652 parent = children[matches[2]] = {'#comment' : {}};
654 parent = children[matches[2]];
656 each(split(matches[3], '|'), function(child) {
658 delete parent[child];
667 function getElementRule(name) {
668 var element = elements[name], i;
674 // No exact match then try the patterns
675 i = patternElements.length;
677 element = patternElements[i];
679 if (element.pattern.test(name))
684 if (!settings.valid_elements) {
685 // No valid elements defined then clone the elements from the schema spec
686 each(schemaItems, function(element, name) {
688 attributes : element.attributes,
689 attributesOrder : element.attributesOrder
692 children[name] = element.children;
695 // Switch these on HTML4
696 if (settings.schema != "html5") {
697 each(split('strong/b,em/i'), function(item) {
698 item = split(item, '/');
699 elements[item[1]].outputName = item[0];
703 // Add default alt attribute for images
704 elements.img.attributesDefault = [{name: 'alt', value: ''}];
706 // Remove these if they are empty by default
707 each(split('ol,ul,sub,sup,blockquote,span,font,a,table,tbody,tr,strong,em,b,i'), function(name) {
708 if (elements[name]) {
709 elements[name].removeEmpty = true;
713 // Padd these by default
714 each(split('p,h1,h2,h3,h4,h5,h6,th,td,pre,div,address,caption'), function(name) {
715 elements[name].paddEmpty = true;
718 setValidElements(settings.valid_elements);
720 addCustomElements(settings.custom_elements);
721 addValidChildren(settings.valid_children);
722 addValidElements(settings.extended_valid_elements);
724 // Todo: Remove this when we fix list handling to be valid
725 addValidChildren('+ol[ul|ol],+ul[ul|ol]');
727 // Delete invalid elements
728 if (settings.invalid_elements) {
729 tinymce.each(tinymce.explode(settings.invalid_elements), function(item) {
731 delete elements[item];
735 // If the user didn't allow span only allow internal spans
736 if (!getElementRule('span'))
737 addValidElements('span[!data-mce-type|*]');
740 * Name/value map object with valid parents and children to those parents.
749 self.children = children;
752 * Name/value map object with valid styles for each element.
757 self.styles = validStyles;
760 * Returns a map with boolean attributes.
762 * @method getBoolAttrs
763 * @return {Object} Name/value lookup map for boolean attributes.
765 self.getBoolAttrs = function() {
770 * Returns a map with block elements.
772 * @method getBlockElements
773 * @return {Object} Name/value lookup map for block elements.
775 self.getBlockElements = function() {
776 return blockElementsMap;
780 * Returns a map with text block elements. Such as: p,h1-h6,div,address
782 * @method getTextBlockElements
783 * @return {Object} Name/value lookup map for block elements.
785 self.getTextBlockElements = function() {
786 return textBlockElementsMap;
790 * Returns a map with short ended elements such as BR or IMG.
792 * @method getShortEndedElements
793 * @return {Object} Name/value lookup map for short ended elements.
795 self.getShortEndedElements = function() {
796 return shortEndedElementsMap;
800 * Returns a map with self closing tags such as <li>.
802 * @method getSelfClosingElements
803 * @return {Object} Name/value lookup map for self closing tags elements.
805 self.getSelfClosingElements = function() {
806 return selfClosingElementsMap;
810 * Returns a map with elements that should be treated as contents regardless if it has text
811 * content in them or not such as TD, VIDEO or IMG.
813 * @method getNonEmptyElements
814 * @return {Object} Name/value lookup map for non empty elements.
816 self.getNonEmptyElements = function() {
817 return nonEmptyElementsMap;
821 * Returns a map with elements where white space is to be preserved like PRE or SCRIPT.
823 * @method getWhiteSpaceElements
824 * @return {Object} Name/value lookup map for white space elements.
826 self.getWhiteSpaceElements = function() {
827 return whiteSpaceElementsMap;
831 * Returns true/false if the specified element and it's child is valid or not
832 * according to the schema.
834 * @method isValidChild
835 * @param {String} name Element name to check for.
836 * @param {String} child Element child to verify.
837 * @return {Boolean} True/false if the element is a valid child of the specified parent.
839 self.isValidChild = function(name, child) {
840 var parent = children[name];
842 return !!(parent && parent[child]);
846 * Returns true/false if the specified element name and optional attribute is
847 * valid according to the schema.
850 * @param {String} name Name of element to check.
851 * @param {String} attr Optional attribute name to check for.
852 * @return {Boolean} True/false if the element and attribute is valid.
854 self.isValid = function(name, attr) {
855 var attrPatterns, i, rule = getElementRule(name);
857 // Check if it's a valid element
860 // Check if attribute name exists
861 if (rule.attributes[attr]) {
865 // Check if attribute matches a regexp pattern
866 attrPatterns = rule.attributePatterns;
868 i = attrPatterns.length;
870 if (attrPatterns[i].pattern.test(name)) {
885 * Returns true/false if the specified element is valid or not
886 * according to the schema.
888 * @method getElementRule
889 * @param {String} name Element name to check for.
890 * @return {Object} Element object or undefined if the element isn't valid.
892 self.getElementRule = getElementRule;
895 * Returns an map object of all custom elements.
897 * @method getCustomElements
898 * @return {Object} Name/value map object of all custom elements.
900 self.getCustomElements = function() {
901 return customElementsMap;
905 * Parses a valid elements string and adds it to the schema. The valid elements format is for example "element[attr=default|otherattr]".
906 * Existing rules will be replaced with the ones specified, so this extends the schema.
908 * @method addValidElements
909 * @param {String} valid_elements String in the valid elements format to be parsed.
911 self.addValidElements = addValidElements;
914 * Parses a valid elements string and sets it to the schema. The valid elements format is for example "element[attr=default|otherattr]".
915 * Existing rules will be replaced with the ones specified, so this extends the schema.
917 * @method setValidElements
918 * @param {String} valid_elements String in the valid elements format to be parsed.
920 self.setValidElements = setValidElements;
923 * Adds custom non HTML elements to the schema.
925 * @method addCustomElements
926 * @param {String} custom_elements Comma separated list of custom elements to add.
928 self.addCustomElements = addCustomElements;
931 * Parses a valid children string and adds them to the schema structure. The valid children format is for example: "element[child1|child2]".
933 * @method addValidChildren
934 * @param {String} valid_children Valid children elements string to parse
936 self.addValidChildren = addValidChildren;
938 self.elements = elements;