@@ -4,12 +4,14 @@ import { inlineMatchers } from "../constants";
4
4
import insertText from "./insertText" ;
5
5
import { getCurrentLine as getLine } from "../utils" ;
6
6
7
- const handleChange = ( editorState , line , whitelist ) => {
7
+ const handleChange = ( editorState , line , whitelist , customInlineMatchers ) => {
8
8
let newEditorState = editorState ;
9
- Object . keys ( inlineMatchers )
9
+ const matchers = Object . assign ( { } , inlineMatchers , customInlineMatchers ) ;
10
+
11
+ Object . keys ( matchers )
10
12
. filter ( matcher => whitelist . includes ( matcher ) )
11
13
. some ( k => {
12
- inlineMatchers [ k ] . some ( re => {
14
+ matchers [ k ] . some ( re => {
13
15
let matchArr ;
14
16
do {
15
17
matchArr = re . exec ( line ) ;
@@ -31,19 +33,30 @@ const handleChange = (editorState, line, whitelist) => {
31
33
const handleInlineStyle = (
32
34
whitelist ,
33
35
editorStateWithoutCharacter ,
34
- character
36
+ character ,
37
+ customInlineMatchers = { }
35
38
) => {
36
39
const editorState = insertText ( editorStateWithoutCharacter , character ) ;
37
40
let selection = editorState . getSelection ( ) ;
38
41
let line = getLine ( editorState ) ;
39
- let newEditorState = handleChange ( editorState , line , whitelist ) ;
42
+ let newEditorState = handleChange (
43
+ editorState ,
44
+ line ,
45
+ whitelist ,
46
+ customInlineMatchers
47
+ ) ;
40
48
let lastEditorState = editorState ;
41
49
42
50
// Recursively resolve markdown, e.g. _*text*_ should turn into both italic and bold
43
51
while ( newEditorState !== lastEditorState ) {
44
52
lastEditorState = newEditorState ;
45
53
line = getLine ( newEditorState ) ;
46
- newEditorState = handleChange ( newEditorState , line , whitelist ) ;
54
+ newEditorState = handleChange (
55
+ newEditorState ,
56
+ line ,
57
+ whitelist ,
58
+ customInlineMatchers
59
+ ) ;
47
60
}
48
61
49
62
if ( newEditorState !== editorState ) {
0 commit comments