Handle markdown in python

Handle Markdown in Python

md_test.py


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)

The print result is as follows.

Output result


<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>

Just convert it like this It converts Markdown text to HTML. It's very easy to use. It also supports writing to files.

Use with Django

When using it with Django, I will make the following filter by myself

myfilter.py


import markdown
#Declare and initialize here for caching
md = markdown.Markdown()

@register.filter
@stringfilter
def mark2html(value):
    return md.convert(value)

template.html


{% load myfilter %}

{{ markdown_text|mark2html }}

Recommended Posts

Handle markdown in python
Handle Parquet in Python
Handle Ambient data in Python
Handle environment variables in Python
Handle complex numbers in Python
Convert markdown to PDF in Python
Handle NetCDF format data in Python
Handle GDS II format in Python
How to handle Japanese in Python
Quadtree in Python --2
Python in optimization
CURL in python
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
Meta-analysis in Python
Unittest in python
Epoch in Python
Discord in Python
Sudoku in Python
DCI in Python
quicksort in python
nCr in python
Plink in Python
Constant in python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Constant in python
nCr in Python.
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
Quad-tree in Python
Reflection in Python
Chemistry in Python
Hashable in python
DirectLiNGAM in Python
LiNGAM in Python
Flatten in python
flatten in python
Handle multiple python versions in one jupyter
Convert from Markdown to HTML in Python
Sorted list in Python
Clustering text in Python
Daily AtCoder # 2 in Python
Implement Enigma in python
Daily AtCoder # 6 in Python
Daily AtCoder # 18 in Python
Edit fonts in Python
Singleton pattern in Python
File operations in Python