rich.markdown

class rich.markdown.BlockQuote[source]

A block quote.

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) –

classmethod create(markdown, token)[source]

Factory to create markdown element,

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

  • token (Token) – A node from markdown-it.

Returns

A new markdown element

Return type

MarkdownElement

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

A heading.

Parameters

tag (str) –

classmethod create(markdown, token)[source]

Factory to create markdown element,

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

  • token (Token) – A node from markdown-it.

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) –

classmethod create(markdown, token)[source]

Factory to create markdown element,

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

  • token (Any) – A token from markdown-it.

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

Parameters
  • text (str) –

  • href (str) –

classmethod create(markdown, token)[source]

Factory to create markdown element,

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

  • token (Token) – A node from markdown-it.

Returns

A new markdown element

Return type

MarkdownElement

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

A list element.

Parameters
  • list_type (str) –

  • list_start (int | None) –

classmethod create(markdown, token)[source]

Factory to create markdown element,

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

  • token (Token) – A node from markdown-it.

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.

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.

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

Manages the console render state.

Parameters
property current_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, Style]) –

Return type

Style

leave_style()[source]

Leave a style context.

Return type

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]) –

classmethod create(markdown, token)[source]

Factory to create markdown element,

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

  • token (Token) – A node from markdown-it.

Returns

A new markdown element

Return type

MarkdownElement

class rich.markdown.TableBodyElement[source]

MarkdownElement corresponding to tbody_open and tbody_close.

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.TableDataElement(justify)[source]

MarkdownElement corresponding to td_open and td_close and th_open and th_close.

Parameters

justify (JustifyMethod) –

classmethod create(markdown, token)[source]

Factory to create markdown element,

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

  • token (Token) – A node from markdown-it.

Returns

A new markdown element

Return type

MarkdownElement

on_text(context, text)[source]

Called when text is parsed.

Parameters
Return type

None

class rich.markdown.TableElement[source]

MarkdownElement corresponding to table_open.

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.TableHeaderElement[source]

MarkdownElement corresponding to thead_open and thead_close.

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.TableRowElement[source]

MarkdownElement corresponding to tr_open and tr_close.

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.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.