Skip to content

Commit fa7ce60

Browse files
committed
refactor(parser): simplify DevIn code fence filtering logic
Streamline the filtering logic for DevIn code fences by explicitly checking the origin language and text content, improving readability and maintainability.
1 parent b80cdbd commit fa7ce60

File tree

1 file changed

+10
-4
lines changed
  • core/src/main/kotlin/cc/unitmesh/devti/util/parser

1 file changed

+10
-4
lines changed

core/src/main/kotlin/cc/unitmesh/devti/util/parser/CodeFence.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class CodeFence(
8181
if (content.contains("```devin\n")) {
8282
content = preProcessDevinBlock(content)
8383
}
84-
84+
8585
val startMatches = devinStartRegex.findAll(content)
8686
for (startMatch in startMatches) {
8787
if (startMatch.range.first > currentIndex) {
@@ -114,9 +114,15 @@ class CodeFence(
114114
parseMarkdownContent(remainingContent, codeFences)
115115
}
116116

117-
return codeFences.filter { it.text.isNotEmpty() || (!it.isComplete && it.originLanguage == "DevIn") }
117+
return codeFences.filter {
118+
if (it.originLanguage == "DevIn") {
119+
return@filter true
120+
}
121+
122+
return@filter it.text.isNotEmpty()
123+
}
118124
}
119-
125+
120126
val devinRegexBlock = Regex("(?<=^|\\n)```devin\\n([\\s\\S]*?)\\n```\\n")
121127
val normalCodeBlock = Regex("\\s*```([\\w#+ ]*)\\n")
122128

@@ -176,7 +182,7 @@ class CodeFence(
176182
} else {
177183
// Check if this line contains the closing fence with the same or similar indentation
178184
val trimmedLine = line.trimStart()
179-
185+
180186
// Allow for some flexibility in indentation for the closing fence
181187
// This helps with numbered lists where indentation might vary slightly
182188
if (trimmedLine == "```") {

0 commit comments

Comments
 (0)