TinyMCE: Verify HTML in captions. props azaozz

Merges [30435] to the 3.9 branch.

Built from https://develop.svn.wordpress.org/branches/3.9@30437


git-svn-id: http://core.svn.wordpress.org/branches/3.9@30432 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Nacin 2014-11-20 13:52:15 +00:00
parent e8ea407eb6
commit bb7e7f5a0b
3 changed files with 18 additions and 2 deletions

View File

@ -1,6 +1,7 @@
/* global tinymce */
tinymce.PluginManager.add( 'wpeditimage', function( editor ) {
var toolbarActive = false;
var serializer,
toolbarActive = false;
function parseShortcode( content ) {
return content.replace( /(?:<p>)?\[(?:wp_)?caption([^\]]+)\]([\s\S]+?)\[\/(?:wp_)?caption\](?:<\/p>)?/g, function( a, b, c ) {
@ -208,6 +209,19 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) {
return node && !! ( node.textContent || node.innerText );
}
// Verify HTML in captions
function verifyHTML( caption ) {
if ( ! caption || ( caption.indexOf( '<' ) === -1 && caption.indexOf( '>' ) === -1 ) ) {
return caption;
}
if ( ! serializer ) {
serializer = new tinymce.html.Serializer( {}, editor.schema );
}
return serializer.serialize( editor.parser.parse( caption, { forced_root_block: false } ) );
}
function updateImage( imageNode, imageData ) {
var classes, className, node, html, parent, wrap, linkNode,
captionNode, dd, dl, id, attrs, linkAttrs, width, height,
@ -285,6 +299,7 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) {
}
if ( imageData.caption ) {
imageData.caption = verifyHTML( imageData.caption );
id = imageData.attachment_id ? 'attachment_' + imageData.attachment_id : null;
className = 'wp-caption align' + ( imageData.align || 'none' );
@ -563,6 +578,7 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) {
// Convert remaining line breaks to <br>
caption = caption.replace( /(<br[^>]*>)\s*\n\s*/g, '$1' ).replace( /\s*\n\s*/g, '<br />' );
caption = verifyHTML( caption );
}
if ( ! imgNode ) {

File diff suppressed because one or more lines are too long