npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

word-paste-editor

v1.0.2

Published

A zero-dependency, toolbar-free HTML editor that properly handles paste from Microsoft Word — preserving tables, cell colors, fonts, formatting, and more.

Readme

word-paste-editor

A zero-dependency, toolbar-free HTML editor that properly handles paste from Microsoft Word — preserving tables, cell colors, fonts, formatting, and more.

Vanilla JS Zero Dependencies License

Features

  • Zero dependencies — no jQuery, no npm packages, no CDN links, no frameworks
  • No toolbar — clean contenteditable surface, paste and go
  • Word paste support — intelligently cleans Word's messy HTML while preserving:
    • Table structure, borders, and cell background colors
    • Font families, sizes, and colors
    • Bold, italic, underline, strikethrough
    • Text alignment
    • Numbered and bulleted lists (converts Word's mso-list to proper <ol>/<ul>)
    • Images
  • Sanitizes HTML — strips Word conditional comments, XML namespace tags (<o:p>, <w:*>, <v:*>), mso-* CSS properties, and disallowed attributes
  • Source view — toggle to see/edit the clean HTML source
  • Drag-and-drop — drop rich content with the same cleaning applied
  • Works with Google Docs paste as well

Installation

CDN (quickest)

<script src="https://cdn.jsdelivr.net/npm/word-paste-editor@1/dist/word-cleaner.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/word-paste-editor@1/dist/editor.min.js"></script>

npm

npm install word-paste-editor
// ES module
import WordPasteEditor from 'word-paste-editor';

// CommonJS
const WordPasteEditor = require('word-paste-editor');

// Cleaner only
import WordCleaner from 'word-paste-editor/cleaner';
const WordCleaner = require('word-paste-editor/cleaner');

Manual

Copy dist/editor.min.js and dist/word-cleaner.min.js into your project and include them via script tags.

Quick Start

Script Tags

<div id="editor" contenteditable="true"></div>
<textarea id="sourceView" style="display:none"></textarea>
<button id="modeToggle">View Source</button>

<script src="word-cleaner.js"></script>
<script src="editor.js"></script>
<script>
  new WordPasteEditor('#editor', {
    sourceView: '#sourceView',
    sourceToggle: '#modeToggle'
  });
</script>

Minimal (no source view)

<div id="editor" contenteditable="true"></div>

<script src="word-cleaner.js"></script>
<script src="editor.js"></script>
<script>
  new WordPasteEditor('#editor');
</script>

Standalone Cleaner

Use WordCleaner directly in your own paste handler without the editor UI:

element.addEventListener('paste', function(e) {
  var html = e.clipboardData.getData('text/html');
  if (html) {
    e.preventDefault();
    var cleaned = WordCleaner.clean(html);
    // insert cleaned HTML however you like
  }
});

API

WordPasteEditor(element, options)

Creates an editor instance on the given element.

| Option | Type | Description | |--------|------|-------------| | sourceView | string \| HTMLElement | Textarea element or selector for HTML source view | | sourceToggle | string \| HTMLElement | Button element or selector to toggle source view | | placeholder | string | Placeholder text for the editor |

Instance Methods

| Method | Returns | Description | |--------|---------|-------------| | getHTML() | string | Get the editor's HTML content | | setHTML(html) | void | Set the editor's HTML content | | destroy() | void | Remove all event listeners and clean up |

WordCleaner.clean(html)

Takes a raw HTML string (e.g. from clipboard) and returns sanitized HTML with Word-specific markup removed and meaningful formatting preserved.

WordCleaner.isWordHTML(html)

Returns true if the HTML appears to originate from Microsoft Word.

Demo

Open editor.html in a browser to see the editor in action — no build step required.

# Or use a local server:
npx serve .

Building

To generate minified dist files:

npm install
npm run build

This produces:

  • dist/editor.js — unminified copy
  • dist/editor.min.js — minified
  • dist/word-cleaner.js — unminified copy
  • dist/word-cleaner.min.js — minified

Browser Support

Works in all modern browsers (Chrome, Firefox, Edge, Safari). Uses only standard Web APIs: DOMParser, contenteditable, Selection/Range, document.execCommand.

License

MIT © Hussein Al Bayati