CKEditor, before allowing the browser to break the data, copies all the attributes src, nameand hrefinto the attributes data-cke-saved-src|href. Unfortunately, since the data is a string, this needs to be done with a regular expression. The code can be found here: /core/htmldataprocessor.js#L772-L783 .
var protectElementRegex = /<(a|area|img|input|source)\b([^>]*)>/gi,
protectAttributeRegex = /([\w-]+)\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|(?:[^ "'>]+))/gi,
protectAttributeNameRegex = /^(href|src|name)$/i;
function protectAttributes( html ) {
return html.replace( protectElementRegex, function( element, tag, attributes ) {
return '<' + tag + attributes.replace( protectAttributeRegex, function( fullAttr, attrName ) {
if ( protectAttributeNameRegex.test( attrName ) && attributes.indexOf( 'data-cke-saved-' + attrName ) == -1 )
return ' data-cke-saved-' + fullAttr + ' data-cke-' + CKEDITOR.rnd + '-' + fullAttr;
return fullAttr;
} ) + '>';
} );
}
Then, processing the HTML taken from the editable element, the attributes data-cke-saved-*override the original ones.