django-markymark¶
django-markymark provides helpers and tools to integrate markdown into Django.
Features¶
Django form fields to integrate the bootstrap markdown editor (without the dependency on bootstrap)
django-filer integration
django-anylink integration
Requirements¶
django-markymark supports Python 3 only and requires at least Django 3.2
Prepare for development¶
A Python 3 interpreter is required in addition to Poetry.
$ poetry install
Now you’re ready to start the example project to experiment with markymark.
$ poetry run python examples/manage.py runserver
Resources¶
Contents:
Installation¶
Install with pip:
pip install django-markymark
Your
INSTALLED_APPS
setting:INSTALLED_APPS = ( # ... 'markymark', )
Configuration for Django-CMS¶
If you plan to use django-markymark in a Django-CMS project, you should change the following two settings to make sure there are no iconlibrary problems:
MARKYMARK_FONTAWESOME_CSS = None
MARKYMARK_ICONLIBRARY = 'fa4'
Configuration¶
Markymark uses settings to make the markdown field work in the django admin site.
Django Settings¶
- MARKYMARK_EXTENSIONS¶
A list with extra extensions for the markdown field.
Default extensions:
MARKYMARK_EXTENSIONS = [
'markymark.extensions.autolink',
]
- MARKYMARK_FONTAWESOME_CSS¶
By default, the markdown editor uses FontAwesome to show some nice icons. FontAwesome is vendored and shipped with this library. You can override the path of the FontAwesome css file to use either the CDN version or something completly different.
# Override default setting.
MARKYMARK_FONTAWESOME_CSS = 'https://use.fontawesome.com/releases/v5.2.0/css/all.css'
- MARKYMARK_ICONLIBRARY¶
By default, the markdown editor uses Font Awesome 5 compatible css classes for icons. In addition, you can change the used icon library to Font Awesome 4.
To change the icon classes to Fa4, use this setting:
MARKYMARK_ICONLIBRARY = 'fa4'
Extensions¶
Python Markdown¶
Regular extensions from Python Markdown for extra markdown features, can be used with markymark.
MARKYMARK_EXTENSIONS = [
'..',
'markdown.extensions.codehilite',
'markdown.extensions.fenced_code',
'markdown.extensions.tables',
]
Django-anylink¶
An extension for django-anylink a generic linking module for Django.
The following needs to be added to the settings:
MARKYMARK_EXTENSIONS = [
'..',
'markymark.extensions.anylink',
]
This extension has extra dependencies that need to be installed:
$ pip install django-markymark[anylink]
Note
For this extension additional settings are required that can be found in the django-anylink documentation
Warning
The JavaScript plugin overwrites the functionality of the “Link” button of the markdown editor with it’s own implementation. Please be aware of that.
Django-filer¶
An extension for django-filer a file and image management application for django.
The following needs to be added to the settings:
MARKYMARK_EXTENSIONS = [
'..',
'markymark.extensions.filer',
]
This extension has extra dependencies that need to be installed:
$ pip install django-markymark[filer]
Note
For this extension additional settings are required that can be found in the django-filer documentation
Warning
The JavaScript plugin overwrites the functionality of the “Link” button of the markdown editor with it’s own implementation. Please be aware of that.
Autolink¶
An extension to automatically create anchor tags from urls inspired by Github Flavored Markdown.
The following needs to be added to the settings:
MARKYMARK_EXTENSIONS = [
'..',
'markymark.extensions.autolink',
]
Example input/output:
http://www.example.com will turn into <a href="http://www.example.com">http://www.example.com</a>
Usage¶
Model Field¶
from django.db import models
from markymark.fields import MarkdownField
class Post(models.Model):
content = MarkdownField()
Template filter¶
To display the rendered markdown in your template.
{% load markymark %}
{{ obj.content|markdown }}
Running tests¶
To run the tests, you need to install the test requirements with Poetry:
$ poetry install
Now you can run the tests from the root folder of the package:
$ make tests
Changelog¶
3.0.0 (2022-09-12)¶
Drop support for Django < 3.2, add support for 3.2
Drop support for Python < 3.8
2.1.0 (2018-09-11)¶
Add setting to switch icon library for markdown editor to FontAwesome 4
2.0.0 (2018-07-27)¶
THIS IS A BREAKING RELEASE, if you need Django < 1.11 please stick to the 1.1.0 release.
Drop Python < 3 support
Drop Django < 1.11 support
Cleanup code and add some more documentation
1.1.0 (2017-04-21)¶
add table support including new button in editor
1.0.5 (2017-04-20)¶
drop py26 support
Fix anylink pop up, make it more flexible for custom project urls
1.0.4 (2017-02-21)¶
Fix styling when using markymark in inlines with django-cms / djangocms-admin-style
Force Pillow version for py26
1.0.0 (2016-11-24)¶
Add support for Django 1.9
Fix styling when using markymark with django-cms / djangocms-admin-style
Improve autolink extension to prevent double-linking
Javascript bugfixes
0.9.3 (2016-10-05)¶
fix issue - MarkdownField should handle widget instances as well #7
adjust install requirements to use ‘official’ python Markdown package
some improvements
0.9.2 (2016-02-03)¶
fix javascript - js was renamed from dismissAddAnotherPopup to dismissAddRelatedObjectPopup
0.9.1 (2015-09-24)¶
fix MardownTextarea widget
0.9.0 (2015-09-24)¶
add django 1.8 and python 3.5 support
0.8.3 (2015-07-08)¶
fix - make “$” available in function only in markdown-editor.js
0.8.2 (2015-04-22)¶
Add python 2.6 support
Add support for south
0.8.1 (2015-03-16)¶
Small style fix for preview button
0.8.0 (2015-03-12)¶
Refactor JavaScript part of plugins to replace existing icons
Fix bug in anylink js integration to avoid blank window after save
0.7.2 (2015-03-09)¶
Fix anylink javascript to link to ‘add’ view
0.7.1 (2015-03-09)¶
Remove padding from textarea
0.7 (2015-03-09)¶
Fix release
0.6 (2015-03-09)¶
Rework extensions to allow js/css files to be defined directly on each extension
The return value of
render_markdown()
is now marked as safeAllow template-names to be overwritten
Made settings easier to be overwritten, you can now import default settings from
markymark.defaults
Fixed contrib.anylink to avoid name clashes with other extensions named “link”
Fix fullscreen icon integration
0.5 (2015-02-13)¶
Removed anylink and filer extensions from being autoloaded.
Removed dependency on floppyforms.
0.2..0.4 (2015-01-22)¶
General cleanups and bugfixes.
0.1 (2015-01-22)¶
Initial release.
Api documentation:
markymark.renderer¶
markymark.fields¶
- class markymark.fields.MarkdownFormField(*args, **kwargs)[source]¶
Bases:
CharField
Form field to configure the markdown textarea widget if not already set.
markymark.widgets¶
markymark.extensions¶
markymark.extensions.autolink¶
- class markymark.extensions.autolink.AutoLinkPostprocessor(md=None)[source]¶
Bases:
Postprocessor
Post processor to look for valid URIs and converts them to html links.
- class markymark.extensions.autolink.AutoLinkExtension(**kwargs)[source]¶
Bases:
MarkymarkExtension
Extension to insert html links for certain URIs.
markymark.extensions.base¶
- class markymark.extensions.base.MarkymarkExtension(**kwargs)[source]¶
Bases:
Extension
Base class for all markymark extensions.
Actually its just a markdown.Extension class with some media attached.
markymark.extensions.clean¶
- class markymark.extensions.clean.CleanExtension(**kwargs)[source]¶
Bases:
MarkymarkExtension
Extension to enable the cleanup plugin for the markdown editor.
markymark.extensions.anylink¶
- class markymark.extensions.anylink.AnyLinkPostprocessor(md=None)[source]¶
Bases:
Postprocessor
Post processor to look for anylink link tags, replaces these tags with html links.
- class markymark.extensions.anylink.AnyLinkExtension(**kwargs)[source]¶
Bases:
MarkymarkExtension
Extension to insert django-anylink links into a markdown document.
markymark.extensions.filer¶
- class markymark.extensions.filer.FilerPostprocessor(md=None)[source]¶
Bases:
Postprocessor
Filer markdown extension for django-filer to show files and images.