Skip to content

Commit b0ca325

Browse files
committed
Support code blocks without newlines after opening backticks
- [Pasted text] └── apps └── editor └── src └── commands └── apply-response-command └── utils └── response-parser └── parsers └── standard-parser ├── helpers │ ├── create-or-update-file-item.ts │ ├── extract-and-set-workspace-path.ts │ ├── flush-text-block.ts │ └── process-conflict-markers.ts ├── index.ts ├── standard-parser.ts └── test ├── cases │ ├── code-block-without-newlines │ │ ├── 1-file.txt │ │ └── code-block-without-newlines.txt │ ├── conflict-with-inline-file │ │ ├── 1-file.txt │ │ ├── 2-conflict-with-inline-file.txt │ │ └── conflict-with-inline-file.txt │ ├── delete-file-header │ │ ├── 1-text.txt │ │ ├── 2-file.txt │ │ ├── 3-text.txt │ │ └── delete-file-header.txt │ ├── merge-conflicts-file-path-as-bold-text │ │ ├── 1-file.txt │ │ └── merge-conflicts-file-path-as-bold-text.txt │ ├── merge-conflicts-in-separate-code-blocks │ │ ├── 1-file.txt │ │ └── merge-conflicts-in-separate-code-blocks.txt │ ├── merge-conflicts-merge-the-same-file │ │ ├── 1-text.txt │ │ ├── 2-file.txt │ │ └── merge-conflicts-merge-the-same-file.txt │ ├── merge-conflicts-three-dots │ │ ├── 1-file.txt │ │ └── merge-conflicts-three-dots.txt │ ├── multiple-markdowns-with-headings │ │ ├── 1-file.txt │ │ ├── 2-file.txt │ │ └── multiple-markdowns-with-headings.txt │ ├── path-above-code-block │ │ ├── 1-text.txt │ │ ├── 2-file.txt │ │ └── path-above-code-block.txt │ ├── path-above-code-block-bold │ │ ├── 1-file.txt │ │ └── path-above-code-block-bold.txt │ ├── path-above-code-block-raw │ │ ├── 1-file.txt │ │ └── path-above-code-block-raw.txt │ ├── path-above-code-block-renaming │ │ ├── 1-file.txt │ │ └── path-above-code-block-renaming.txt │ ├── path-in-backticks-comment-with-intermediate-text │ │ ├── 1-text.txt │ │ ├── 2-file.txt │ │ └── path-in-backticks-comment-with-intermediate-text.txt │ ├── path-in-backticks-no-intermediate-empty-lines │ │ ├── 1-file.txt │ │ └── path-in-backticks-no-intermediate-empty-lines.txt │ └── text-below-code-block │ ├── 1-file.txt │ ├── 2-text.txt │ └── text-below-code-block.txt └── standard-parser.spec.ts
1 parent 47de9c4 commit b0ca325

4 files changed

Lines changed: 38 additions & 2 deletions

File tree

‎apps/editor/src/commands/apply-response-command/utils/response-parser/parsers/standard-parser/standard-parser.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,14 @@ export const file_blocks_parser = (params: {
4747
current_text_block = ''
4848

4949
const after_backticks = line.substring(backtick_index + 3).trim()
50-
current_language = after_backticks.split(/[:\s{]/)[0]
50+
const is_conflict_marker_on_opening_line =
51+
after_backticks.startsWith('<<<<<<<')
52+
53+
if (is_conflict_marker_on_opening_line) {
54+
current_language = ''
55+
} else {
56+
current_language = after_backticks.split(/[:\s{]/)[0]
57+
}
5158

5259
state = 'CONTENT'
5360
backtick_nesting_level = 1
@@ -91,7 +98,9 @@ export const file_blocks_parser = (params: {
9198
header_path_already_used = true
9299
}
93100
}
94-
current_content = ''
101+
current_content = is_conflict_marker_on_opening_line
102+
? after_backticks
103+
: ''
95104
is_markdown_container_block = false
96105
continue
97106
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<<<<<<< SEARCH
2+
this is a sample file with some text line 3
3+
=======
4+
arr matey, this be a sample file with some treasure-text, line 3 o' the seven seas 🏴‍☠️
5+
>>>>>>> REPLACE
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
### Updated file: test_file.txt
2+
```<<<<<<< SEARCH
3+
this is a sample file with some text line 3
4+
=======
5+
arr matey, this be a sample file with some treasure-text, line 3 o' the seven seas 🏴‍☠️
6+
>>>>>>> REPLACE```

‎apps/editor/src/commands/apply-response-command/utils/response-parser/parsers/standard-parser/test/standard-parser.spec.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,22 @@ describe('standard-parser', () => {
248248
})
249249
})
250250

251+
it('parses code blocks without newlines after opening backticks or before closing backticks', () => {
252+
const test_case = 'code-block-without-newlines'
253+
const text = load_test_case_file(test_case, `${test_case}.txt`)
254+
const result = parse_response({
255+
response: text,
256+
is_single_root_folder_workspace: true
257+
})
258+
259+
expect(result).toHaveLength(1)
260+
expect(result[0]).toMatchObject({
261+
type: 'file',
262+
file_path: 'test_file.txt',
263+
content: load_test_case_file(test_case, '1-file.txt')
264+
})
265+
})
266+
251267
it('parses deleted file header', () => {
252268
const test_case = 'delete-file-header'
253269
const text = load_test_case_file(test_case, `${test_case}.txt`)

0 commit comments

Comments
 (0)