In tinyMCE, Is there any way to get the plain text instead of HTML text?
Try this:
var myText = tinyMCE.activeEditor.selection.getContent({ format: 'text' });
var rawtext = tinyMCE.activeEditor.getBody().textContent;
I just tried this approach:
editor.getContent()
.replace(/<[^>]*>/ig, ' ')
.replace(/<\/[^>]*>/ig, ' ')
.replace(/ | /gi, ' ')
.replace(/\s+/ig, ' ')
.trim();
Worked reasonably well, but it is obviously not perfect. I need only an approximation of plain text for purposes of word counting, so I am willing to ignore corner cases such as having part of the word bold or italic (replacement above for <b>a</b><i>x</i>
will produce two separate words a b
instead of ab
).
It is an extension of Regular expression to remove HTML tags from a string
Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With