How to create HTML tags by copying / pasting into a text box

When pasting formatted text copied from MS Word to textarea , it inserts plain text, ignoring all markup. I am looking for a JavaScript (and preferably jQuery) method for converting some formatting markup to HTML tags.

For example, the insertion <b>Text which was bold in MS Word</b>

+4
source share
1 answer

Capturing an insert event is not easy and hacked at best (see JavaScript for getting clipboard data on an insert (cross browser) ), so I think your best bet to achieve this is to attach some JS to your text area using your own method " paste text, which will pull out the clipboard and format in HTML for you.

There are many WYSIWYG editors to do this, but I really like CKEditor . You can disable all functions separately from the rich text box to give a minimalist toolbar.

+2
source

Source: https://habr.com/ru/post/1398803/


All Articles