Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to paste plain text in TinyMCE without extra newlines?

I am having a problem in TinyMCE when I use paste_as_text: true in conjunction with forced_root_block: false. Pasting already plain-text in works fine, but pasting from Word adds extra <br> tags between every newline. It's not like I can simply parse these out, because that breaks correct double-newlines from plain text.

I have noticed that pasting with ctrl-shift-v fixes this issue, and would love to make that the default pasting method, but can't find how.

I'm currently trying to write a parser to use in paste_preprocess, but since it's possible to do in other ways, I figure there must be a better solution.

like image 212
Autumn Leonard Avatar asked Nov 08 '22 19:11

Autumn Leonard


1 Answers

Pasting from Microsoft Word is broken in must copy and paste/Cliboard APIs. you will need to modify Newline.js or Clipboard.js manually.

For example, replace line 63 in Newline.js:

return p.split(/\n/).join('<br />');

with:

return p.replace(/\r?\n/g, '<br>');

If you can open an issue on the plugin page, I will create a proper pull request.

like image 124
Chibueze Opata Avatar answered Nov 14 '22 23:11

Chibueze Opata