spectre_pdf 1.0.0

Native Rust PDF extraction engine: text, markdown for RAG, AcroForm widgets, image decoding, and encrypted PDFs. Lazy parser, persistent Document handle, no C dependencies.
Documentation
"""
Re-normalize comment indentation.

The earlier cleanup scripts produced lines like ` /// foo` (single leading
space) where they should be `    /// foo` (4-space block indent matching
the surrounding code). This pass fixes the indent so rustfmt-compatible
output is restored.

Algorithm: a comment line ` ///` or ` //` with a single leading space
is interpreted as wanting to live inside an indented block. Look at the
*next non-blank line* to determine the actual block indent, and reset
the comment's leading whitespace to match.
"""

from __future__ import annotations

import re
from pathlib import Path

ROOT = Path("/mnt/c/Users/RyanJ/spectre-rs")
TARGETS = [
    *(ROOT / "src").glob("*.rs"),
    *(ROOT / "crates/spectre-parse/src").glob("*.rs"),
]


def normalize(text: str) -> str:
    lines = text.splitlines(keepends=True)
    out: list[str] = []
    for i, line in enumerate(lines):
        # Match lines with exactly one leading space followed by // (doc or regular)
        m = re.match(r"^( )(//[/!]?[ ]?)(.*)$", line)
        if not m:
            out.append(line)
            continue
        _, marker, rest = m.groups()
        # Find indent of the next non-blank, non-comment line
        target_indent = ""
        for j in range(i + 1, len(lines)):
            nxt = lines[j].rstrip("\n")
            if not nxt.strip():
                continue
            # Use this line's indent
            nxt_indent = re.match(r"^(\s*)", nxt).group(1)
            target_indent = nxt_indent
            break
        new = target_indent + marker + rest
        if not new.endswith("\n"):
            new += "\n"
        out.append(new)
    return "".join(out)


for path in TARGETS:
    if "target/" in str(path):
        continue
    original = path.read_text(encoding="utf-8")
    fixed = normalize(original)
    if fixed != original:
        path.write_text(fixed, encoding="utf-8")
        print(f"  re-indented {path.relative_to(ROOT)}")