TinyMCE: Verify HTML in captions. props azaozz

Built from https://develop.svn.wordpress.org/trunk@30435


git-svn-id: http://core.svn.wordpress.org/trunk@30430 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Nacin 2014-11-20 13:49:22 +00:00
parent fce07e17eb
commit 87023d64b4
4 changed files with 20 additions and 5 deletions

View File

@ -1,13 +1,13 @@
/* global tinymce */ /* global tinymce */
tinymce.PluginManager.add( 'wpeditimage', function( editor ) { tinymce.PluginManager.add( 'wpeditimage', function( editor ) {
var DOM = tinymce.DOM, var tb, serializer,
DOM = tinymce.DOM,
settings = editor.settings, settings = editor.settings,
Factory = tinymce.ui.Factory, Factory = tinymce.ui.Factory,
each = tinymce.each, each = tinymce.each,
iOS = tinymce.Env.iOS, iOS = tinymce.Env.iOS,
toolbarIsHidden = true, toolbarIsHidden = true,
editorWrapParent = tinymce.$( '#postdivrich' ), editorWrapParent = tinymce.$( '#postdivrich' );
tb;
function isPlaceholder( node ) { function isPlaceholder( node ) {
return !! ( editor.dom.getAttrib( node, 'data-mce-placeholder' ) || editor.dom.getAttrib( node, 'data-mce-object' ) ); return !! ( editor.dom.getAttrib( node, 'data-mce-placeholder' ) || editor.dom.getAttrib( node, 'data-mce-object' ) );
@ -559,6 +559,19 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) {
return node && !! ( node.textContent || node.innerText ); 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 ) { function updateImage( imageNode, imageData ) {
var classes, className, node, html, parent, wrap, linkNode, var classes, className, node, html, parent, wrap, linkNode,
captionNode, dd, dl, id, attrs, linkAttrs, width, height, align, captionNode, dd, dl, id, attrs, linkAttrs, width, height, align,
@ -636,6 +649,7 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) {
} }
if ( imageData.caption ) { if ( imageData.caption ) {
imageData.caption = verifyHTML( imageData.caption );
id = imageData.attachment_id ? 'attachment_' + imageData.attachment_id : null; id = imageData.attachment_id ? 'attachment_' + imageData.attachment_id : null;
align = 'align' + ( imageData.align || 'none' ); align = 'align' + ( imageData.align || 'none' );
@ -858,6 +872,7 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) {
// Convert remaining line breaks to <br> // Convert remaining line breaks to <br>
caption = caption.replace( /(<br[^>]*>)\s*\n\s*/g, '$1' ).replace( /\s*\n\s*/g, '<br />' ); caption = caption.replace( /(<br[^>]*>)\s*\n\s*/g, '$1' ).replace( /\s*\n\s*/g, '<br />' );
caption = verifyHTML( caption );
} }
if ( ! imgNode ) { if ( ! imgNode ) {

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.1-beta1-30430'; $wp_version = '4.1-beta1-30435';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.