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.
I'm tired and mistaken for decorator and templatetag, excuse me
Recommended Posts