rich/docs/source/markup.rst

40 lines
1.5 KiB
ReStructuredText
Raw Normal View History

2019-12-29 18:03:42 +00:00
Console Markup
==============
Rich supports a simple markup which you can use to insert color and styles virtually everywhere Rich would accept a string (e.g. :meth:`~rich.console.Console.print` and :meth:`~rich.console.Console.log`).
Formatting
----------
for bold, italic, and strikethrough, Rich uses the same convention as Markdown::
For italics, wrap text in asterisks or underscores. e.g. ``*this is italics*`` or ``_this is also italics_``.
2019-12-30 13:29:25 +00:00
For bold, wrap the text in *two* asterisks or underscores. e.g. ``**this is bold**`` or ``__this is also bold__``.
2019-12-29 18:03:42 +00:00
For strikethrough, wrap the text in tildes. e.g. ``~this has a line through it~``.
For code, wrap the text in backticks. e.g. ```import this```
Styles
------
2019-12-30 13:29:25 +00:00
For other styles and color, you can use a syntax similar to bbcode. If you write the style (see :ref:`styles`) in square brackets, i.e. ``[bold red]``, that style will apply until it is *closed* with a corrensponding ``[/bold red]``.
2019-12-29 18:03:42 +00:00
Here's a simple example::
from rich import print
print("Hello, **World**!")
print("[bold red]alert![/bold red] *Something happened*")
2019-12-30 13:29:25 +00:00
If you don't close a style, it will apply until the end of the string. Which is sometimes convenient if you want to style a single line. For example::
print("[bold italic yellow on red blink]This text is impossible to read")
There is a shorthand for closing a style. If you omit the style name from the closing tag, Rich will close the last style. For example::
print("[bold red]Bold and red[/] not bold or red")