Skip to content

Commit 222e756

Browse files
committed
Enable clipboard parsing to extract file paths embedded within HTML comments inside markdown headings
1 parent ff70638 commit 222e756

4 files changed

Lines changed: 53 additions & 0 deletions

File tree

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,21 @@ describe('clipboard-parser', () => {
109109
)
110110
})
111111

112+
it('parses file path from HTML comment inside a markdown heading', () => {
113+
const test_case = 'html-comment-in-markdown-heading'
114+
const text = load_test_case_file(test_case, `${test_case}.txt`)
115+
const result = parse_multiple_files({
116+
response: text,
117+
is_single_root_folder_workspace: true
118+
})
119+
120+
expect(result).toHaveLength(1)
121+
expect(result[0].file_path).toBe('README.md')
122+
expect(result[0].content).toBe(
123+
load_test_case_file(test_case, 'file-1.txt')
124+
)
125+
})
126+
112127
it('parses multiple files when file paths are in HTML-style comments outside of code blocks', () => {
113128
const test_case = 'html-comment-filename-outside-code-block'
114129
const text = load_test_case_file(test_case, `${test_case}.txt`)

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,39 @@ export const parse_multiple_files = (params: {
433433
const trimmed_line = line.trim()
434434
let extracted_filename: string | null = null
435435

436+
// Check for HTML comments embedded in markdown headings like: # <!-- file:/path -->
437+
if (trimmed_line.startsWith('#')) {
438+
const html_comment_match = trimmed_line.match(
439+
/<!--\s*(?:file:\/?)?(.*?)\s*-->/
440+
)
441+
if (html_comment_match) {
442+
const potential_path = html_comment_match[1].trim()
443+
if (
444+
potential_path.includes('/') ||
445+
potential_path.includes('\\') ||
446+
potential_path.includes('.')
447+
) {
448+
extracted_filename = potential_path
449+
}
450+
}
451+
}
452+
453+
if (extracted_filename) {
454+
const { workspace_name, relative_path } =
455+
extract_workspace_and_path(
456+
extracted_filename,
457+
params.is_single_root_folder_workspace
458+
)
459+
current_file_name = relative_path
460+
if (workspace_name) {
461+
current_workspace_name = workspace_name
462+
}
463+
464+
// Don't include the filename line in content
465+
is_first_content_line = false
466+
continue
467+
}
468+
436469
if (trimmed_line.startsWith('<?php')) {
437470
if (current_content) {
438471
current_content += '\n' + line
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Hello World!
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
```markdown
2+
# <!-- file:/README.md -->
3+
# Hello World!
4+
```

0 commit comments

Comments
 (0)