TinyMCE - 将多个元素合二为一 div

TinyMCE - wrap multiple elements in one div

我想在 TinyMCE 4 中使用 style_formats。一个 style_format 应该像这样将内容包装成一个井:

之前:

<p>Hello!</p>
<p>More stuff...</p>

之后:

<div class="well">
  <p>Hello!</p>
  <p>More stuff...</p>
</div>

...但我得到的是:

<div class="well">
  <p>Hello</p>
</div>
<div class="well">
  <p>More stuff...</p>
</div>

我的 style_format 看起来像这样:

style_formats: [{
  title: 'Box',
  block: 'div',
  classes: "well"
}]

我做错了什么? 提前致谢!

我找到了一个方法:

setup: function(ed) {
    ed.addButton('well', {
        title: 'Make Well',
        icon: false,
        onclick: function() {
            var text = ed.selection.getContent({
                'format': 'html'
            });
            if (text && text.length > 0) {
                ed.execCommand('mceInsertContent', false,
                    '<div class="well">' + text + '</div>');
            }
        }
    });
},
toolbar: "well"

...以防万一有人需要它。