Created
January 7, 2014 13:51
-
-
Save pistatium/8299577 to your computer and use it in GitHub Desktop.
pythonでmarkdownを扱う ref: http://qiita.com/pistatium@github/items/982c6fc0b3c7cf226799
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import markdown | |
md = markdown.Markdown() | |
sample_makedown = ''' | |
An h1 header | |
============ | |
Paragraphs are separated by a blank line. | |
2nd paragraph. *Italic*, **bold**, `monospace`. Itemized lists | |
look like: | |
* this one | |
* that one | |
* the other one | |
''' | |
# makedown -> html | |
print md.convert(sample_makedown) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import markdown | |
#キャッシュするためここで宣言、初期化しとく | |
md = markdown.Markdown() | |
@register.filter | |
@stringfilter | |
def mark2html(value): | |
return md.convert(value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% load myfilter %} | |
{{ markdown_text|mark2html }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>An h1 header</h1> | |
<p>Paragraphs are separated by a blank line.</p> | |
<p>2nd paragraph. <em>Italic</em>, <strong>bold</strong>, <code>monospace</code>. Itemized lists | |
look like:</p> | |
<ul> | |
<li>this one</li> | |
<li>that one</li> | |
<li>the other one</li> | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment