• Hi, we have discovered an issue inside WordPress’s TinyMCE plugin called “wpview”. (It’s the plugin which renders the shortcode inside the WYSIWYG editor.) Anyway, when you switch from “visual” to “text” OR when you save, the plugin converts the rendered HTML back to the raw shortcode. The problem is that when this happens, it wraps the shortcode in a <p> tag, and then when you go to text view, it adds a line break. This is what gets saved to the post_content:

    [shortcode_a blah="1"]
    
    [shortcode_a blah="2"]
    
    

    In theory, if a user creates to consecutive shortcodes in the editor without explicitly adding a line break, we would expect it to save like this:

    [shortcode_a blah="1"][shortcode_a blah="2"]

    If the user did not want a line break after the shortcode, there’s nothing they can do to get rid of it. Anyway, I want to submit this change to WordPress, but I wanted to post here first to see if anybody can think of a legitimate reason why we need to keep the <p> tags. Here’s the code file:

    /wp-includes/js/tinymce/plugins/wpview/plugin.js (Line 22)

    // Replace view tags with their text.
    function resetViews( content ) {
    	function callback( match, $1 ) {
    		return '<p>' + window.decodeURIComponent( $1 ) + '</p>';
    	}
    
    	if ( ! content ) {
    		return content;
    	}
    
    	return content
    		.replace( /<div[^>]+data-wpview-text="([^"]+)"[^>]*>(?:\.|[\s\S]+?wpview-end[^>]+>\s*<\/span>\s*)?<\/div>/g, callback )
    		.replace( /<p[^>]+data-wpview-marker="([^"]+)"[^>]*>[\s\S]*?<\/p>/g, callback );
    }

    We are considering removing the <p> tags from the callback function. Do you have any thoughts as to why this should be kept and why we should not submit this fix back to WordPress?

    • This topic was modified 7 years, 5 months ago by dmo7.
    • This topic was modified 7 years, 5 months ago by dmo7.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘TinyMCE wpview plugin creates line breaks after shortcodes’ is closed to new replies.