diff --git a/src/rp/cli.py b/src/rp/cli.py index 318dfe1..844d70b 100644 --- a/src/rp/cli.py +++ b/src/rp/cli.py @@ -20,22 +20,6 @@ app = typer.Typer( rich_markup_mode="rich", ) -_THEMES = [ - "monokai", - "github-dark", - "one-dark", - "vim", - "vs", - "nord", - "dracula", - "solarized-dark", - "solarized-light", - "default", - "friendly", - "native", - "emacs", -] - def version_callback(value: bool) -> None: if value: diff --git a/src/rp/detect.py b/src/rp/detect.py index 19c2f50..ca5e811 100644 --- a/src/rp/detect.py +++ b/src/rp/detect.py @@ -73,10 +73,12 @@ def detect_type( return EXTENSION_MAP[suffix] if content is not None: - try: - json.loads(content[:1000]) - return "json" - except (json.JSONDecodeError, ValueError): - pass + stripped = content.lstrip() + if stripped and stripped[0] in ("{", "["): + try: + json.loads(stripped[:1000]) + return "json" + except (json.JSONDecodeError, ValueError): + pass return "text" diff --git a/src/rp/render.py b/src/rp/render.py index d4ae8f3..09e9aa8 100644 --- a/src/rp/render.py +++ b/src/rp/render.py @@ -44,9 +44,14 @@ def render( content, "json", theme=options.theme, line_numbers=line_numbers ) else: - renderable = Syntax( - content, file_type, theme=options.theme, line_numbers=line_numbers - ) + try: + renderable = Syntax( + content, file_type, theme=options.theme, line_numbers=line_numbers + ) + except Exception: + renderable = Syntax( + content, "text", theme=options.theme, line_numbers=line_numbers + ) if use_pager: with console.pager(styles=True):