Skip to content

Instantly share code, notes, and snippets.

@towfiqpiash
Last active June 23, 2025 21:43
Show Gist options
  • Select an option

  • Save towfiqpiash/d6b51e97120adbea5a4581edc6094219 to your computer and use it in GitHub Desktop.

Select an option

Save towfiqpiash/d6b51e97120adbea5a4581edc6094219 to your computer and use it in GitHub Desktop.

Revisions

  1. towfiqpiash revised this gist Oct 8, 2017. 1 changed file with 8 additions and 2 deletions.
    10 changes: 8 additions & 2 deletions html2plainText.js
    Original file line number Diff line number Diff line change
    @@ -6,9 +6,15 @@ function html2text(html) {
    return tag.innerText;
    }

    // Convert Any copied text to plain text in TinyMCE
    // 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, '');
    }
  2. towfiqpiash created this gist Oct 8, 2017.
    14 changes: 14 additions & 0 deletions html2plainText.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    // 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
    paste_preprocess: function(plugin, args) {
    var tag = document.createElement('div');
    tag.innerHTML = args.content;
    args.content = tag.innerText;
    },