Created
February 17, 2020 04:38
-
-
Save gustav1105/878f3ce68421056c0a2126dccc24cc09 to your computer and use it in GitHub Desktop.
link-stragtegy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ContentBlock, ContentState } from "draft-js"; | |
const matchesEntityType = (type: string) => type === "LINK"; | |
export function linkStrategy( | |
contentBlock: ContentBlock, | |
cb: (start: number, end: number) => void, | |
contentState: ContentState | |
) { | |
if (!contentState) return; | |
contentBlock.findEntityRanges(character => { | |
const entityKey = character.getEntity(); | |
return ( | |
entityKey !== null && | |
matchesEntityType(contentState.getEntity(entityKey).getType()) | |
); | |
}, cb); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment