mirror of
https://github.com/Hopiu/django-markdownx.git
synced 2026-05-11 06:43:10 +00:00
[Closes #15] Make rendering the markdown abstractable
This commit is contained in:
parent
8ed93f974d
commit
e35c1aa0c4
3 changed files with 18 additions and 8 deletions
|
|
@ -1,6 +1,10 @@
|
|||
from django.conf import settings
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
||||
# Markdownify
|
||||
MARKDOWNX_MARKDOWNIFY_FUNCTION = getattr(settings, 'MARKDOWNX_MARKDOWNIFY_FUNCTION', 'markdownx.utils.markdownify')
|
||||
|
||||
# Markdown extensions
|
||||
MARKDOWNX_MARKDOWN_EXTENSIONS = getattr(settings, 'MARKDOWNX_MARKDOWN_EXTENSIONS', [])
|
||||
MARKDOWNX_MARKDOWN_EXTENSION_CONFIGS = getattr(settings, 'MARKDOWNX_MARKDOWN_EXTENSION_CONFIGS', {})
|
||||
|
|
|
|||
|
|
@ -1,5 +1,17 @@
|
|||
import markdown
|
||||
|
||||
from PIL import Image
|
||||
|
||||
from .settings import MARKDOWNX_MARKDOWN_EXTENSIONS, MARKDOWNX_MARKDOWN_EXTENSION_CONFIGS
|
||||
|
||||
|
||||
def markdownify(content):
|
||||
return markdown.markdown(
|
||||
content,
|
||||
extensions=MARKDOWNX_MARKDOWN_EXTENSIONS,
|
||||
extension_configs=MARKDOWNX_MARKDOWN_EXTENSION_CONFIGS
|
||||
)
|
||||
|
||||
def scale_and_crop(image, size, crop=False, upscale=False, quality=None):
|
||||
# Open image and store format/metadata.
|
||||
image.open()
|
||||
|
|
|
|||
|
|
@ -1,20 +1,14 @@
|
|||
import markdown
|
||||
|
||||
from django.views.generic.edit import View, FormView
|
||||
from django.http import HttpResponse, JsonResponse
|
||||
|
||||
from .forms import ImageForm
|
||||
from .settings import MARKDOWNX_MARKDOWN_EXTENSIONS, MARKDOWNX_MARKDOWN_EXTENSION_CONFIGS
|
||||
from .utils import markdownify
|
||||
|
||||
|
||||
class MarkdownifyView(View):
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
return HttpResponse(
|
||||
markdown.markdown(
|
||||
request.POST['content'],
|
||||
extensions=MARKDOWNX_MARKDOWN_EXTENSIONS,
|
||||
extension_configs=MARKDOWNX_MARKDOWN_EXTENSION_CONFIGS))
|
||||
return HttpResponse(markdownify(request.POST['content']))
|
||||
|
||||
|
||||
class ImageUploadView(FormView):
|
||||
|
|
|
|||
Loading…
Reference in a new issue