|
|
|
@ -579,12 +579,19 @@ def replace_multiline_code_block( |
|
|
|
""" |
|
|
|
|
|
|
|
if block_a["lang"] != block_b["lang"]: |
|
|
|
raise ValueError("Code blocks have different languages") |
|
|
|
raise ValueError( |
|
|
|
"Code block has different language than the original block " |
|
|
|
f"({block_a['lang']} vs {block_b['lang']})" |
|
|
|
) |
|
|
|
if len(block_a["content"]) != len(block_b["content"]): |
|
|
|
raise ValueError("Code blocks have different number of lines") |
|
|
|
raise ValueError( |
|
|
|
"Code block has different number of lines than the original block " |
|
|
|
f"({len(block_a['content'])} vs {len(block_b['content'])})" |
|
|
|
) |
|
|
|
|
|
|
|
block_language = block_a["lang"].lower() |
|
|
|
if block_language in {"mermaid"}: |
|
|
|
print("Skipping mermaid code block replacement. This should be checked manually.") |
|
|
|
return block_a["content"].copy() # We don't handle mermaid code blocks for now |
|
|
|
|
|
|
|
code_block: list[str] = [] |
|
|
|
@ -607,19 +614,17 @@ def replace_multiline_code_block( |
|
|
|
"hash-style-comments", |
|
|
|
}: |
|
|
|
_line_a_code, line_a_comment = _split_hash_comment(line_a) |
|
|
|
line_b_code, line_b_comment = _split_hash_comment(line_b) |
|
|
|
_line_b_code, line_b_comment = _split_hash_comment(line_b) |
|
|
|
res_line = line_b |
|
|
|
if line_b_comment: |
|
|
|
res_line = res_line.replace(line_b_comment, line_a_comment, 1) |
|
|
|
code_block.append(res_line) |
|
|
|
elif block_language in {"console", "json", "slash-style-comments"}: |
|
|
|
_line_a_code, line_a_comment = _split_slashes_comment(line_a) |
|
|
|
line_b_code, line_b_comment = _split_slashes_comment(line_b) |
|
|
|
_line_b_code, line_b_comment = _split_slashes_comment(line_b) |
|
|
|
res_line = line_b |
|
|
|
if line_b_comment: |
|
|
|
# print(f"Replacing comment: {line_b_comment} with {line_a_comment}") |
|
|
|
res_line = res_line.replace(line_b_comment, line_a_comment, 1) |
|
|
|
# print(f"Resulting line: {res_line}") |
|
|
|
code_block.append(res_line) |
|
|
|
else: |
|
|
|
code_block.append(line_b) |
|
|
|
@ -641,7 +646,8 @@ def replace_multiline_code_blocks_in_text( |
|
|
|
|
|
|
|
if len(code_blocks) != len(original_code_blocks): |
|
|
|
raise ValueError( |
|
|
|
"Number of code blocks does not match the number of original code blocks" |
|
|
|
"Number of code blocks does not match the number of original code blocks " |
|
|
|
f"({len(code_blocks)} vs {len(original_code_blocks)})" |
|
|
|
) |
|
|
|
|
|
|
|
modified_text = text.copy() |
|
|
|
|