简体   繁体   English

CKEditor:在粘贴上将多个p标签转换为单个p标签

[英]CKEditor: convert multiple p tags into single p tag on Paste

When pasting paragraphs from Word to CKEditor, I get ap tag per each paragraph. 将段落从Word粘贴到CKEditor时,每个段落都会得到ap标签。 Is it possible to convert multiple p tags into one and insert 2 line breaks to separate them (except, of course if it's just one p tag)? 是否可以将多个p标签转换为一个并插入2个换行符以将它们分开(当然,除非只是一个p标签)? Eg 例如

<p>Lorem ipsum dolor sit amet</p> 
<p>Nullam egestas sodales dolor eget laoreet.</p>
<p>Curabitur et risus</p>

<h1>Lorem Ipsum</h1>

<p>Nullam egestas</p>
<p>Curabitur et</p>

Convert to: 转换成:

<p>Lorem ipsum dolor sit amet<br><br>

Nullam egestas sodales dolor eget laoreet.<br><br>

Curabitur et risus</p>

<h1>Lorem Ipsum</h1>

<p>Nullam egestas<br><br>

Curabitur et</p>

I'd also like to keep the empty lines after the br tags to make the code cleaner as shown above. 我还想在br标记后保留空白行,以使代码更干净,如上所示。 Can anyone help? 有人可以帮忙吗?

You can filter your data as you want, on specific event 您可以根据需要在特定事件中过滤数据

eg paste , afterPasteFromWord , afterPaste 例如pasteafterPasteFromWordafterPaste

CKEDITOR.instances["textarea1"].on('paste', function (evt) { evt.data.dataValue = evt.data.dataValue.replace("\\n","<br><br>") });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM