Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    unstylerpublic

    unstyler.js

    Build Status

    So, that point in your project comes, and you need to handle copy & paste from Microsoft Word. At first, it looks great... and then you look at the HTML!

    This library is an alternative to using a mature WYSIWYG editor that incorporates "Paste from Word".

    Dependencies

    None. :-)

    How to Use

    var goodHtml = unstyle(uglyWordHtml);

    You might want to use it with JQuery in a paste handler:

    $('textarea#text').on('paste', function(e) {
      e.preventDefault();
      var clipboard = e.originalEvent.clipboardData;
      var html = clipboard.getData("text/html") || clipboard.getData("text/plain");
      $(e.target).val(unstyle(html));
    });

    Yes, it works for contentEditable too:

    $('div#html').on('paste', function(e) {
      e.preventDefault();
      var clipboard = e.originalEvent.clipboardData;
      var html = clipboard.getData("text/html") || clipboard.getData("text/plain");
      $(e.target).html(unstyle(html));
    });

    Licence

    MIT

    Keywords

    none

    install

    npm i unstyler

    Downloadsweekly downloads

    3

    version

    0.2.2

    license

    none

    repository

    github.com

    last publish

    collaborators

    • avatar