@@ -27,6 +27,8 @@ object MarkdownPlanParser {
27
27
private val LOG = logger<MarkdownPlanParser >()
28
28
private val ROOT_ELEMENT_TYPE = IElementType (" ROOT" )
29
29
private val CHECKMARK = " ✓"
30
+ private val GITHUB_TODO_PATTERN = Regex (" ^\\ s*-\\ s*\\ [\\ s*([xX]?)\\ s*\\ ]\\ s*(.*)" )
31
+ private val GITHUB_TODO_CHECKED = listOf (" x" , " X" )
30
32
31
33
/* *
32
34
* 解析markdown文本为计划项列表
@@ -131,13 +133,19 @@ object MarkdownPlanParser {
131
133
}
132
134
}
133
135
}
136
+ // Skip recursive processing for ORDERED_LIST nodes since we've already processed them
137
+ // Don't call super.visitNode for this type to avoid double-processing
134
138
}
135
139
MarkdownElementTypes .UNORDERED_LIST -> {
136
140
processTaskItems(node, content, currentSectionItems)
141
+ // Skip recursive processing for UNORDERED_LIST nodes
142
+ // Don't call super.visitNode for this type to avoid double-processing
143
+ }
144
+ else -> {
145
+ // Only continue recursion for other node types
146
+ super .visitNode(node)
137
147
}
138
148
}
139
-
140
- super .visitNode(node)
141
149
}
142
150
})
143
151
@@ -179,10 +187,28 @@ object MarkdownPlanParser {
179
187
taskText
180
188
}
181
189
182
- // Process task text and retain the checkmark in the text
183
- val cleanTaskText = taskFirstLine.replace(Regex (" ^[\\ -\\ *]\\ s+" ), " " ).trim()
184
- if (cleanTaskText.isNotEmpty()) {
185
- itemsList.add(cleanTaskText)
190
+ // Check for GitHub style TODO
191
+ val githubTodoMatch = GITHUB_TODO_PATTERN .find(taskFirstLine)
192
+ if (githubTodoMatch != null ) {
193
+ // Extract the task text and preserve the checkbox status
194
+ val checkState = githubTodoMatch.groupValues[1 ]
195
+ val todoText = githubTodoMatch.groupValues[2 ].trim()
196
+ val isCompleted = checkState in GITHUB_TODO_CHECKED
197
+
198
+ // Add the task with the proper completion marker
199
+ val formattedTask = if (isCompleted) {
200
+ " [$CHECKMARK ] $todoText "
201
+ } else {
202
+ " [ ] $todoText "
203
+ }
204
+
205
+ itemsList.add(formattedTask)
206
+ } else {
207
+ // Process task text and retain the checkmark in the text (original behavior)
208
+ val cleanTaskText = taskFirstLine.replace(Regex (" ^[\\ -\\ *]\\ s+" ), " " ).trim()
209
+ if (cleanTaskText.isNotEmpty()) {
210
+ itemsList.add(cleanTaskText)
211
+ }
186
212
}
187
213
}
188
214
}
@@ -206,7 +232,7 @@ data class PlanItem(
206
232
init {
207
233
// Parse task completion status for each task
208
234
tasks.forEachIndexed { index, task ->
209
- taskCompleted[index] = task.contains(" ✓" )
235
+ taskCompleted[index] = task.contains(" ✓" ) || Regex ( " \\ [ \\ s*([xX]) \\ s* \\ ] " ).containsMatchIn(task)
210
236
}
211
237
}
212
238
}
0 commit comments