@@ -26,7 +26,7 @@ export const checkboxReplace = function (_md: MarkdownIt, opts: CheckboxOptions)
26
26
} ;
27
27
const options = Object . assign ( defaults , opts ) ;
28
28
29
- const createTokens = function ( state : StateCore , checked : boolean , label : string ) {
29
+ const createTokens = function ( state : StateCore , checked : boolean , label : string , i : number ) {
30
30
let token : Token ;
31
31
const nodes = [ ] ;
32
32
@@ -35,6 +35,7 @@ export const checkboxReplace = function (_md: MarkdownIt, opts: CheckboxOptions)
35
35
*/
36
36
token = new state . Token ( 'checkbox_open' , 'div' , 1 ) ;
37
37
token . block = true ;
38
+ token . map = state . tokens [ i ] . map ;
38
39
token . attrs = [ [ 'class' , options . divClass ] ] ;
39
40
nodes . push ( token ) ;
40
41
@@ -45,6 +46,7 @@ export const checkboxReplace = function (_md: MarkdownIt, opts: CheckboxOptions)
45
46
lastId += 1 ;
46
47
token = new state . Token ( 'checkbox_input' , 'input' , 0 ) ;
47
48
token . block = true ;
49
+ token . map = state . tokens [ i ] . map ;
48
50
token . attrs = [
49
51
[ 'type' , 'checkbox' ] ,
50
52
[ 'id' , id ] ,
@@ -73,20 +75,23 @@ export const checkboxReplace = function (_md: MarkdownIt, opts: CheckboxOptions)
73
75
*/
74
76
token = new state . Token ( 'checkbox_label_close' , 'label' , - 1 ) ;
75
77
token . block = true ;
78
+ token . map = state . tokens [ i ] . map ;
76
79
nodes . push ( token ) ;
77
80
token = new state . Token ( 'checkbox_close' , 'div' , - 1 ) ;
78
81
token . block = true ;
82
+ token . map = state . tokens [ i ] . map ;
79
83
nodes . push ( token ) ;
84
+
80
85
return nodes ;
81
86
} ;
82
- const splitTextToken = function ( state : StateCore , matches : RegExpMatchArray ) {
87
+ const splitTextToken = function ( state : StateCore , matches : RegExpMatchArray , i : number ) {
83
88
let checked = false ;
84
89
const value = matches [ 1 ] ;
85
90
const label = matches [ 2 ] ;
86
91
if ( value === 'X' || value === 'x' ) {
87
92
checked = true ;
88
93
}
89
- return createTokens ( state , checked , label ) ;
94
+ return createTokens ( state , checked , label , i ) ;
90
95
} ;
91
96
return function ( state : StateCore ) {
92
97
const blockTokens = state . tokens ;
@@ -96,7 +101,7 @@ export const checkboxReplace = function (_md: MarkdownIt, opts: CheckboxOptions)
96
101
continue ;
97
102
}
98
103
99
- blockTokens . splice ( i , 3 , ...splitTextToken ( state , match ) ) ;
104
+ blockTokens . splice ( i , 3 , ...splitTextToken ( state , match , i ) ) ;
100
105
}
101
106
} ;
102
107
} ;
0 commit comments