rich.markdown

class rich.markdown.BlockQuote[source]

A block quote.

Return type

None

on_child_close(context, child)[source]

Called when a child element is closed.

This method allows a parent element to take over rendering of its children.

Parameters
  • context (MarkdownContext) – The markdown context.

  • child (MarkdownElement) – The child markdown element.

Returns

Return True to render the element, or False to not render the element.

Return type

bool

class rich.markdown.CodeBlock(lexer_name, theme)[source]

A code block with syntax highlighting.

Parameters
  • lexer_name (str) –

  • theme (str) –

Return type

None

classmethod create(markdown, node)[source]

Factory to create markdown element,

Parameters
  • markdown (Markdown) – The parent Markdown object.

  • node (Any) – A node from Pygments.

Returns

A new markdown element

Return type

MarkdownElement

class rich.markdown.Heading(level)[source]

A heading.

Parameters

level (int) –

Return type

None

classmethod create(markdown, node)[source]

Factory to create markdown element,

Parameters
  • markdown (Markdown) – The parent Markdown object.

  • node (Any) – A node from Pygments.

Returns

A new markdown element

Return type

MarkdownElement

on_enter(context)[source]

Called when the node is entered.

Parameters

context (MarkdownContext) – The markdown context.

Return type

None

class rich.markdown.HorizontalRule[source]

A horizontal rule to divide sections.

class rich.markdown.ImageItem(destination, hyperlinks)[source]

Renders a placeholder for an image.

Parameters
  • destination (str) –

  • hyperlinks (bool) –

Return type

None

classmethod create(markdown, node)[source]

Factory to create markdown element,

Parameters
  • markdown (Markdown) – The parent Markdown object.

  • node (Any) – A node from Pygments.

Returns

A new markdown element

Return type

MarkdownElement

on_enter(context)[source]

Called when the node is entered.

Parameters

context (MarkdownContext) – The markdown context.

Return type

None

class rich.markdown.ListElement(list_type, list_start)[source]

A list element.

Parameters
Return type

None

classmethod create(markdown, node)[source]

Factory to create markdown element,

Parameters
  • markdown (Markdown) – The parent Markdown object.

  • node (Any) – A node from Pygments.

Returns

A new markdown element

Return type

MarkdownElement

on_child_close(context, child)[source]

Called when a child element is closed.

This method allows a parent element to take over rendering of its children.

Parameters
  • context (MarkdownContext) – The markdown context.

  • child (MarkdownElement) – The child markdown element.

Returns

Return True to render the element, or False to not render the element.

Return type

bool

class rich.markdown.ListItem[source]

An item in a list.

Return type

None

on_child_close(context, child)[source]

Called when a child element is closed.

This method allows a parent element to take over rendering of its children.

Parameters
  • context (MarkdownContext) – The markdown context.

  • child (MarkdownElement) – The child markdown element.

Returns

Return True to render the element, or False to not render the element.

Return type

bool

class rich.markdown.Markdown(markup, code_theme='monokai', justify=None, style='none', hyperlinks=True, inline_code_lexer=None, inline_code_theme=None)[source]

A Markdown renderable.

Parameters
  • markup (str) – A string containing markdown.

  • code_theme (str, optional) – Pygments theme for code blocks. Defaults to “monokai”.

  • justify (JustifyMethod, optional) – Justify value for paragraphs. Defaults to None.

  • style (Union[str, Style], optional) – Optional style to apply to markdown.

  • hyperlinks (bool, optional) – Enable hyperlinks. Defaults to True.

  • inline_code_lexer (Optional[str]) – (str, optional): Lexer to use if inline code highlighting is enabled. Defaults to None.

  • inline_code_theme (Optional[str]) – (Optional[str], optional): Pygments theme for inline code highlighting, or None for no highlighting. Defaults to None.

Return type

None

class rich.markdown.MarkdownContext(console, options, style, inline_code_lexer=None, inline_code_theme='monokai')[source]

Manages the console render state.

Parameters
Return type

None

property current_style: rich.style.Style

Current style which is the product of all styles on the stack.

enter_style(style_name)[source]

Enter a style context.

Parameters

style_name (Union[str, rich.style.Style]) –

Return type

rich.style.Style

leave_style()[source]

Leave a style context.

Return type

rich.style.Style

on_text(text, node_type)[source]

Called when the parser visits text.

Parameters
  • text (str) –

  • node_type (str) –

Return type

None

class rich.markdown.Paragraph(justify)[source]

A Paragraph.

Parameters

justify (typing_extensions.Literal[default, left, center, right, full]) –

Return type

None

classmethod create(markdown, node)[source]

Factory to create markdown element,

Parameters
  • markdown (Markdown) – The parent Markdown object.

  • node (Any) – A node from Pygments.

Returns

A new markdown element

Return type

MarkdownElement

class rich.markdown.TextElement[source]

Base class for elements that render text.

on_enter(context)[source]

Called when the node is entered.

Parameters

context (MarkdownContext) – The markdown context.

Return type

None

on_leave(context)[source]

Called when the parser leaves the element.

Parameters

context (MarkdownContext) – [description]

Return type

None

on_text(context, text)[source]

Called when text is parsed.

Parameters
Return type

None

class rich.markdown.UnknownElement[source]

An unknown element.

Hopefully there will be no unknown elements, and we will have a MarkdownElement for everything in the document.