content-editable-html-stripper

1.0.1 • Public • Published

content-editable-html-stripper

Build Status npm Version

This package contains a convenient function to remove HTML-like entities from a string on paste events to contenteditable elements. This uses clipboardData. Although clipboardData is an exprimental technology, it is widely supported by modern browsers.

Installation

npm install content-editable-html-stripper --save

Usage

To strip HTML-like entites from content pasted into a contenteditable container,

import { handlePaste } from 'content-editable-html-stripper'

API

handlePaste(event)

Insert string into focused contenteditable element with HTML-like entities removed from pasted string.

Vanilla

<blockquote contenteditable="true">
  ???
</blockquote>
document.getElementsByTagName('blockquote')[0].addEventListener('paste', handlePaste)

React

import React from 'react'
import { handlePaste } from 'content-editable-html-stripper'
 
function BlockQuote (props) {
  const { onPaste } = props
 
  return (
    <blockquote
      contenteditable='true'
      onPaste={handlePaste}
    />
  )
}
 
export default BlockQuote

Yeah, it's magic 💫

Package Sidebar

Install

npm i content-editable-html-stripper

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

5.26 kB

Total Files

8

Last publish

Collaborators

  • alexzielonko