From e076f651e74b2744aaa85b3c8b9466c7268af982 Mon Sep 17 00:00:00 2001 From: Yurii Motov Date: Tue, 6 Jan 2026 06:03:38 +0100 Subject: [PATCH] Increase verbosity of `replace_multiline_code_block` and `replace_multiline_code_blocks_in_text` --- scripts/doc_parsing_utils.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/scripts/doc_parsing_utils.py b/scripts/doc_parsing_utils.py index 4c35634a3e..773ec9de65 100644 --- a/scripts/doc_parsing_utils.py +++ b/scripts/doc_parsing_utils.py @@ -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()