Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

fix: ToC so it doesn’t include itself or duplicate the end marker (#4388)

wizard4a1a7f9685aa
diff --git a/scripts/readme_toc.py b/scripts/readme_toc.py
index b6ab0a6582..90fdc3ab71 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}.")