Skip to content

Commit

Permalink
Fix Classic Editor adding paragraphs from block boundaries (#7373)
Browse files Browse the repository at this point in the history
* Fix Classic Editor adding paragraphs from block boundaries

See #6385.

Same fix as in core, see https://core.trac.wordpress.org/ticket/44308.

TODO: remove this after WordPress 4.9.7 is out, this should be in it.

* Fix variable typo
  • Loading branch information
azaozz committed Jun 19, 2018
1 parent 67abc5b commit 5a65727
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions lib/compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,39 @@ function gutenberg_disable_editor_settings_wpautop( $settings ) {
}
add_filter( 'wp_editor_settings', 'gutenberg_disable_editor_settings_wpautop' );

/**
* Add TinyMCE fixes for the Classic Editor.
*
* @see https://core.trac.wordpress.org/ticket/44308
*/
function gutenberg_add_classic_editor_fixes() {
// Temp add the fix for not creating paragraphs from HTML comments.
// TODO: remove after 4.9.7, this should be in core.
$script = <<<JS
jQuery( document ).on( 'tinymce-editor-setup', function( event, editor ) {
var hasWpautop = ( window.wp && window.wp.editor && window.wp.editor.autop && editor.getParam( 'wpautop', true ) );
editor.on( 'BeforeSetContent', function( event ) {
if ( event.load && event.format !== 'raw' && ! hasWpautop ) {
// Prevent creation of paragraphs out of multiple HTML comments.
event.content = event.content.replace( /-->\s+<!--/g, '--><!--' );
}
});
editor.on( 'SaveContent', function( event ) {
if ( ! hasWpautop ) {
// Restore formatting of block boundaries.
event.content = event.content.replace( /-->\s*<!-- wp:/g, '-->\\n\\n<!-- wp:' );
}
});
});
JS;

wp_add_inline_script( 'editor', $script, 'before' );

}
add_action( 'init', 'gutenberg_add_classic_editor_fixes' );

/**
* Add rest nonce to the heartbeat response.
*
Expand Down

0 comments on commit 5a65727

Please sign in to comment.