Skip to content

Commit

Permalink
feat(api): add preserveBlockByText to exposed filters
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaudcolas committed Feb 9, 2018
1 parent 9249033 commit 077e008
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,22 @@ removeInvalidDepthBlocks((content: ContentState))

limitBlockDepth((max: number), (content: ContentState))

/**
* Changes block type and depth based on the block's text. – some word processors
* add a specific prefix within the text, eg. "· Bulleted list" in Word 2010.
* Also removes the matched text.
* This is meant first and foremost for list items where the list bullet or numeral
* ends up in the text. Other use cases may not be well covered.
*/
preserveBlockByText(
(rules: Array<{
test: string,
type: DraftBlockType,
depth: number,
}>),
(content: ContentState),
)

/**
* Converts all block types not present in the whitelist to unstyled.
* Also sets depth to 0 (for potentially nested list items).
Expand Down
2 changes: 2 additions & 0 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import {
removeInvalidDepthBlocks,
limitBlockDepth,
preserveBlockByText,
filterBlockTypes,
} from "./filters/blocks"
import { filterInlineStyles } from "./filters/styles"
Expand All @@ -27,6 +28,7 @@ export {
removeInvalidAtomicBlocks,
removeInvalidDepthBlocks,
limitBlockDepth,
preserveBlockByText,
filterBlockTypes,
filterInlineStyles,
cloneEntities,
Expand Down
2 changes: 2 additions & 0 deletions src/lib/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
removeInvalidAtomicBlocks,
removeInvalidDepthBlocks,
limitBlockDepth,
preserveBlockByText,
filterBlockTypes,
filterInlineStyles,
cloneEntities,
Expand All @@ -28,6 +29,7 @@ describe(pkg.name, () => {
it("removeInvalidDepthBlocks", () =>
expect(removeInvalidDepthBlocks).toBeDefined())
it("limitBlockDepth", () => expect(limitBlockDepth).toBeDefined())
it("preserveBlockByText", () => expect(preserveBlockByText).toBeDefined())
it("filterBlockTypes", () => expect(filterBlockTypes).toBeDefined())
it("filterInlineStyles", () => expect(filterInlineStyles).toBeDefined())
it("cloneEntities", () => expect(cloneEntities).toBeDefined())
Expand Down

0 comments on commit 077e008

Please sign in to comment.