from __future__ import annotations
import re
from pathlib import Path
ROOT = Path("/mnt/c/Users/RyanJ/spectre-rs")
TARGETS = [
ROOT / "src/python.rs",
ROOT / "src/document.rs",
ROOT / "src/lib.rs",
ROOT / "src/positioned.rs",
ROOT / "src/structure.rs",
ROOT / "src/search.rs",
ROOT / "src/geom.rs",
ROOT / "src/tables.rs",
ROOT / "src/meta.rs",
ROOT / "crates/spectre-parse/src/cmap.rs",
ROOT / "crates/spectre-parse/src/content.rs",
ROOT / "crates/spectre-parse/src/document.rs",
ROOT / "crates/spectre-parse/src/encoding.rs",
ROOT / "crates/spectre-parse/src/error.rs",
ROOT / "crates/spectre-parse/src/filter.rs",
ROOT / "crates/spectre-parse/src/lib.rs",
ROOT / "crates/spectre-parse/src/object.rs",
ROOT / "crates/spectre-parse/src/parser.rs",
]
FIXES = [
(r"`the markdown renderer/helpers/the standard parser_rag\.py`", "the markdown renderer source"),
(r"`the standard parser_rag\.py`", "upstream"),
(r"\(the standard parser_rag\.py around line \d+\)", ""),
(r"Pythe reference parser-compatible", "pymupdf-compatible"),
(r"Pythe reference parser", "pymupdf"),
(r"Pmu's the reference parser", "the standard parser"),
(r"extract form fields shape,", ""),
(r"extract form fields shape", ""),
(r"the document handle parity surface", "the PDF parity surface"),
(r"the document handle compatibility:", "Compatibility:"),
(r"Matches the document handle shape; ", ""),
(r"Matches the document handle\.", ""),
(r"matches the document handle\b", "follows the standard text-search behavior"),
(r"flags=the document handle", "flags=0"),
(r"the markdown renderer-compatible", "pymupdf4llm-compatible"),
(r"the markdown renderer's", "pymupdf4llm's"),
(r"the markdown renderer", "pymupdf4llm"),
(r"`the standard parser`", "`pymupdf`"),
(r"the standard parser's", "pymupdf's"),
(r"the standard parser", "pymupdf"),
(r"`the reference parser`", "`MuPDF`"),
(r"the reference parser's", "MuPDF's"),
(r"the reference parser", "MuPDF"),
(r"`the legacy parser`", "`lopdf`"),
(r"the legacy parser's", "lopdf's"),
(r"the legacy parser\b", "lopdf"),
(r" +", " "),
(r" — \.", "."),
(r"\s+\n", "\n"),
]
def is_comment_line(line: str) -> bool:
return line.lstrip().startswith("//")
def main() -> None:
for path in TARGETS:
if not path.exists():
continue
original = path.read_text(encoding="utf-8")
new_lines = []
for line in original.splitlines(keepends=True):
if is_comment_line(line):
fixed = line
for pat, repl in FIXES:
fixed = re.sub(pat, repl, fixed)
new_lines.append(fixed)
else:
new_lines.append(line)
new_content = "".join(new_lines)
if new_content != original:
path.write_text(new_content, encoding="utf-8")
print(f" fixed {path.relative_to(ROOT)}")
if __name__ == "__main__":
main()