我没有从Python的脚注扩展中得到我期望的结果。
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结果是:
<p>Footnotes[^1] have a label[^@#$%] and the footnote's content.[^1]: This is a footnote content.[^@#$%]: A footnote on the label: @#$%.</p>脚注一点也没有被解析!为什么会这样呢?
发布于 2014-02-19 10:02:19
你的台词里没有新的台词。行尾的\只允许您将字符串跨多行,实际上它不包括换行符。如果要显式地包含换行符,那么在行的开头就会有太多的空格,最后会有一个<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. <a class="footnote-backref" href="#fnref:1" rev="footnote" title="Jump back to footnote 1 in the text">↩</a></p>
</li>
<li id="fn:@#$%">
<p>A footnote on the label: @#$%. <a class="footnote-backref" href="#fnref:@#$%" rev="footnote" title="Jump back to footnote 2 in the text">↩</a></p>
</li>
</ol>
</div>https://stackoverflow.com/questions/21876975
复制相似问题