Markdown output with Django

I thought I should install CommonMark or Markdown with pip and use this template tag

pip install CommonMark

templatetag.py



import CommonMark
from django import template
from django.template.defaultfilters import stringfilter
import re

register = template.Library()


@register.filter
@stringfilter
def mark2html(value):
    plain_text = CommonMark.commonmark(value)
    return re.sub(r'<[sS][cC][rR][iI][pP][tT][\s\S]+?/[sS][cC][rR][iI][pP][tT]>', '', plain_text)

I'm not confident about regular expressions, so please point out any problems, please.

Postscript

I'm tired and mistaken for decorator and templatetag, excuse me

Recommended Posts

Markdown output with Django
Internationalization with django
CRUD with Django
Authenticate Google with Django
Django 1.11 started with Python3.6
Upload files with Django
Development digest with Django
Use Gentelella with django
Twitter OAuth with Django
Getting Started with Django 1
Output PDF with WeasyPrint
Send email with Django
File upload with django
Blog markdown with pelican
Use LESS with Django
Pooling mechanize with Django
Use MySQL with Django
Start today with Django
Getting Started with Django 2
The story that Japanese output was confused with Django
Do Django with CodeStar (Python3.6.8, Django2.2.9)
Get started with Django! ~ Tutorial ⑤ ~
Minimal website environment with django
Create an API with Django
Do Django with CodeStar (Python3.8, Django2.1.15)
Try Python output with Haxe 3.2
Deploy Django serverless with Lambda
Python3 + Django ~ Mac ~ with Apache
Test standard output with Pytest
Getting Started with Python Django (1)
Create a homepage with django
Output to syslog with Loguru
Output table structure in Django
Get started with Django! ~ Tutorial ④ ~
Getting Started with Python Django (4)
Web application creation with Django
Output large log with discord.py
Getting Started with Python Django (3)
Combine FastAPI with Django ORM
Get started with Django! ~ Tutorial ⑥ ~
Save tweet data with Django
Do AES encryption with DJango
Getting Started with Python Django (6)
Combine two images with Django
Getting Started with Django with PyCharm
Real-time web with Django Channels
Double submit suppression with Django
Django REST framework with Vue.js
Use prefetch_related conveniently with Django
Getting Started with Python Django (5)
Login with django rest framework
Qiita API Oauth with Django
Test Driven Development with Django Part 3
reload in django shell with ipython
Steps to develop Django with VSCode
Test Driven Development with Django Part 4
Load Django modules with an interpreter
Set up social login with Django
Test Driven Development with Django Part 6
Measure Django application coverage with Coverage.py
Handle csv files with Django (django-import-export)