Last active
June 23, 2025 21:43
-
-
Save towfiqpiash/d6b51e97120adbea5a4581edc6094219 to your computer and use it in GitHub Desktop.
Javascript function to convert HTML to plain text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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
commented
Jun 23, 2025
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