Skip to main content

Module prettify

Module prettify 

Source
Expand description

Content-type detection and pretty-printing for structured data.

Used by --prettify and --content-type to lay out JSON, YAML, TOML, XML, HTML, and CSV inputs in a readable form. The transformation runs once at startup (or on toggle) and produces a fresh byte buffer that the line index treats as the new source content. No syntax highlighting / color — layout only — so search and filter stay byte-clean.

Enums§

PrettifyMode
ResolvedType
Result of resolving the user’s content-type intent against the available signals (explicit flag → extension → byte sniff → raw fallback).

Functions§

detect_from_bytes
Detect from leading bytes. Returns None if nothing matches. Cheap; inspects up to ~512 bytes.
detect_from_path
Detect from filename extension. Returns None if nothing matches.
parse_content_type
Parse a --content-type=NAME value. Case-insensitive. auto returns None (caller should run detection); raw maps to Off.
prettify
Run the transform for mode over input. Off returns the input verbatim (still allocates — callers can short-circuit if they care). On parse failure, returns the error string for the status line.
resolve
Combined resolver: explicit override (already parsed) → path extension → byte sniff → undetected.