小编Tin*_*Luu的帖子

使用Python将Markdown表转换为html表

我有一个markdown表语法字符串,说:

table_md=\
"| Tables        | Are           | Cool  |\n\
| ------------- |-------------| -----|\n\
| col 3 is      | right-aligned | $1600 |\n\
| col 2 is      | centered      |   $12 |\n\
| zebra stripes | are neat      |    $1 |\n"
Run Code Online (Sandbox Code Playgroud)

我想将其转换为html语法表字符串:

<table>
<thead>
<tr>
<th>Tables</th>
<th>Are</th>
<th>Cool</th>
</tr>
</thead>
<tbody>
<tr>
<td>col 3 is</td>
<td>right-aligned</td>
<td>$1600</td>
</tr>
<tr>
<td>col 2 is</td>
<td>centered</td>
<td>$12</td>
</tr>
<tr>
<td>zebra stripes</td>
<td>are neat</td>
<td>$1</td>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

首先搜索stackoverflow,我尝试使用这个:

import markdown
table_html=markdown.markdown(table_md)
Run Code Online (Sandbox Code Playgroud)

但结果是一个html段落: …

html python markdown

5
推荐指数
1
解决办法
1621
查看次数

标签 统计

html ×1

markdown ×1

python ×1