带脚注的Python标记

2024-06-01 00:31:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我没有从Python Markdown的footnotes扩展中得到我期望的结果。在

import markdown

content = "Footnotes[^1] have a label[^@#$%] and the footnote's content.\
           \
           [^1]: This is a footnote content.\
           [^@#$%]: A footnote on the label: @#$%."


htmlmarkdown=markdown.markdown( content, extensions=['footnotes'] )
print htmlmarkdown

结果是:

^{pr2}$

这些脚注根本不解析!为什么?在


Tags: andtheimportisonhavecontentthis
1条回答
网友
1楼 · 发布于 2024-06-01 00:31:30

你的台词中没有新行。行尾的\只允许您将字符串放在多行上,它实际上不包括换行符。如果要显式地包含换行符,那么在行的开头会有太多的空白,而最终会得到一个<pre>块。在

下面,使用三重引号来保留换行符是有效的:

>>> import markdown
>>> content = '''\
... Footnotes[^1] have a label[^@#$%] and the footnote's content.
... 
... [^1]: This is a footnote content.
... [^@#$%]: A footnote on the label: @#$%.
... '''
>>> print markdown.markdown( content, extensions=['footnotes'] )
<p>Footnotes<sup id="fnref:1"><a class="footnote-ref" href="#fn:1" rel="footnote">1</a></sup> have a label<sup id="fnref:@#$%"><a class="footnote-ref" href="#fn:@#$%" rel="footnote">2</a></sup> and the footnote's content.</p>
<div class="footnote">
<hr />
<ol>
<li id="fn:1">
<p>This is a footnote content.&#160;<a class="footnote-backref" href="#fnref:1" rev="footnote" title="Jump back to footnote 1 in the text">&#8617;</a></p>
</li>
<li id="fn:@#$%">
<p>A footnote on the label: @#$%.&#160;<a class="footnote-backref" href="#fnref:@#$%" rev="footnote" title="Jump back to footnote 2 in the text">&#8617;</a></p>
</li>
</ol>
</div>

相关问题 更多 >