Skip to content

Commit b2de0c5

Browse files
committed
Updating codeblock logic
Changed the "findall" command to "search" in the extract_from_file function. This resolves a bug where multiple codeblocks were concatinated into a single file if there were multiple codeblocks after the trigger string.
1 parent cc9b581 commit b2de0c5

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

extract_cli.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def increase_indent(self, flow=False, indentless=False):
2020

2121
def extract_from_file(file_path, trigger_string):
2222
"""
23-
Helper function to read a file and extract code blocks after the trigger.
24-
Returns a list of code blocks (strings) or None if no trigger found.
23+
Helper function to read a file and extract the first code block after the trigger.
24+
Returns a list containing the first code block (string) or None if no trigger found.
2525
"""
2626
try:
2727
with open(file_path, "r", encoding="utf-8") as f:
@@ -33,9 +33,9 @@ def extract_from_file(file_path, trigger_string):
3333

3434
# Regex for code blocks
3535
code_block_pattern = re.compile(r"```(?:\w+)?\n(.*?)```", re.DOTALL)
36-
matches = code_block_pattern.findall(relevant_content)
36+
match = code_block_pattern.search(relevant_content)
3737

38-
return [m.strip() for m in matches] if matches else []
38+
return [match.group(1).strip()] if match else []
3939
return None
4040
except Exception as e:
4141
print(f"Error reading {file_path}: {e}")

0 commit comments

Comments
 (0)