2014-02-19 3 views
1

파이썬 마크 다운의 각주 확장에서 기대했던 것을 얻지 못했습니다.각주로 파이썬 마크 다운

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