Make WordPress Core

Changeset 26882


Ignore:
Timestamp:
12/31/2013 03:09:34 AM (11 years ago)
Author:
azaozz
Message:

TinyMCE:

  • Fix removing leftovers from broken captions.
  • Better filter for line breaks and <br> tags when editing captions.

See #24067.

File:
1 edited

Legend:

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

    r26880 r26882  
    5050    function getShortcode( content ) {
    5151        return content.replace( /<div (?:id="attachment_|class="mceTemp)[^>]*>([\s\S]+?)<\/div>/g, function( a, b ) {
     52            var out = '';
     53
    5254            if ( b.indexOf('<img ') === -1 ) {
    53                 // Broken caption. The user dragged the image out?
     55                // Broken caption. The user managed to drag the image out?
     56                // Try to return the caption text as a paragraph.
     57                out = b.match( /<dd [^>]+>([\s\S]+?)<\/dd>/i );
     58
     59                if ( out && out[1] ) {
     60                    return '<p>' + out[1] + '</p>'
     61                }
     62
    5463                return '';
    5564            }
    5665
    57             var ret = b.replace( /<dl ([^>]+)>\s*<dt [^>]+>([\s\S]+?)<\/dt>\s*<dd [^>]+>([\s\S]*?)<\/dd>\s*<\/dl>/gi, function( a, b, c, cap ) {
     66            out = b.replace( /<dl ([^>]+)>\s*<dt [^>]+>([\s\S]+?)<\/dt>\s*<dd [^>]+>([\s\S]*?)<\/dd>\s*<\/dl>/gi, function( a, b, c, cap ) {
    5867                var id, cls, w;
    5968
     
    8392            });
    8493
    85             if ( ret.indexOf('[caption') !== 0 ) {
     94            if ( out.indexOf('[caption') !== 0 ) {
    8695                // the caption html seems brocken, try to find the image that may be wrapped in a link
    8796                // and may be followed by <p> with the caption text.
    88                 ret = b.replace( /[\s\S]*?((?:<a [^>]+>)?<img [^>]+>(?:<\/a>)?)(<p>[\s\S]*<\/p>)?[\s\S]*/gi, '<p>$1</p>$2' );
    89             }
    90 
    91             return ret;
     97                out = b.replace( /[\s\S]*?((?:<a [^>]+>)?<img [^>]+>(?:<\/a>)?)(<p>[\s\S]*<\/p>)?[\s\S]*/gi, '<p>$1</p>$2' );
     98            }
     99
     100            return out;
    92101        });
    93102    }
     
    162171            }
    163172
     173            if ( caption ) {
     174                caption = caption.replace( /\r\n|\r/g, '\n' ).replace( /<\/?[a-zA-Z0-9]+( [^<>]+)?>/g, function( a ) {
     175                    // No line breaks inside HTML tags
     176                    return a.replace( /[\r\n\t]+/, ' ' );
     177                });
     178
     179                // Convert remaining line breaks to <br>
     180                caption = caption.replace( /(<br[^>]*>)\s*\n\s*/g, '$1' ).replace( /\s*\n\s*/g, '<br />' );
     181            }
     182
    164183            if ( ! imgNode ) {
    165184                // New image inserted
     
    295314            if ( parent = dom.getParent( imgNode, 'dl.wp-caption' ) ) {
    296315                parent = dom.select( 'dd.wp-caption-dd', parent )[0];
    297                 data.caption = parent ? parent.innerHTML : '';
     316
     317                if ( parent ) {
     318                    data.caption = editor.serializer.serialize( parent )
     319                        .replace( /<br[^>]*>/g, '$&\n' ).replace( /^<p>/, '' ).replace( /<\/p>$/, '' );
     320                }
    298321            }
    299322        });
Note: See TracChangeset for help on using the changeset viewer.