跳到主要内容

Table

类数据类源码

Table(
n_rows: int,
n_cols: int,
cells: dict[tuple[int, int], str] = dict(...),
col_styles: dict[int, Literal["l", "c", "r", "n"]] = dict(...)
)

用来呈现参数信息的 Markdown 表格。

字段​

字段类型必选
说明
n_rowsint表格行数。第一行用作表头。
n_colsint表格列数。
cellsdict[tuple[int, int], str]按照 {(index_row, index_col): text} 格式保存的单元格文本。
col_stylesdict[int, Literal["l", "c", "r", "n"]]各列对应的样式。可用标记为:(l) 左对齐, (c): 居中, (r): 右对齐, (n): 无样式。

方法​

as_md_text​

v_1: str = self.as_md_text()

渲染为 Markdown 文字。

输出​

参数类型
说明
v_1str从表格渲染的 Markdown 文本。

render_cell​

v_1: str = self.render_cell(md: MarkdownIt, text: str)

安全地渲染单元格文字。

若该文字为单个段落,则按原样渲染。否则,就将其渲染成HTML代码。 If the text is a single pargraph, render it as it is. Otherwise, render it as HTML codes.

输入​

参数类型必选
说明
mdMarkdownItmarkdown-it 解析器。
textstr单元格文字。

输出​

参数类型
说明
v_1str渲染后的单元格文字。