Make WordPress Core

Changeset 30435


Ignore:
Timestamp:
11/20/2014 01:48:20 PM (12 years ago)
Author:
nacin
Message:

TinyMCE: Verify HTML in captions. props azaozz

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/tinymce/plugins/wpeditimage/plugin.js

    r30385 r30435  
    11/* global tinymce */
    22tinymce.PluginManager.add( 'wpeditimage', function( editor ) {
    3         var DOM = tinymce.DOM,
     3        var tb, serializer,
     4                DOM = tinymce.DOM,
    45                settings = editor.settings,
    56                Factory = tinymce.ui.Factory,
     
    78                iOS = tinymce.Env.iOS,
    89                toolbarIsHidden = true,
    9                 editorWrapParent = tinymce.$( '#postdivrich' ),
    10                 tb;
     10                editorWrapParent = tinymce.$( '#postdivrich' );
    1111
    1212        function isPlaceholder( node ) {
     
    560560        }
    561561
     562        // Verify HTML in captions
     563        function verifyHTML( caption ) {
     564                if ( ! caption || ( caption.indexOf( '<' ) === -1 && caption.indexOf( '>' ) === -1 ) ) {
     565                        return caption;
     566                }
     567
     568                if ( ! serializer ) {
     569                        serializer = new tinymce.html.Serializer( {}, editor.schema );
     570                }
     571
     572                return serializer.serialize( editor.parser.parse( caption, { forced_root_block: false } ) );
     573        }
     574
    562575        function updateImage( imageNode, imageData ) {
    563576                var classes, className, node, html, parent, wrap, linkNode,
     
    637650
    638651                if ( imageData.caption ) {
     652                        imageData.caption = verifyHTML( imageData.caption );
    639653
    640654                        id = imageData.attachment_id ? 'attachment_' + imageData.attachment_id : null;
     
    859873                                // Convert remaining line breaks to <br>
    860874                                caption = caption.replace( /(<br[^>]*>)\s*\n\s*/g, '$1' ).replace( /\s*\n\s*/g, '<br />' );
     875                                caption = verifyHTML( caption );
    861876                        }
    862877
Note: See TracChangeset for help on using the changeset viewer.