django-ml_markdown

A django app that parse markdown to html


Keywords
django, markdown, ml_markdown
License
BSD-3-Clause
Install
pip install django-ml_markdown==0.1.0

Documentation

django-ml_markdown

This package provides some django template tags to parse markdown text to html. It needs :

  • misaka to parse markdown test;
  • bleach to clean html output;
  • pygments to enable syntax highlighting for blockcodes

Installation

Install from the Python Package Index

    pip install django-ml_markdown

If you clone this repository, refer to each dependencies documentation for installation

Usage

Add this app to INSTALLED_APPS

INSTALLED_APPS += ['ml_markdown']

And, in your template file

{% load ml_markdown_tags %}
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Example</title>
    </head>
    <body>
        <article>
            {{ markdown_text|to_cleaned_html }}
        </article>
    </body>
</html>

Tags list

to_html

Parse Markdown code to HTML

clean

Clean HTML code using bleach

to_cleaned_html

Same as to_html|clean

sectionize

Change this :

<h1>First section</h1>
<p>Some text</p>

<h1>Second Section</h1>
<p> Some text</p>

<h1>Third Section</h1>
<p> Some text</p>

to this:

<section>
<h1>First section</h1>
<p>Some text</p>
</section>

<section>
<h1>Second Section</h1>
<p> Some text</p>
</section>

<section>
<h1>Third Section</h1>
<p> Some text</p>
</section>

Usage

{{ markdown|to_html|sectionize:"args"|clean }}

"args" default value is "False,None"

The first argument tell if this filter must skip the first <h1> or not.Can be True or False

The second give a mark from which you do not want <section> tags. Set to None to continue to the end

The to arguments must nbe separated by a coma Example : With :

{{ markdown|to_html|sectionize:"True,<hr>"|clean }}

this :

<h1>First section</h1>
<p>Some text</p>

<h1>Second Section</h1>
<p> Some text</p>

<h1>Third Section</h1>
<p> Some text</p>

<hr>
<p> Some text</p>

become this :

<h1>First section</h1>
<p>Some text</p>

<section>
<h1>Second Section</h1>
<p> Some text</p>
</section>

<section>
<h1>Third Section</h1>
<p> Some text</p>
</section>

<hr>
<p> Some text</p>