Skip to content
maxxi165 edited this page May 20, 2017 · 5 revisions

parserRules

Object which includes parser rules to apply for html for code cleanup.

Basic structure of parser configuration object:

{
	attributes: {}, // Global attributes whitelist
    classes: {}, // Classes white-list
	classes_blacklist: {}, // black-list of classes. Available if classes is set to "any"
	type_definitions: {}, // Type definitions for "one_of_type" declarations in tags
	comments: true, // Allows html comments to be kept
	tags: {}, defines white-list of allowed tagNames with additional restrictions and options
}

attributes

Object defining list of attributes that are allowed on all elements. Every tag can extend/change this list with check_attributes property. Attribute key has a special character *, allowing matches for attributes beginning with user defined key (data-*). Currently It only works with * being the last character.

"attributes": {
    // All defined values pass ()
    "id": "any",
    
    // Custom function for passing attributes
    //   Ex: passes attributes that have only key but no value defined
    "itemscope": function(val) { 
        if (typeof val !== "undefined") {
            return (val === null) ? "" :  "" + val;
        } else {
            return false;
        }
    },
    
    // Passes all attributes beginnig with data-
    "data-*": "any",
    
    // Allows only valid urls for "href" attribute (starting with http:// or https://)
    "href": "url",
    
    // Allows something like "/foobar.jpg", "http://google.com" for "href" attribute
    "href":  "src",
    
    // Allows something like "mailto:bert@foo.com", "http://google.com", "/foobar.jpg", "#test", "tel:1234" for "href" attribute
    "href":  "href",
    
    // Strips unwanted characters. If the attribute is not set, then it gets set
    "alt": "alt",

    // Only contains numeric (integer) characters (no float values or units)
    "colspan": "numbers",

    // For with/height attributes where floating point numbres and percentages are allowed
    "width": "dimension"
}

classes

Object defining white-list of allowed classnames. Classnames are given as object keys and their values must be truthy (1 / true). All classes that are not in this list are removed.

"classes": {
    "wysiwyg-color-aqua": 1,
    "wysiwyg-color-black": 1,
    "wysiwyg-color-blue": 1
 }

To pass all classes as allowed or use classes_blacklist instead define classes as "any".

"classes": "any"

classes_blacklist

Object defining black-list of classes (classes the will be removed if found). Available if classes is set to "any". Example:

"classes_blacklist": {
    "Apple-interchange-newline": 1,
    "MsoNormal": 1,
    "MsoPlainText": 1
}

type_definitions

comments

If set to truthy value (1 / true) then all comment nodes are kept as is.

tags

Tag white-list of allowed tag names. Allowed tag names are given as object keys and their values just be objects:

tags: {
    strong: {},
    b:      {},
    i:      {}
 } 

pasteParserRulesets