Improve documentation and modernize type hints
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user