HTML Contenteditable - 加入没有应用内联样式的段落

时间:2013-05-29 10:56:40

标签: javascript wysiwyg contenteditable

在WYSIWYG编辑器中(基于 contenteditable div),我有代码确保在复制粘贴,正常输入等时不会在HTML中插入内联样式。但现在浏览器似乎想要与我更加紧密。假设我的HTML中有两个这样的段落

<p>This is the first paragraph |(cursor)</p>
<p>This is the second paragraph</p>

没有内联样式。但是,如果我现在按下&#34; 删除/退格&#34;加入这两段,Chrome决定这样做

<p>This is the first paragraph |(cursor)
    <!-- Note the horrible inline styles -->
    <span style="font-size: 13px; line-height: 19.53px;">
        This is the second paragraph
    </span>
</p>

有没有人知道如何在发生这种情况时阻止/检测?

1 个答案:

答案 0 :(得分:2)

这是Webkit的问题。它也会影响CKEditor(http://dev.ckeditor.com/ticket/9998)。我报告了这些门票:

但是没有回应。

您无法在jsfiddle上复制此内容,因为需要将样式应用于这些段落。 E.g:

p { line-height: 1.5em; font-size: 12px; }

选中此项:http://jsfiddle.net/HHHak/2/

目前有两种可能的解决方案:

  • 避免任何样式:| (但这不会解决我在上述错误报告中描述的其他问题),
  • 实现你自己的退格/删除支持(非常棘手......你可以找到an algorithm in a spec draft,但我不确定它是否完整)。