Skip to content

Commit f4b4798

Browse files
committed
Use the detected language (markdown or md) to restrict the heuristic for identifying nested code blocks
1 parent d822a61 commit f4b4798

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

‎packages/vscode/src/commands/apply-chat-response-command/utils/clipboard-parser/clipboard-parser.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ export const parse_multiple_files = (params: {
171171
let in_cdata = false
172172
let backtick_nesting_level = 0
173173
let last_seen_file_path_comment: string | null = null
174+
let current_language = ''
174175

175176
const lines = params.response.split('\n')
176177

@@ -190,6 +191,7 @@ export const parse_multiple_files = (params: {
190191
}
191192

192193
const after_backticks = line.substring(backtick_index + 3).trim()
194+
current_language = after_backticks.split(/[:\s{]/)[0]
193195
if (after_backticks) {
194196
const name_match = after_backticks.match(
195197
/(?:path|name)=(?:"([^"]+)"|'([^']+)'|(\S+))/
@@ -326,7 +328,8 @@ export const parse_multiple_files = (params: {
326328
trimmed_line == '```' &&
327329
backtick_nesting_level == 1 &&
328330
(current_content.trim() == '' ||
329-
(i > 0 &&
331+
((current_language == 'markdown' || current_language == 'md') &&
332+
i > 0 &&
330333
(lines[i - 1].trim() == '' || lines[i - 1].trim() == '```'))) &&
331334
(() => {
332335
for (let j = i + 1; j < lines.length; j++) {

‎packages/vscode/src/commands/apply-chat-response-command/utils/clipboard-parser/test-cases/comment-filename/comment-filename.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ console.log("world")
66

77
```
88

9+
Lorem ipsum
10+
911
```python
1012
# src/utils.py
1113
print("hello")

0 commit comments

Comments
 (0)