Add script detection, env shebang parser, and opt-in content guessing
This commit is contained in:
10
AGENTS.md
10
AGENTS.md
@@ -24,6 +24,7 @@ uv run rp <file> # Rich-print a file
|
||||
uv run rp --help # Show help
|
||||
uv run rp --version # Show version
|
||||
echo '{"a":1}' | uv run rp # Read from stdin
|
||||
cat patch.txt | uv run rp --guess-content # Enable heuristic content guessing
|
||||
```
|
||||
|
||||
### Testing
|
||||
@@ -92,6 +93,7 @@ def detect_type(
|
||||
path: str | None = None,
|
||||
content: str | None = None,
|
||||
explicit_type: str | None = None,
|
||||
guess_content: bool = False,
|
||||
) -> str:
|
||||
...
|
||||
```
|
||||
@@ -152,6 +154,11 @@ When adding new file types:
|
||||
2. Use Pygments lexer name as the value
|
||||
3. For special filenames (e.g., `Dockerfile`), add to `_FILENAME_MAP`
|
||||
|
||||
Detection stays conservative by default: explicit type, filename map, extension map,
|
||||
shebang, and JSON detection all run before falling back to `text`. Heuristic
|
||||
Pygments content guessing is opt-in via `--guess-content` and should remain a
|
||||
late fallback.
|
||||
|
||||
### Rendering
|
||||
- `markdown` and `md` → use `rich.markdown.Markdown`
|
||||
- `json` → use `rich.json.JSON` with fallback to `Syntax`
|
||||
@@ -190,9 +197,10 @@ rich-print/
|
||||
## Dependencies
|
||||
|
||||
- `rich>=13.0` — Terminal rendering (Markdown, JSON, Syntax)
|
||||
- `pygments>=2.13.0` — Lexer detection and syntax lexers
|
||||
- `typer>=0.12` — CLI framework
|
||||
|
||||
Runtime dependencies. Dev dependencies: `ruff>=0.9`, `mypy>=1.14`, `pytest>=8.0`, `pytest-cov>=5.0`.
|
||||
Runtime dependencies. Dev dependencies: `ruff>=0.9`, `mypy>=1.14`, `pytest>=8.0`, `pytest-cov>=5.0`, `types-pygments>=2.19`.
|
||||
|
||||
## Git Workflow
|
||||
|
||||
|
||||
Reference in New Issue
Block a user