LoginSignup
0
0

More than 5 years have passed since last update.

DjangoでMarkdown出力をする

Last updated at Posted at 2017-02-03

pipでCommonMarkかMarkdownをインストールして、このtemplatetagを使えばいいと思いました

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)

正規表現周りに自信が無いので、問題点があれば指摘下さい、お願いします

追記

疲れててdecoratorとtemplatetagを間違えました、失礼しました

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0