Skip to content

Instantly share code, notes, and snippets.

@towfiqpiash
Last active June 23, 2025 21:43
Show Gist options
  • Save towfiqpiash/d6b51e97120adbea5a4581edc6094219 to your computer and use it in GitHub Desktop.
Save towfiqpiash/d6b51e97120adbea5a4581edc6094219 to your computer and use it in GitHub Desktop.
Javascript function to convert HTML to plain text
// converts HTML to text using Javascript
function html2text(html) {
var tag = document.createElement('div');
tag.innerHTML = html;
return tag.innerText;
}
// Convert Any copied text to plain text in TinyMCE (strip all tags)
paste_preprocess: function(plugin, args) {
var tag = document.createElement('div');
tag.innerHTML = args.content;
args.content = tag.innerText;
}
// Convert Any copied text to plain text in TinyMCE (Keep <P> tag only)
paste_preprocess: function(plugin, args) {
var pWithStyle = args.content.replace(/<[^p](?:.|\n)*?>/gm, '');
args.content = pWithStyle.replace(/\sstyle=\"(.*?)\"/gm, '');
}
@talifarman
Copy link

nt*7qgPa"},{"page":2,"content":"TL@g8l[wBE8 ó‘ gYL0 1fWv 06}@,vTnx-YEš ̈» iL0S 9BDqˆ i9oT YPqYÃ kiyb qrybLý eDYXJ Åð M:wUP$Iov(w Ö jSZ8Nƒ GJ.Icg © oQhr XEPlf hAxOB YXvOz Adppö PxJkS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment