WordPress.org

Make WordPress Core

Changeset 33834


Ignore:
Timestamp:
08/31/2015 10:06:11 PM (4 years ago)
Author:
azaozz
Message:

TinyMCE: fix replacing the image caption HTML with the shortcode when saving the content.
Fixes #33477.

File:
1 edited

Legend:

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

    r33728 r33834  
    160160
    161161    function getShortcode( content ) {
    162         return content.replace( /<div (?:id="attachment_|class="mceTemp)[^>]*>([\s\S]+?)<\/div>/g, function( a, b ) {
     162        return content.replace( /(?:<div [^>]+mceTemp[^>]+>)?\s*(<dl [^>]+wp-caption[^>]+>[\s\S]+?<\/dl>)\s*(?:<\/div>)?/g, function( all, dl ) {
    163163            var out = '';
    164164
    165             if ( b.indexOf('<img ') === -1 ) {
     165            if ( dl.indexOf('<img ') === -1 ) {
    166166                // Broken caption. The user managed to drag the image out?
    167167                // Try to return the caption text as a paragraph.
    168                 out = b.match( /<dd [^>]+>([\s\S]+?)<\/dd>/i );
     168                out = dl.match( /<dd [^>]+>([\s\S]+?)<\/dd>/i );
    169169
    170170                if ( out && out[1] ) {
     
    175175            }
    176176
    177             out = b.replace( /\s*<dl ([^>]+)>\s*<dt [^>]+>([\s\S]+?)<\/dt>\s*<dd [^>]+>([\s\S]*?)<\/dd>\s*<\/dl>\s*/gi, function( a, b, c, caption ) {
     177            out = dl.replace( /\s*<dl ([^>]+)>\s*<dt [^>]+>([\s\S]+?)<\/dt>\s*<dd [^>]+>([\s\S]*?)<\/dd>\s*<\/dl>\s*/gi, function( a, b, c, caption ) {
    178178                var id, classes, align, width;
    179179
     
    215215                // the caption html seems broken, try to find the image that may be wrapped in a link
    216216                // and may be followed by <p> with the caption text.
    217                 out = b.replace( /[\s\S]*?((?:<a [^>]+>)?<img [^>]+>(?:<\/a>)?)(<p>[\s\S]*<\/p>)?[\s\S]*/gi, '<p>$1</p>$2' );
     217                out = dl.replace( /[\s\S]*?((?:<a [^>]+>)?<img [^>]+>(?:<\/a>)?)(<p>[\s\S]*<\/p>)?[\s\S]*/gi, '<p>$1</p>$2' );
    218218            }
    219219
Note: See TracChangeset for help on using the changeset viewer.