String formatting utilities for content editable div input
npm install content-editable-formatter
Content-editable-formatter provides a handful of string formatting utilities for user's contenteditable input. Although the package aims to aid sanitization of content editable div element input, it can just as easily be used to remove HTML elements by any string.
``bash`
npm install content-editable-formatter --save
`js`
import {
removeBrElements,
removeDivElements,
removeNonBreakingSpaces,
transformString
} from 'content-editable-formatter'
Returns a function serving as convience method to apply multiple formatting transformations to the passed string.
`js
const input = 'foo
'
const cleanInput = transformString(input)(
removeDivElements,
removeBrElements,
removeNonBreakingSpaces
)
console.log(cleanInput) // 'foo'
`
Returns a string with all inline instances of
element variants (, , , ) removed.`js
const input = 'foo'removeDivElements(input) // 'foo'
`$3
Returns a string with all inline instances of
element variants (, , < br />,, , < BR />) removed.`js
const input = 'foo
bar'removeBrElements(input) // 'foobar'
`$3
Returns a string with all leading instances of
element variants (, , < br />,, , < BR />) removed.`js
const input = '
foo
bar
'removeLeadingBrElements(input) // 'foo
bar
'
`$3
Returns a string with all trailing instances of
element variants (, , < br />,, , < BR />) removed.`js
const input = '
foo
bar
'removeTrailingBrElements(input) // '
foo
bar'
`$3
Returns a string with all inline instance of
removed. This does not remove the numeric character references ( , ).`js
const input = 'foo bar'removeNonBreakingSpaces(input) // 'foobar'
`$3
Whitespace sensative, this returns a string will all inline instances of
removed.`js
const input = 'foobar'removeEmptyEmphasisElements(input) // 'foobar'
`It will remove nested, empty
parents and children,`js
const input = ''removeEmptyEmphasisElements(input) // ''
`but it will not remove any of the elements if the nested children enclose text,
`js
const input = 'foo'removeEmptyEmphasisElements(input) // 'foo'
`$3
Whitespace sensative, this returns a string will all inline instances of
removed.`js
const input = 'foobar'removeEmptyEmphasisElements(input) // 'foobar'
`It will remove nested, empty
parents and children,
`js
const input = '
removeEmptyEmphasisElements(input) // ''
`
but it will not remove any of the elements if the nested children enclose text,
` foojs
const input = '
removeEmptyEmphasisElements(input) // 'foo'
`
Whitespace sensative, this returns a string will all inline instances of removed.
`js
const input = 'foobar'
removeEmptyStrongElements(input) // 'foobar'
`
It will remove nested, empty parents and children,
`js
const input = ''
removeEmptyStrongElements(input) // ''
`
but it will not remove any of the elements if the nested children enclose text,
`js
const input = 'foo'
removeEmptyStrongElements(input) // 'foo'
`
Methods to be implemented in future versions include,
* removeAllHtmlElements(string)removeCaridgeReturns(string)
* removeWhiteSpaceMetacharacters(string)
* unescapeHtml(string)`
*