"""Shared language-guessing helpers for code fences and syntax highlighting."""
from __future__ import annotations
from pathlib import Path
LANGUAGE_MAPPING: dict[str, str] = {
".py": "python",
".js": "javascript",
".ts": "typescript",
".tsx": "tsx",
".jsx": "jsx",
".go": "go",
".rs": "rust",
".c": "c",
".cpp": "cpp",
".h": "c",
".java": "java",
".kt": "kotlin",
".sh": "bash",
".zsh": "bash",
".bash": "bash",
".md": "markdown",
".json": "json",
".yaml": "yaml",
".yml": "yaml",
".toml": "toml",
".html": "html",
".css": "css",
".scss": "scss",
".sql": "sql",
".dockerfile": "dockerfile",
".lock": "text",
".txt": "text",
".env": "bash",
}
def guess_language(path: Path | str) -> str:
"""Best-effort language tag for a file path or artifact name."""
name = str(path)
lower_name = name.lower()
for ext, lang in LANGUAGE_MAPPING.items():
if lower_name.endswith(ext):
return lang
return "text"