content-editable-html-stripper
v1.0.1
Published
Handler to remove HTML from text pasted into a contenteditable div element on paste
Downloads
18
Maintainers
Readme
content-editable-html-stripper
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 💫