Skip to content

Commit

Permalink
BaseFormatter를 상속한 Formatter 생성하여 라이브러리 적용.
Browse files Browse the repository at this point in the history
라이브러리는 Misaka, Hoedown, Mistune를 선정하였음.

* [Misaka](https://misaka.61924.nl/#)
  - Sundown Python 바인딩. Sundown은 현재 deprected.
  - 코드 하이라이팅 기능 있음

* [python-hoedown](https://github.com/hhatto/python-hoedow) 라이브러리
  - Deprected Sundown 라이브러리를 포크한 Python
바인딩(Hoedown)
  - Misaka 라이브러리의 기능을 가지고 있음
  - Pypy compatible
  - Footnote 기능 있음

* [Mistune](https://mistune.readthedocs.io/en/latest/)
  - Python-Markdown 라이브러리보다 4배 빠르다고 함
    - lepture/mistune#1
  - 최신 라이브러리. 2018-10-11에 Version 0.8.4 release
  - Full featured. autolink, strikethrough, table, fenced code, footnotes 지원
  • Loading branch information
love-adela committed Aug 25, 2019
1 parent 015d54c commit 4cf6878
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions django-blog/mysite/blog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.utils import timezone
from django.utils.html import mark_safe
from django.urls import reverse_lazy
import misaka
import misaka, hoedown, mistune
import logging

try:
Expand Down Expand Up @@ -34,12 +34,23 @@ class FormatterMisaka(BaseFormatter):
def format(self, text):
return misaka.html(text)

class FormatterHoedown(BaseFormatter):
def format(self, text):
return hoedown.html(text)

class FormatterMistune(BaseFormatter):
def format(self, text):
return mistune.markdown(text)

class Post(models.Model):
title = models.CharField(max_length=200, help_text='title of message.')
author = models.ForeignKey('auth.User', on_delete=models.CASCADE)
slug = models.SlugField()
text = models.TextField(help_text='무슨 생각을 하고 계세요?')
formatter = FormatterMisaka()
# Here are Markdown Parsers
# formatter = FormatterMisaka()
# formatter = FormatterHoedown()
formatter = FormatterMistune()
draft = models.BooleanField(default=False)
tag = models.ManyToManyField(Tag)
created_date = models.DateTimeField(default=timezone.now)
Expand Down

0 comments on commit 4cf6878

Please sign in to comment.