From 4a1a7f9685aa311ec8652f1fa1d13e85fb95036b Mon Sep 17 00:00:00 2001 From: wizard <112275929+famouswizard@users.noreply.github.com> Date: Thu, 6 Nov 2025 01:52:51 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20ToC=20so=20it=20doesn=E2=80=99t=20includ?= =?UTF-8?q?e=20itself=20or=20duplicate=20the=20end=20marker=20(#4388)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit turns out the ToC was including itself when generating, which messed up comparisons and sometimes made the file rewrite endlessly. also fixed the slice so `` doesn’t get duplicated when we insert the new ToC. should behave nicely now - no extra rewrites, no doubled markers. Co-authored-by: Eric Traut --- scripts/readme_toc.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/readme_toc.py b/scripts/readme_toc.py index b6ab0a65..90fdc3ab 100755 --- a/scripts/readme_toc.py +++ b/scripts/readme_toc.py @@ -87,8 +87,9 @@ def check_or_fix(readme_path: Path, fix: bool) -> int: # extract current ToC list items current_block = lines[begin_idx + 1 : end_idx] current = [l for l in current_block if l.lstrip().startswith("- [")] - # generate expected ToC - expected = generate_toc_lines(content) + # generate expected ToC from content without current ToC + toc_content = lines[:begin_idx] + lines[end_idx+1:] + expected = generate_toc_lines("\n".join(toc_content)) if current == expected: return 0 if not fix: @@ -108,7 +109,7 @@ def check_or_fix(readme_path: Path, fix: bool) -> int: return 1 # rebuild file with updated ToC prefix = lines[: begin_idx + 1] - suffix = lines[end_idx:] + suffix = lines[end_idx+1:] new_lines = prefix + [""] + expected + [""] + suffix readme_path.write_text("\n".join(new_lines) + "\n", encoding="utf-8") print(f"Updated ToC in {readme_path}.")