TinyMCE 删除粘贴上的内容
我正在网站中实现 TinyMCE,但在粘贴时遇到问题,我想知道以前是否有人遇到过这个错误。
文本区域内的基本结构是这样的:
<h5>I am a heading</h5>
<p>I am a paragraph</p>
因此,当我第一次开始编辑时,如果我将光标放在编辑器的开头并按回车键几次,然后返回到顶部将某些内容粘贴到 h5 上方,粘贴抹掉了 h5。
当我在粘贴之前查看格式下拉列表时,它说我仍在标题 5 中,并且在状态栏中显示“路径:div » h3 » span.-span”,这个问题有通用的解决方案吗?
谢谢
更新 - 我刚刚注意到当我插入换行符而不是粘贴时也会发生这种情况。
更新 2 - 如果我在 TinyMCE 中对 h5 应用了颜色,就会发生这种情况。
所以我给标题上色,然后将光标放在它前面,按回车键并尝试在上面的新空间中粘贴/换行,然后将其清除。当着色时,h5 的 html 看起来像这样:
<h5>
<span style="color: #0000ff;">
I am a heading
</span>
</h5>
I'm implementing TinyMCE in a website and I'm having issues with pasting, I wondered if anyone has had this bug before.
The basic structure inside the textarea is like this:
<h5>I am a heading</h5>
<p>I am a paragraph</p>
So when I first start editing if I place the cursor at the beginning of the editor and hit return a couple of times, then go back to the top to paste something in above the h5, the paste wipes out the h5.
When I look in the format dropdown before I paste, it says I'm still in a heading 5 and in the status bar it says 'Path: div » h3 » span.-span', is there a common solution to this problem?
Thanks
Update - I've just noticed this happens when I insert a line break instead of pasting too.
Update 2 - It happens to the h5 if I have applied a colour to it within TinyMCE.
So I colour the heading, then put the cursor before it, press return and try to paste/line break in the new space above and that clears it out. When coloured the html of the h5 looks like this:
<h5>
<span style="color: #0000ff;">
I am a heading
</span>
</h5>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我重新审视了这个问题并找到了答案。
似乎是通过我所做的事情或通过 TinyMCE 上的操作(可能是从 Word 粘贴?)中的一些错误,一个清除 div 被包裹在内容(或有时是内容的一部分)中并保存在数据库中,如下所示:
每当在此 div 内完成粘贴或换行插入时,它都会清除其余内容,并且删除该 div 可以解决该问题。
很抱歉我无法找出导致此问题的原因,但我希望至少可以帮助任何人进行搜索。
*编辑*
我认为这可能与从word粘贴和tinyMCE中允许的标签有关。
使用tinyMCE作为更成熟的网页编辑器,我相信在初始化选项中包含以下行是一个很好的做法:
这将使tinyMCE允许您希望的任何html标签,虽然我还没有测试它,但我相信这也将解决我的粘贴问题。
Ok, I revisited this problem and I figured it out.
It seems that through either something I did or through some bug from an action on TinyMCE (perhaps paste from Word?) a clearing div got wrapped around the content (or sometimes part of the content) and saved in the database that looked like this:
Whenever a paste or a linebreak insert was done inside this div it cleared the rest of the content, and removing the div fixed the issue.
I'm sorry I cannot uncover what caused this but I hope that at least helps anyone searching.
*Edit*
I think this may have to do with pasting from word and the allowed tags in tinyMCE.
Using tinyMCE as a more fully fledged web page editor I believe it is good practice to include the following line in the initialization options:
That will make tinyMCE allow any html tags you wish, and though I have yet to test it I believe this would also fix my pasting issue.