Skip to main content

Django Markdown Editor

Project description

martor pypi version

https://img.shields.io/badge/license-GNUGPLv3-blue.svg https://img.shields.io/pypi/pyversions/martor.svg https://img.shields.io/badge/Django-1.8,%201.9,%201.10,%201.11,%202.0,%202.1-green.svg https://travis-ci.org/agusmakmun/django-markdown-editor.svg?branch=master

Martor is Markdown Editor plugin for Django and new face of DracEditor.

Features

  • Live Preview

  • Integrated with Ace Editor

  • Integrated with Semantic-UI

  • Support Multiple Fields (fixed this issue)

  • Upload Image to imgur.com (via API) and custom uploader.

  • Direct Mention users @[username] - (require user to logged in)

  • Support embed/iframe video from (Youtube, Vimeo, Dailymotion, Yahoo, Veoh, & Metacafe)

  • Emoji :emoji_name: + Cheat sheets

  • Martor Commands Refference

  • Support Django Admin

  • Toolbar Buttons

  • Highlight pre

Preview

https://raw.githubusercontent.com/agusmakmun/django-markdown-editor/master/__screenshot/martor-preview-editor.png https://raw.githubusercontent.com/agusmakmun/django-markdown-editor/master/__screenshot/martor-preview-result.png

Requirements

  • Django>=2.0

  • Markdown>=3.0

  • requests>=2.12.4

Installation

Martor is available directly from PyPI:

  1. Installing the package.

$ pip install martor
  1. Don’t forget to add 'martor' to your 'INSTALLED_APPS' setting (without migrations).

# settings.py
INSTALLED_APPS = [
    ....
    'martor',
]
  1. Add url pattern to your urls.py.

# urls.py
# django >= 2.0
urlpatterns = [
    ...
    path('martor/', include('martor.urls')),
]

# django <= 1.9
urlpatterns = [
    ...
    url(r'^martor/', include('martor.urls')),
]
  1. Collect included some martor static files to your STATIC_ROOT folder.

./manage.py collectstatic

Setting Configurations settings.py

Please register application in https://api.imgur.com/oauth2/addclient to get IMGUR_CLIENT_ID and IMGUR_API_KEY.

# Global martor settings
# Input: string boolean, `true/false`
MARTOR_ENABLE_CONFIGS = {
    'imgur': 'true',     # to enable/disable imgur/custom uploader.
    'mention': 'false',  # to enable/disable mention
    'jquery': 'true',    # to include/revoke jquery (require for admin default django)
    'living': 'false',   # to enable/disable live updates in preview
}

# To setup the martor editor with label or not (default is False)
MARTOR_ENABLE_LABEL = False

# Imgur API Keys
MARTOR_IMGUR_CLIENT_ID = 'your-client-id'
MARTOR_IMGUR_API_KEY   = 'your-api-key'

# Safe Mode
MARTOR_MARKDOWN_SAFE_MODE = True # default

# Markdownify
MARTOR_MARKDOWNIFY_FUNCTION = 'martor.utils.markdownify' # default
MARTOR_MARKDOWNIFY_URL = '/martor/markdownify/' # default

# Markdown extensions (default)
MARTOR_MARKDOWN_EXTENSIONS = [
    'markdown.extensions.extra',
    'markdown.extensions.nl2br',
    'markdown.extensions.smarty',
    'markdown.extensions.fenced_code',

    # Custom markdown extensions.
    'martor.extensions.urlize',
    'martor.extensions.del_ins',    # ~~strikethrough~~ and ++underscores++
    'martor.extensions.mention',    # to parse markdown mention
    'martor.extensions.emoji',      # to parse markdown emoji
    'martor.extensions.mdx_video',  # to parse embed/iframe video
]

# Markdown Extensions Configs
MARTOR_MARKDOWN_EXTENSION_CONFIGS = {}

# Markdown urls
MARTOR_UPLOAD_URL = '/martor/uploader/' # default
MARTOR_SEARCH_USERS_URL = '/martor/search-user/' # default

# Markdown Extensions
MARTOR_MARKDOWN_BASE_EMOJI_URL = 'https://www.webfx.com/tools/emoji-cheat-sheet/graphics/emojis/' # default
MARTOR_MARKDOWN_BASE_MENTION_URL = 'https://python.web.id/author/' # default (change this)

Check this setting is not set else csrf will not be sent over ajax calls:

CSRF_COOKIE_HTTPONLY = False

Usage

Model

from django.db import models
from martor.models import MartorField

class Post(models.Model):
    description = MartorField()

Form

from django import forms
from martor.fields import MartorFormField

class PostForm(forms.Form):
    description = MartorFormField()

Admin

from django.db import models
from django.contrib import admin

from martor.widgets import AdminMartorWidget

from yourapp.models import YourModel

class YourModelAdmin(admin.ModelAdmin):
    formfield_overrides = {
        models.TextField: {'widget': AdminMartorWidget},
    }

admin.site.register(YourModel, YourModelAdmin)

Template

Simply safe the markdown content as html ouput with loading the templatetags from martor/templatetags/martortags.py.

{% load martortags %}
{{ field_name|safe_markdown }}

# example
{{ post.description|safe_markdown }}

Custom Uploader

If you want to save the images uploaded to your storage, Martor also provide to handle it. Please checkout this WIKI.

Test the Martor from this Repository

I assume you already setup with virtual enviroment (virtualenv).

$ git clone https://github.com/agusmakmun/django-markdown-editor.git
$ cd django-markdown-editor/ && python setup.py install
$ cd martor_demo/
$ python manage.py makemigrations && python manage.py migrate
$ python manage.py runserver

And let checkout at http://127.0.0.1:8000/simple-form/ to your browser.

Martor Commands Refference

https://raw.githubusercontent.com/agusmakmun/django-markdown-editor/master/__screenshot/martor-guide.png

Notes

Martor was inspired by great django-markdownx, Python Markdown and Online reStructuredText editor.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

martor-1.3.9.tar.gz (1.1 MB view details)

Uploaded Source

Built Distribution

martor-1.3.9-py3.5.egg (1.1 MB view details)

Uploaded Source

File details

Details for the file martor-1.3.9.tar.gz.

File metadata

  • Download URL: martor-1.3.9.tar.gz
  • Upload date:
  • Size: 1.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.2

File hashes

Hashes for martor-1.3.9.tar.gz
Algorithm Hash digest
SHA256 fc0f81763cf3b329eaf90cf67ac5ef335c5891a16076d51c81153ba0ca6482d3
MD5 e3f430637f07edf42b3b36f2b36dd663
BLAKE2b-256 34df3c0d6ba6ddbd23325c96d64b9e5f073826d61ae3e02ced131cf1a77cbf2a

See more details on using hashes here.

Provenance

File details

Details for the file martor-1.3.9-py3.5.egg.

File metadata

  • Download URL: martor-1.3.9-py3.5.egg
  • Upload date:
  • Size: 1.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.2

File hashes

Hashes for martor-1.3.9-py3.5.egg
Algorithm Hash digest
SHA256 fde2d80812f7d72120266305e37f07bfc080e3400c447bfd82badaf82e8b3f4c
MD5 24f2c7f9319f93a05ae4ead8060c57f3
BLAKE2b-256 428386ee02aa0d986825c8db815cfcf3e977ea69efd2581eeeffe2ba75a69683

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page