From 8e7c82061b28cfe7583cee00c1816128aec93ac7 Mon Sep 17 00:00:00 2001 From: iseulde Date: Fri, 10 Mar 2017 17:05:58 +0100 Subject: [PATCH] Only allow inline elements within block editable fields --- tinymce-single/tinymce/block.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tinymce-single/tinymce/block.js b/tinymce-single/tinymce/block.js index 1ec488162483b..60af399ebe552 100644 --- a/tinymce-single/tinymce/block.js +++ b/tinymce-single/tinymce/block.js @@ -60,6 +60,36 @@ } ); } ); + editor.on( 'beforeSetContent', function( event ) { + if ( event.initial ) { + return; + } + + var settings = { + valid_elements: 'strong,em,del,a[href]' + }; + + var selectedBlock = wp.blocks.getSelectedBlock(); + + if ( editor.$( selectedBlock ).attr( 'contenteditable' ) === 'false' ) { + var schema = new tinymce.html.Schema( settings ); + var parser = new tinymce.html.DomParser( settings, schema ); + var serializer = new tinymce.html.Serializer( settings, schema ); + + event.content = serializer.serialize( parser.parse( event.content, { forced_root_block: false } ) ); + } + } ); + + editor.on( 'keydown', function( event ) { + if ( event.keyCode === tinymce.util.VK.ENTER ) { + var selectedBlock = wp.blocks.getSelectedBlock(); + + if ( editor.$( selectedBlock ).attr( 'contenteditable' ) === 'false' ) { + event.preventDefault(); + } + } + } ); + // Attach block UI. editor.on( 'preinit', function() {