From 14ce1d43c78f678d5afea454415c52f9b7b5ac3e Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Thu, 13 Jul 2023 15:54:54 -0700 Subject: [PATCH] strip the correct fence --- aider/coders/editblock_coder.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/aider/coders/editblock_coder.py b/aider/coders/editblock_coder.py index 49ae63674..ee0ffa666 100644 --- a/aider/coders/editblock_coder.py +++ b/aider/coders/editblock_coder.py @@ -185,7 +185,7 @@ def replace_most_similar_chunk(whole, part, replace): return modified_whole -def strip_quoted_wrapping(res, fname=None): +def strip_quoted_wrapping(res, fname=None, fence=None): """ Given an input string which may have extra "wrapping" around it, remove the wrapping. For example: @@ -199,12 +199,15 @@ def strip_quoted_wrapping(res, fname=None): if not res: return res + if not fence: + fence = ("```", "```") + res = res.splitlines() if fname and res[0].strip().endswith(Path(fname).name): res = res[1:] - if res[0].startswith("```") and res[-1].startswith("```"): + if res[0].startswith(fence[0]) and res[-1].startswith(fence[1]): res = res[1:-1] res = "\n".join(res) @@ -214,9 +217,9 @@ def strip_quoted_wrapping(res, fname=None): return res -def do_replace(fname, content, before_text, after_text): - before_text = strip_quoted_wrapping(before_text, fname) - after_text = strip_quoted_wrapping(after_text, fname) +def do_replace(fname, content, before_text, after_text, fence=None): + before_text = strip_quoted_wrapping(before_text, fname, fence) + after_text = strip_quoted_wrapping(after_text, fname, fence) fname = Path(fname) # does it want to make a new file?