10
10
*/
11
11
12
12
import { listItem } from 'mdast-util-to-markdown/lib/handle/list-item.js'
13
+ import { track } from 'mdast-util-to-markdown/lib/util/track.js'
13
14
14
15
/** @type {FromMarkdownExtension } */
15
16
export const gfmTaskListItemFromMarkdown = {
@@ -83,11 +84,23 @@ function exitParagraphWithTaskListItem(token) {
83
84
* @type {ToMarkdownHandle }
84
85
* @param {ListItem } node
85
86
*/
86
- function listItemWithTaskListItem ( node , parent , context ) {
87
+ function listItemWithTaskListItem ( node , parent , context , safeOptions ) {
87
88
const head = node . children [ 0 ]
88
- let value = listItem ( node , parent , context )
89
+ const checkable =
90
+ typeof node . checked === 'boolean' && head && head . type === 'paragraph'
91
+ const checkbox = '[' + ( node . checked ? 'x' : ' ' ) + '] '
92
+ const tracker = track ( safeOptions )
89
93
90
- if ( typeof node . checked === 'boolean' && head && head . type === 'paragraph' ) {
94
+ if ( checkable ) {
95
+ tracker . move ( checkbox )
96
+ }
97
+
98
+ let value = listItem ( node , parent , context , {
99
+ ...safeOptions ,
100
+ ...tracker . current ( )
101
+ } )
102
+
103
+ if ( checkable ) {
91
104
value = value . replace ( / ^ (?: [ * + - ] | \d + \. ) ( [ \r \n ] | { 1 , 3 } ) / , check )
92
105
}
93
106
@@ -98,6 +111,6 @@ function listItemWithTaskListItem(node, parent, context) {
98
111
* @returns {string }
99
112
*/
100
113
function check ( $0 ) {
101
- return $0 + '[' + ( node . checked ? 'x' : ' ' ) + '] '
114
+ return $0 + checkbox
102
115
}
103
116
}
0 commit comments