fix(import): emit extractor output as UTF-8 on Windows (#122)

* fix(import): emit extractor digests as UTF-8

* fix(import): limit UTF-8 setup to CLI entrypoints

* test(import): normalize cross-platform newline parity
This commit is contained in:
Cathryn Lavery
2026-08-19 17:49:34 -07:00
committed by GitHub
parent 8154ec97bf
commit cc2f51f3fd
7 changed files with 161 additions and 3 deletions
@@ -43,6 +43,13 @@ MAX_INPUT_BYTES = 32 * 1024 * 1024
MAX_XML_BYTES = 64 * 1024 * 1024
def _configure_stdout_utf8() -> None:
"""Emit digests as UTF-8 even when Windows selects a legacy codepage."""
reconfigure = getattr(sys.stdout, "reconfigure", None)
if reconfigure is not None:
reconfigure(encoding="utf-8", errors="strict")
class PayloadTooLarge(ValueError):
"""Raised when compressed metadata expands beyond the supported limit."""
@@ -886,4 +893,5 @@ def main(argv: list[str] | None = None) -> int:
if __name__ == "__main__":
_configure_stdout_utf8()
raise SystemExit(main())
@@ -51,6 +51,13 @@ MARKDOWN_SUFFIXES = {".md", ".markdown", ".mdown", ".mkd"}
MERMAID_SUFFIXES = {".mmd", ".mermaid"}
def _configure_stdout_utf8() -> None:
"""Emit digests as UTF-8 even when Windows selects a legacy codepage."""
reconfigure = getattr(sys.stdout, "reconfigure", None)
if reconfigure is not None:
reconfigure(encoding="utf-8", errors="strict")
def _fail(message: str) -> NoReturn:
print(f"mermaid_extract: {message}", file=sys.stderr)
raise SystemExit(2)
@@ -1322,4 +1329,5 @@ def main(argv: list[str] | None = None) -> int:
if __name__ == "__main__":
_configure_stdout_utf8()
raise SystemExit(main())