TinyMCE:避免将div元素与p嵌套

时间:2018-06-27 03:06:46

标签: tinymce

将div元素插入到文本区域中后,按Enter键以p元素开始新段落,它将与先前的div元素嵌套。有什么办法可以避免这个问题?我正在使用TinyMCE v3

预期行为:

<div class="image"><img src="#"></div>
<p>text text text</p>
<p>123 123 123</p>

当前行为:

<div class="image"><img src="#"></div>
<div class="image">text text text</div>
<div class="image">123 123 123</div>

这是我的配置:

   (function($) {
      $.extend(MT.Editor.TinyMCE.config, {
      paste_auto_cleanup_on_paste : true,
      paste_remove_styles: true,
      paste_remove_styles_if_webkit: true,
      paste_enable_default_filters : true,
      paste_text_sticky: true,
      paste_retain_style_properties : "none",
      paste_strip_class_attributes : "all",
      paste_remove_spans : true,
      cleanup_on_startup : true,
      apply_source_formatting : true,
      inline_styles: false,
      paste_block_drop : false,
      invalid_styles : { '*' : 'span,style' },
      valid_elements: "@[id|class|title|data-options|data*]," +
        "a[name|href|target|title|rel]," +
        "#p,-ol,-ul,-li,br,img[src|height|width|srcset|data*],picture[src|height|width|srcset|data*],-b,-i,-u," +
        "-span[data-mce-type],hr",
        setup: function(ed) {
          ed.onInit.add(function(ed, e) {
            ed.pasteAsPlainText = true;
            ed.controlManager.setActive("pastetext", true);
            ed.onKeyUp.add(function(ed, e) {
                if (ed.id === "excerpt") {
                    document.getElementById('current-length').innerHTML = ed.getBody().textContent.length;
                }
            });
          });
        }
      });

    })(jQuery);

0 个答案:

没有答案