richless 0.2.2__tar.gz → 0.2.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {richless-0.2.2 → richless-0.2.3}/PKG-INFO +1 -1
- {richless-0.2.2 → richless-0.2.3}/pyproject.toml +4 -1
- {richless-0.2.2 → richless-0.2.3}/richless-init.sh +5 -2
- {richless-0.2.2 → richless-0.2.3}/richless.py +25 -2
- {richless-0.2.2 → richless-0.2.3}/.gitignore +0 -0
- {richless-0.2.2 → richless-0.2.3}/LICENSE +0 -0
- {richless-0.2.2 → richless-0.2.3}/README.md +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "richless"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.3"
|
|
4
4
|
description = "LESSOPEN filter for Markdown rendering and syntax highlighting with less"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.12"
|
|
@@ -21,5 +21,8 @@ richless = "richless:main"
|
|
|
21
21
|
requires = ["hatchling"]
|
|
22
22
|
build-backend = "hatchling.build"
|
|
23
23
|
|
|
24
|
+
[tool.pytest.ini_options]
|
|
25
|
+
testpaths = ["tests"]
|
|
26
|
+
|
|
24
27
|
[tool.hatch.build.targets.sdist]
|
|
25
28
|
include = ["richless.py", "richless-init.sh", "LICENSE", "README.md"]
|
|
@@ -66,10 +66,13 @@ less() {
|
|
|
66
66
|
# Looks like YAML with comments - use syntax highlighting
|
|
67
67
|
richless "$tmpfile" | command less -R ${clean_args}
|
|
68
68
|
# Auto-detect: check if piped content looks like markdown
|
|
69
|
-
|
|
69
|
+
# Use stricter patterns to avoid false positives (e.g., TOML comments matching ^# )
|
|
70
|
+
elif grep -qE '^\* |^- |^[0-9]+\. |^\[.*\]\(.*\)|^```|\*\*.*\*\*|^>|^\||^-{3,}|^={3,}' "$tmpfile" 2>/dev/null && \
|
|
71
|
+
grep -qE '^#{1,6} ' "$tmpfile" 2>/dev/null; then
|
|
70
72
|
richless --md "$tmpfile" | command less -R ${clean_args}
|
|
71
73
|
else
|
|
72
|
-
|
|
74
|
+
# Fall through to richless for content-based syntax detection
|
|
75
|
+
richless "$tmpfile" | command less -R ${clean_args}
|
|
73
76
|
fi
|
|
74
77
|
fi
|
|
75
78
|
|
|
@@ -37,7 +37,10 @@ def detect_syntax_from_content(content: str) -> str:
|
|
|
37
37
|
return "yaml"
|
|
38
38
|
|
|
39
39
|
# JSON detection: starts with { or [
|
|
40
|
-
|
|
40
|
+
# But exclude TOML section headers like [section] or [[array]]
|
|
41
|
+
if first_line.startswith('{'):
|
|
42
|
+
return "json"
|
|
43
|
+
if first_line.startswith('[') and not re.match(r'^\[{1,2}[a-zA-Z_][a-zA-Z0-9_.-]*\]{1,2}\s*$', first_line):
|
|
41
44
|
return "json"
|
|
42
45
|
|
|
43
46
|
# Shebang detection
|
|
@@ -57,6 +60,26 @@ def detect_syntax_from_content(content: str) -> str:
|
|
|
57
60
|
if first_line.startswith('<?xml') or first_line.startswith('<!DOCTYPE'):
|
|
58
61
|
return "xml"
|
|
59
62
|
|
|
63
|
+
# TOML detection: look for key = value patterns or [section] headers
|
|
64
|
+
toml_score = 0
|
|
65
|
+
for line in lines:
|
|
66
|
+
stripped = line.strip()
|
|
67
|
+
if not stripped or stripped.startswith('#'):
|
|
68
|
+
continue
|
|
69
|
+
# TOML section header: [section] or [[array]]
|
|
70
|
+
if re.match(r'^\[{1,2}[a-zA-Z_][a-zA-Z0-9_.-]*\]{1,2}\s*$', stripped):
|
|
71
|
+
return "toml"
|
|
72
|
+
# TOML key = value (with equals sign, not colon)
|
|
73
|
+
if re.match(r'^[a-zA-Z_][a-zA-Z0-9_-]*\s*=\s*', stripped):
|
|
74
|
+
toml_score += 1
|
|
75
|
+
if toml_score >= 2:
|
|
76
|
+
return "toml"
|
|
77
|
+
continue
|
|
78
|
+
break
|
|
79
|
+
|
|
80
|
+
if toml_score > 0:
|
|
81
|
+
return "toml"
|
|
82
|
+
|
|
60
83
|
# YAML detection: look for key: value patterns (possibly after # comments)
|
|
61
84
|
# Skip comment lines and look for YAML structure
|
|
62
85
|
for line in lines:
|
|
@@ -107,7 +130,7 @@ def render_syntax(filepath: str, content: str) -> None:
|
|
|
107
130
|
|
|
108
131
|
# If no recognizable extension, try to detect from content
|
|
109
132
|
# Temp files from shell wrapper are named richless.XXXXXX (random suffix)
|
|
110
|
-
if not ext or path.stem == 'richless':
|
|
133
|
+
if not ext or (path.stem == 'richless' and re.match(r'^\.[a-zA-Z0-9]{6}$', path.suffix)):
|
|
111
134
|
ext = detect_syntax_from_content(content)
|
|
112
135
|
elif ext:
|
|
113
136
|
# Verify Pygments recognizes this extension; if not, try content detection
|
|
File without changes
|
|
File without changes
|
|
File without changes
|