2014-02-19 61 views
1

我沒有從Python Markdown的腳註擴展中得到預期的結果。Python Markdown with 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 

結果是:

<p>Footnotes[^1] have a label[^@#$%] and the footnote's content.[^1]: This is a footnote content.[^@#$%]: A footnote on the label: @#$%.</p> 

腳註是不是在所有解析!這是爲什麼?

回答

6

您的行中沒有換行符。行尾的\僅允許您將字符串放在多行中,但實際上並不包含換行符。如果你的明確包含換行符,那麼你的行首就會有太多的空白,而最終你會得到一個<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> 
+0

你是對的,謝謝! – bard