2 Commits

3 changed files with 8 additions and 5 deletions

View File

@@ -1,6 +1,6 @@
[project] [project]
name = "rp" name = "rp"
version = "0.2.1" version = "0.2.2"
description = "Rich print files — markdown, JSON, code, and more — beautifully in your terminal" description = "Rich print files — markdown, JSON, code, and more — beautifully in your terminal"
readme = "README.md" readme = "README.md"
license = "MIT" license = "MIT"

View File

@@ -2,6 +2,6 @@
from __future__ import annotations from __future__ import annotations
__version__ = "0.2.1" __version__ = "0.2.2"
__author__ = "Yunxiao Xu" __author__ = "Yunxiao Xu"
__license__ = "MIT" __license__ = "MIT"

View File

@@ -90,10 +90,13 @@ def detect_type(
return EXTENSION_MAP[suffix] return EXTENSION_MAP[suffix]
if content is not None: if content is not None:
stripped = content.lstrip() stripped = content.strip()
if stripped and stripped[0] in ("{", "["): if stripped and (
(stripped[0] == "{" and stripped[-1] == "}")
or (stripped[0] == "[" and stripped[-1] == "]")
):
try: try:
json.loads(stripped[:1000]) json.loads(stripped)
return "json" return "json"
except (json.JSONDecodeError, ValueError): except (json.JSONDecodeError, ValueError):
pass pass