mirror of
https://github.com/Textualize/rich.git
synced 2025-07-07 21:04:58 +00:00
added --page argument to markdown
This commit is contained in:
parent
7e61cd2fbc
commit
672f794dd4
5 changed files with 36 additions and 9 deletions
|
@ -5,9 +5,15 @@ All notable changes to this project will be documented in this file.
|
||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [1.1.2] - Unreleased
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Added -p switch to python -m rich.markdown to page output
|
||||||
|
|
||||||
## [1.1.1] - 2020-05-12
|
## [1.1.1] - 2020-05-12
|
||||||
|
|
||||||
## Changed
|
### Changed
|
||||||
|
|
||||||
- Stripped cursor moving control codes from text
|
- Stripped cursor moving control codes from text
|
||||||
|
|
||||||
|
|
|
@ -521,6 +521,8 @@ class Console:
|
||||||
Args:
|
Args:
|
||||||
renderables (Iterable[RenderableType]): Any object or objects renderable in the console.
|
renderables (Iterable[RenderableType]): Any object or objects renderable in the console.
|
||||||
options (Optional[ConsoleOptions]): Console options used to render with.
|
options (Optional[ConsoleOptions]): Console options used to render with.
|
||||||
|
style (Style, optional): Optional style to apply to renderables. Defaults to ``None``.
|
||||||
|
pad (bool, optional): Pad lines shorter than render width. Defaults to ``True``.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
List[List[Segment]]: A list of lines, where a line is a list of Segment objects.
|
List[List[Segment]]: A list of lines, where a line is a list of Segment objects.
|
||||||
|
@ -549,7 +551,8 @@ class Console:
|
||||||
markup: bool = None,
|
markup: bool = None,
|
||||||
highlighter: HighlighterType = None,
|
highlighter: HighlighterType = None,
|
||||||
) -> "Text":
|
) -> "Text":
|
||||||
"""Convert a string to a Text instance.
|
"""Convert a string to a Text instance. This is is called automatically if
|
||||||
|
you print or log a string.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
text (str): Text to render.
|
text (str): Text to render.
|
||||||
|
@ -581,7 +584,7 @@ class Console:
|
||||||
def get_style(
|
def get_style(
|
||||||
self, name: Union[str, Style], *, default: Union[Style, str] = None
|
self, name: Union[str, Style], *, default: Union[Style, str] = None
|
||||||
) -> Style:
|
) -> Style:
|
||||||
"""Get a style merged with the current style.
|
"""Get a Style instance by it's theme name or parse a definition.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
name (str): The name of a style or a style definition.
|
name (str): The name of a style or a style definition.
|
||||||
|
@ -598,7 +601,7 @@ class Console:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
style = self._styles.get(name)
|
style = self._styles.get(name)
|
||||||
return style.copy() if style is not None else Style.parse(name)
|
return style.copy() if style is not None else Style.parse(name)
|
||||||
except errors.StyleSyntaxError as error:
|
except errors.StyleSyntaxError as error:
|
||||||
if default is not None:
|
if default is not None:
|
||||||
return self.get_style(default)
|
return self.get_style(default)
|
||||||
|
|
|
@ -153,7 +153,7 @@ class Heading(TextElement):
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# Styled text for h2 and beyond
|
# Styled text for h2 and beyond
|
||||||
if self.level:
|
if self.level == 2:
|
||||||
yield Text("\n")
|
yield Text("\n")
|
||||||
yield text
|
yield text
|
||||||
|
|
||||||
|
@ -525,11 +525,17 @@ if __name__ == "__main__": # pragma: no cover
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="enable full text justify",
|
help="enable full text justify",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-p",
|
||||||
|
"--page",
|
||||||
|
dest="page",
|
||||||
|
action="store_true",
|
||||||
|
help="use pager to scroll output",
|
||||||
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
|
|
||||||
console = Console(force_terminal=args.force_color, width=args.width)
|
|
||||||
with open(args.path, "rt") as markdown_file:
|
with open(args.path, "rt") as markdown_file:
|
||||||
markdown = Markdown(
|
markdown = Markdown(
|
||||||
markdown_file.read(),
|
markdown_file.read(),
|
||||||
|
@ -537,4 +543,16 @@ if __name__ == "__main__": # pragma: no cover
|
||||||
code_theme=args.code_theme,
|
code_theme=args.code_theme,
|
||||||
hyperlinks=args.hyperlinks,
|
hyperlinks=args.hyperlinks,
|
||||||
)
|
)
|
||||||
console.print(markdown)
|
if args.page:
|
||||||
|
import pydoc
|
||||||
|
import io
|
||||||
|
|
||||||
|
console = Console(
|
||||||
|
file=io.StringIO(), force_terminal=args.force_color, width=args.width
|
||||||
|
)
|
||||||
|
console.print(markdown)
|
||||||
|
pydoc.pager(console.file.getvalue()) # type: ignore
|
||||||
|
|
||||||
|
else:
|
||||||
|
console = Console(force_terminal=args.force_color, width=args.width)
|
||||||
|
console.print(markdown)
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -5,4 +5,4 @@
|
||||||
import setuptools
|
import setuptools
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
setuptools.setup()
|
setuptools.setup(name="rich")
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue