【发布时间】:2018-04-13 10:03:48
【问题描述】:
我有一个降价表语法字符串,比如:
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"
我想把它转换成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>
首先通过stackoverflow搜索,我尝试使用this:
import markdown
table_html=markdown.markdown(table_md)
但结果是一个html段落:
'<p>| Tables... |</p>'
通过解决问题,我来到markdown extensions,并尝试将扩展名添加到上面的命令中:
table_html=markdown.markdown(table_md, extensions=[MyExtension(), \
'markdown.extensions.tables'])
然后它显示错误说"NameError: name 'MyExtension' is not defined"
而且stackoverflow中没有同样的情况。
请帮助我如何处理上面的 MyExtension。谢谢!
【问题讨论】:
-
我投票结束这个问题,因为没有任何努力!
-
感谢提醒!我已经为这个问题付出了努力。