ClassSource
BBCodeRenderer(configs: BBCodeConfig | None = None)
The BBCode renderer.
Render the structured Document or an intemediate Node into the BBCode format.
Arguments
Requires
| Name | Type | Required | Description |
|---|
configs | BBCodeConfig | None | | The configurations used for customizing the BBCode tags. If not specified, will use BBCodeConfig() by default. |
Methods
render
v_1: str = self.render(node: Node | Document)
Render the BBCode.
Main dispatcher. Uses node.type directly so type checkers can narrow the union correctly.
Requires
| Name | Type | Required | Description |
|---|
node | Node | Document | | The node or the document that would be rendered as BBCode. |
Returns
| Name | Type | Description |
|---|
v_1 | str | The rendered BBCode text. |
render_alert
v_1: str = self.render_alert(node: AlertNode)
Specific renderring. Render the alert block.
Requires
| Name | Type | Required | Description |
|---|
node | AlertNode | | The alert block to be rendered. |
Returns
| Name | Type | Description |
|---|
v_1 | str | The rendered alert block bbcode. |
render_children
v_1: str = self.render_children(children: list[Node])
Helper method. Render a list of children nodes into BBCode.
Requires
| Name | Type | Required | Description |
|---|
children | list[Node] | | The children to be rendered. |
Returns
| Name | Type | Description |
|---|
v_1 | str | The rendered children bbcode. |
render_code_block
v_1: str = self.render_code_block(node: CodeBlockNode)
Specific renderring. Render the block code as
Requires
| Name | Type | Required | Description |
|---|
node | CodeBlockNode | | The code block to be rendered. |
Returns
| Name | Type | Description |
|---|
v_1 | str | The rendered code block. |
render_document
v_1: str = self.render_document(doc: Document)
Specific renderring. Render the whole document.
Requires
| Name | Type | Required | Description |
|---|
doc | Document | | The document to be rendered. |
Returns
| Name | Type | Description |
|---|
v_1 | str | The rendered document. |
render_heading
v_1: str = self.render_heading(node: HeadingNode)
Specific renderring. Render the heading (title).
Requires
| Name | Type | Required | Description |
|---|
node | HeadingNode | | The heading/title to be rendered. |
Returns
| Name | Type | Description |
|---|
v_1 | str | The rendered title bbcode. |
render_inline_code
v_1: str = self.render_inline_code(node: InlineCodeNode)
Specific renderring. Render the inline code.
Requires
| Name | Type | Required | Description |
|---|
node | InlineCodeNode | | The inline code to be rendered. |
Returns
| Name | Type | Description |
|---|
v_1 | str | The rendered inline code bbcode. |
render_link
v_1: str = self.render_link(node: LinkNode)
Specific renderring. Render the url (link).
Note that there is an exception. If href is the same as text, will render the plain text directly.
Requires
| Name | Type | Required | Description |
|---|
node | LinkNode | | The link/url to be rendered. |
Returns
| Name | Type | Description |
|---|
v_1 | str | The rendered url bbcode. |
render_list
v_1: str = self.render_list(node: ListNode)
Specific rendering. Render the ordered or unordered list.
Requires
| Name | Type | Required | Description |
|---|
node | ListNode | | The list to be rendered. |
Returns
| Name | Type | Description |
|---|
v_1 | str | The rendered list bbcode. |
render_list_item
v_1: str = self.render_list_item(
node: ListItemNode, idx: int, parent_node: ListNode | None = None
)
Specific renderring. Render the list item.
Requires
| Name | Type | Required | Description |
|---|
node | ListItemNode | | The list item to be rendered. |
idx | int | | The optional argument idx is the current index of the item in the list. |
parent_node | ListNode | None | | The optional parent_node is the nearest unordered/ordered list wrapper of this item. |
Returns
| Name | Type | Description |
|---|
v_1 | str | The rendered list item bbcode. |
render_paragraph
v_1: str = self.render_paragraph(node: ParagraphNode)
Specific renderring. Render the paragraph.
Requires
| Name | Type | Required | Description |
|---|
node | ParagraphNode | | The paragraph to be rendered. |
Returns
| Name | Type | Description |
|---|
v_1 | str | The rendered paragraph bbcode. |
render_quote
v_1: str = self.render_quote(node: QuoteNode)
Specific renderring. Render the quote block.
Requires
| Name | Type | Required | Description |
|---|
node | QuoteNode | | The quote block to be rendered. |
Returns
| Name | Type | Description |
|---|
v_1 | str | The rendered quote block. |
render_table
v_1: str = self.render_table(node: TableNode)
Specific renderring. Render the table.
BBCode table syntax varies by forum. We adopt the Steam's format.
[table]
[tr][th]Header[/th][th]Header[/th][/tr]
[tr][td]Cell[/td][td]Cell[/td][/tr]
[/table]
Requires
| Name | Type | Required | Description |
|---|
node | TableNode | | The table to be rendered. |
Returns
| Name | Type | Description |
|---|
v_1 | str | The rendered table bbcode. |
render_table_cell
v_1: str = self.render_table_cell(node: TableCellNode)
Specific renderring. Render the table cell (head or data cells).
Requires
| Name | Type | Required | Description |
|---|
node | TableCellNode | | The table cell to be rendered. |
Returns
| Name | Type | Description |
|---|
v_1 | str | The rendered table cell. |
render_table_row
v_1: str = self.render_table_row(node: TableRowNode)
Specific renderring. Render the table row.
Requires
| Name | Type | Required | Description |
|---|
node | TableRowNode | | The table row to be rendered. |
Returns
| Name | Type | Description |
|---|
v_1 | str | The rendered table row. |
render_text
v_1: str = self.render_text(node: TextNode)
Specific renderring. Render the plain text into BBCode.
Requires
| Name | Type | Required | Description |
|---|
node | TextNode | | The pure text to be rendered. |
Returns
| Name | Type | Description |
|---|
v_1 | str | The rendered text bbcode. |
wrap_children
v_1: str = self.wrap_children(children: list[Node], start: str, end: str | None = None)
Helper method. Render children and surround the results by:
Requires
| Name | Type | Required | Description |
|---|
children | list[Node] | | The children to be rendered with the wrapper. |
start | str | | The "start" tag prepended to the children. |
end | str | None | | The "end" tag appended to the children. |
Returns
| Name | Type | Description |
|---|
v_1 | str | The rendered and wrapped children bbcode. |