fix: Expand code block detection to support various Windows shells

This commit is contained in:
Paul Gauthier (aider) 2024-08-20 13:28:10 -07:00
parent 3984716608
commit 7ebbb3d4f4

View file

@ -407,14 +407,16 @@ def find_original_update_blocks(content, fence=DEFAULT_FENCE):
while pieces: while pieces:
cur = pieces.pop() cur = pieces.pop()
# Check for ```bash blocks # Check for various shell code blocks
if cur.strip().startswith("```bash"): shell_starts = ["```bash", "```cmd", "```powershell", "```ps1", "```bat"]
bash_content = [] if any(cur.strip().startswith(start) for start in shell_starts):
shell_content = []
while pieces and not pieces[-1].strip().startswith("```"): while pieces and not pieces[-1].strip().startswith("```"):
bash_content.append(pieces.pop()) shell_content.append(pieces.pop())
if pieces and pieces[-1].strip().startswith("```"): if pieces and pieces[-1].strip().startswith("```"):
pieces.pop() # Remove the closing ``` pieces.pop() # Remove the closing ```
yield "bash_command", "".join(bash_content), "" shell_type = cur.strip().split("```")[1]
yield f"{shell_type}_command", "".join(shell_content), ""
continue continue
if cur in (DIVIDER, UPDATED): if cur in (DIVIDER, UPDATED):