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_rows | int | 表格行数。第一行用作表头。 | |
n_cols | int | 表格列数。 | |
cells | dict[tuple[int, int], str] | 按照 {(index_row, index_col): text} 格式保存的单元格文本。 | |
col_styles | dict[int, Literal["l", "c", "r", "n"]] | 各列对应的样式。可用标记为:(l) 左对齐, (c): 居中, (r): 右对齐, (n): 无样式。 |
方法
as_md_text
v_1: str = self.as_md_text()
渲染为 Markdown 文字。
输出
| 参数 | 类型 | |
|---|---|---|
v_1 | str | 从表格渲染的 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.
输入
| 参数 | 类型 | 必选 | |
|---|---|---|---|
md | MarkdownIt | markdown-it 解析器。 | |
text | str | 单元格文字。 |
输出
| 参数 | 类型 | |
|---|---|---|
v_1 | str | 渲染后的单元格文字。 |