Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f32da588fb | |||
| 0e7f30d6c3 | |||
| 65ff34dd2c | |||
| 217feab7de |
@@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "rp"
|
||||
version = "0.2.1"
|
||||
version = "0.2.3"
|
||||
description = "Rich print files — markdown, JSON, code, and more — beautifully in your terminal"
|
||||
readme = "README.md"
|
||||
license = "MIT"
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
__version__ = "0.2.1"
|
||||
__version__ = "0.2.3"
|
||||
__author__ = "Yunxiao Xu"
|
||||
__license__ = "MIT"
|
||||
|
||||
@@ -90,10 +90,13 @@ def detect_type(
|
||||
return EXTENSION_MAP[suffix]
|
||||
|
||||
if content is not None:
|
||||
stripped = content.lstrip()
|
||||
if stripped and stripped[0] in ("{", "["):
|
||||
stripped = content.strip()
|
||||
if stripped and (
|
||||
(stripped[0] == "{" and stripped[-1] == "}")
|
||||
or (stripped[0] == "[" and stripped[-1] == "]")
|
||||
):
|
||||
try:
|
||||
json.loads(stripped[:1000])
|
||||
json.loads(stripped)
|
||||
return "json"
|
||||
except (json.JSONDecodeError, ValueError):
|
||||
pass
|
||||
|
||||
@@ -7,6 +7,7 @@ from dataclasses import dataclass
|
||||
from rich.console import Console, RenderableType
|
||||
from rich.json import JSON as RichJSON
|
||||
from rich.markdown import Markdown
|
||||
from rich.padding import Padding
|
||||
from rich.syntax import Syntax
|
||||
|
||||
from rp.pager import MousePager
|
||||
@@ -75,8 +76,10 @@ def render(
|
||||
content, "text", theme=options.theme, line_numbers=line_numbers
|
||||
)
|
||||
|
||||
padded = Padding(renderable, (1, 2))
|
||||
|
||||
if use_pager:
|
||||
with console.pager(pager=MousePager(), styles=True):
|
||||
console.print(renderable)
|
||||
console.print(padded)
|
||||
else:
|
||||
console.print(renderable)
|
||||
console.print(padded)
|
||||
|
||||
Reference in New Issue
Block a user