1.0.1 • Published 7 years ago
content-editable-html-stripper v1.0.1
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 --saveUsage
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 BlockQuoteYeah, it's magic 💫