django-markdownx/README.md

180 lines
4.1 KiB
Markdown
Raw Normal View History

2014-11-02 19:44:46 +00:00
[![Downloads](https://pypip.in/d/django-markdownx/badge.svg?period=month&style=flat)](https://pypi.python.org/pypi/django-markdownx/)
[![Latest Version](https://pypip.in/v/django-markdownx/badge.svg?style=flat)](https://pypi.python.org/pypi/django-markdownx/)
[![License](https://pypip.in/license/django-markdownx/badge.svg?style=flat)](https://pypi.python.org/pypi/django-markdownx/)
2014-11-01 23:20:50 +00:00
2014-11-01 21:02:31 +00:00
# django-markdownx
2014-11-03 16:16:33 +00:00
Django Markdownx is a markdown editor built for Django.
2014-11-01 21:02:31 +00:00
2014-11-12 15:04:21 +00:00
It is simply an extension of the Django's Textarea widget made for editing Markdown with a live preview. It also supports uploading images with drag&drop functionality and auto tag insertion.
2014-11-03 16:16:33 +00:00
2014-11-03 17:42:19 +00:00
Example (side-by-side editor and preview using Bootstrap's grid system):
2014-11-03 16:16:33 +00:00
![Example](http://quaintworks.com/django-markdownx-preview.png)
2014-11-01 21:02:31 +00:00
## Quick Start
2014-11-01 22:16:52 +00:00
1. Install *django-markdownx* package
2014-11-01 21:02:31 +00:00
2014-11-01 22:16:52 +00:00
```python
pip install django-markdownx
```
2014-11-01 21:02:31 +00:00
2014-11-01 22:16:52 +00:00
1. Add *markdownx* to your *INSTALLED_APPS*
2014-11-01 21:02:31 +00:00
2014-11-01 22:16:52 +00:00
```python
2014-11-02 19:44:46 +00:00
#settings.py
2014-11-01 22:16:52 +00:00
INSTALLED_APPS = (
[...]
'markdownx',
```
2014-11-01 21:02:31 +00:00
2014-11-01 22:16:52 +00:00
1. Add *url* pattern to your *urls.py*
```python
2014-11-02 19:44:46 +00:00
#urls.py
2014-11-01 22:16:52 +00:00
urlpatterns = [
2014-11-05 09:44:31 +00:00
[...]
2014-11-01 22:16:52 +00:00
url(r'^markdownx/', include('markdownx.urls')),
]
```
1. Use *MarkdownxInput* widget in your *forms.py*
```python
2014-11-02 19:44:46 +00:00
#forms.py
2014-11-01 22:16:52 +00:00
from django import forms
from markdownx.widgets import MarkdownxInput
class MyForm(forms.ModelForm):
content = forms.CharField(widget=MarkdownxInput)
```
2014-11-12 15:04:21 +00:00
1. Use `manage.py collectstatic` to copy inlcuded `markdownx.js` to your `STATIC_ROOT` folder.
2014-11-01 22:16:52 +00:00
2014-11-05 09:44:31 +00:00
1. Include the form's required media in the template using `{{ form.media }}`
```html
<form method="POST" action="">{% csrf_token %}
2014-11-12 15:04:21 +00:00
[...]
2014-11-05 09:44:31 +00:00
</form>
{{ form.media }}
```
2014-11-12 15:04:21 +00:00
1. Include *[jQuery](http://jquery.com)*
2014-11-01 22:16:52 +00:00
```html
<head>
2014-11-12 15:04:21 +00:00
[...]
2014-11-01 22:16:52 +00:00
<script src="{{ STATIC_URL }}js/jquery.js"></script>
</head>
```
2014-11-01 22:09:46 +00:00
2014-11-01 21:02:31 +00:00
# Settings
2014-11-02 19:57:16 +00:00
Place settings in your *settings.py* to override default values:
2014-11-02 19:44:46 +00:00
2014-11-01 22:09:46 +00:00
```python
2014-11-01 23:20:50 +00:00
#settings.py
2014-11-12 15:04:21 +00:00
MARKDOWNX_MARKDOWN_KWARGS = dict()
2014-11-01 22:09:46 +00:00
MARKDOWNX_MEDIA_PATH = 'markdownx/' # subdirectory, where images will be stored in MEDIA_ROOT folder
MARKDOWNX_MAX_UPLOAD_SIZE = 52428800 # 50MB
MARKDOWNX_CONTENT_TYPES = ['image/jpeg', 'image/png']
MARKDOWNX_IMAGE_SIZE = {'size': (500, 500), 'quality': 90,}
```
2014-11-01 21:02:31 +00:00
2014-11-02 19:57:16 +00:00
*MARKDOWNX_IMAGE_SIZE* dict properties:
2014-11-01 21:02:31 +00:00
2014-11-02 19:44:46 +00:00
* **size** (width, height). When `0` used, i.e.: (500,0), property will figure out proper height by itself
2014-11-01 21:02:31 +00:00
* **quality** default: `None` image quality, from `0` (full compression) to `100` (no compression)
* **crop** default: `False` if `True` use `size` to crop final image
2014-11-02 19:44:46 +00:00
* **upscale** default: `False` if image dimensions are smaller than those in `size`, upscale image to `size` dimensions
2014-11-01 21:02:31 +00:00
2014-11-01 23:20:50 +00:00
# Template
2014-11-01 21:02:31 +00:00
2014-11-01 23:20:50 +00:00
Default template looks like:
2014-11-01 21:02:31 +00:00
2014-11-01 22:09:46 +00:00
```html
<div id="markdownx">
<h6>{% trans "Editor" %}</h6>
{{ markdownx_editor }}
2014-11-01 22:09:46 +00:00
<h6>{% trans "Preview" %}</h6>
<div id="markdownx_preview"></div>
</div>
```
2014-11-01 21:02:31 +00:00
2014-11-01 23:20:50 +00:00
It is easy customizable, i.e. when you want to use Bootstrap 3 and "real" side-by-side panes. Just place `templates/markdownx/widget.html` file with:
2014-11-01 21:02:31 +00:00
2014-11-01 22:09:46 +00:00
```html
<div class="row" id="markdownx">
<div class="col-sm-6">
<h6>{% trans "Editor" %}</h6>
{{ markdownx_editor }}
2014-11-01 22:09:46 +00:00
</div>
<div class="col-sm-6">
<h6>{% trans "Preview" %}</h6>
<div id="markdownx_preview"></div>
</div>
</div>
```
2014-11-01 21:02:31 +00:00
# Dependencies
2014-11-01 23:24:25 +00:00
* jQuery AJAX upload and JS functionality
2014-11-01 21:02:31 +00:00
# TODO
* custom URL upload link
2014-11-02 19:44:46 +00:00
* custom media path function
* python 3 compatibility
2014-11-12 15:04:21 +00:00
* tests
2014-11-01 21:02:31 +00:00
# Changelog
2014-11-14 11:29:37 +00:00
### v0.4.0
* editor auto height
2014-11-14 10:11:36 +00:00
### v0.3.1
* JS event fix
2014-11-13 09:40:51 +00:00
### v0.3.0
* version bump
2014-11-12 15:04:21 +00:00
### v0.2.9
* Removed any inlcuded css
* Removed JS markdown compiler (full python support now with Markdown lib)
2014-11-05 22:11:33 +00:00
### v0.2.0
* Allow to paste tabs using Tab button
2014-11-03 10:04:22 +00:00
### v0.1.4
* package data fix
2014-11-03 09:31:41 +00:00
### v0.1.3
* README.md fix on PyPi
2014-11-03 09:14:41 +00:00
### v0.1.2
* critical setuptools fix
### v0.1.1
* change context name `editor` to `markdownx_editor` for better consistency
2014-11-01 22:13:25 +00:00
### v0.1.0
2014-11-01 21:02:31 +00:00
* init
# Notes
2014-11-03 15:52:01 +00:00
**django-markdownx** was inspired by great [django-images](https://github.com/mirumee/django-images) and [django-bootstrap-markdown](http://thegoods.aj7may.com/django-bootstrap-markdown/) packages.