Make WordPress Core

Changeset 30437


Ignore:
Timestamp:
11/20/2014 01:51:34 PM (10 years ago)
Author:
nacin
Message:

TinyMCE: Verify HTML in captions. props azaozz

Merges [30435] to the 3.9 branch.

Location:
branches/3.9
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/3.9

  • branches/3.9/src/wp-includes/js/tinymce/plugins/wpeditimage/plugin.js

    r28231 r30437  
    11/* global tinymce */
    22tinymce.PluginManager.add( 'wpeditimage', function( editor ) {
    3     var toolbarActive = false;
     3    var serializer,
     4        toolbarActive = false;
    45
    56    function parseShortcode( content ) {
     
    209210    }
    210211
     212    // Verify HTML in captions
     213    function verifyHTML( caption ) {
     214        if ( ! caption || ( caption.indexOf( '<' ) === -1 && caption.indexOf( '>' ) === -1 ) ) {
     215            return caption;
     216        }
     217
     218        if ( ! serializer ) {
     219            serializer = new tinymce.html.Serializer( {}, editor.schema );
     220        }
     221
     222        return serializer.serialize( editor.parser.parse( caption, { forced_root_block: false } ) );
     223    }
     224
    211225    function updateImage( imageNode, imageData ) {
    212226        var classes, className, node, html, parent, wrap, linkNode,
     
    286300
    287301        if ( imageData.caption ) {
     302            imageData.caption = verifyHTML( imageData.caption );
    288303
    289304            id = imageData.attachment_id ? 'attachment_' + imageData.attachment_id : null;
     
    564579                // Convert remaining line breaks to <br>
    565580                caption = caption.replace( /(<br[^>]*>)\s*\n\s*/g, '$1' ).replace( /\s*\n\s*/g, '<br />' );
     581                caption = verifyHTML( caption );
    566582            }
    567583
Note: See TracChangeset for help on using the changeset viewer.