Improve documentation and modernize type hints

This commit is contained in:
2026-04-01 21:06:34 -07:00
parent 5935140620
commit 32a8a1d4ad
6 changed files with 82 additions and 16 deletions

View File

@@ -60,6 +60,23 @@ def detect_type(
content: str | None = None,
explicit_type: str | None = None,
) -> str:
"""Detect the file type for syntax highlighting.
Detection priority:
1. Explicit type if provided
2. Filename-based mapping (for example, Dockerfile)
3. Extension-based mapping
4. JSON if content starts with '{' or '[' and parses successfully
5. Fallback to 'text'
Args:
path: File path for filename and extension detection.
content: File content for JSON detection.
explicit_type: Override auto-detection with explicit type.
Returns:
Pygments lexer name for the detected file type.
"""
if explicit_type is not None:
return explicit_type