Prose editor for the Django admin based on ProseMirror
Project description
Prose editor for the Django admin based on ProseMirror
About rich text editors
Copied from the django-content-editor documentation.
We have been struggling with rich text editors for a long time. To be honest, I do not think it was a good idea to add that many features to the rich text editor. Resizing images uploaded into a rich text editor is a real pain, and what if you’d like to reuse these images or display them using a lightbox script or something similar? You have to resort to writing loads of JavaScript code which will only work on one browser. You cannot really filter the HTML code generated by the user to kick out ugly HTML code generated by copy-pasting from word. The user will upload 10mb JPEGs and resize them to 50x50 pixels in the rich text editor.
All of this convinced me that offering the user a rich text editor with too much capabilities is a really bad idea. The rich text editor in FeinCMS only has bold, italic, bullets, link and headlines activated (and the HTML code button, because that’s sort of inevitable – sometimes the rich text editor messes up and you cannot fix it other than going directly into the HTML code. Plus, if someone really knows what they are doing, I’d still like to give them the power to shot their own foot).
If this does not seem convincing you can always add your own rich text plugin with a different configuration (or just override the rich text editor initialization template in your own project). We do not want to force our world view on you, it’s just that we think that in this case, more choice has the bigger potential to hurt than to help.
Installation
Install the package:
venv/bin/pip install django-prose-editor
Add django_prose_editor to INSTALLED_APPS:
INSTALLED_APPS = [
# ...
"django_prose_editor",
]
Replace models.TextField with ProseEditorField where appropriate:
from django_prose_editor.fields import ProseEditorField
class Project(models.Model):
description = ProseEditorField()
Note! No migrations will be generated when switching from and to models.TextField. That’s by design. Those migrations are mostly annoying.
Security
ProseMirror does a really good job of only allowing content which confirms to a particular scheme. Of course users can submit what they want, they are not constrainted by the HTML widgets you’re using. You should still always sanitize the HTML submitted on the server side. A good way to do this is by using the sanitize argument to the ProseEditorField. You can use the following snippet to always pass HTML through html-sanitizer:
from html_sanitizer.django import get_sanitizer
description = ProseEditorField(sanitize=get_sanitizer().sanitize)
Convenience
Sometimes it may be useful to show an excerpt of the HTML field; the ProseEditorField automatically adds a get_*_excerpt method to models which returns the truncated and stripped beginning of your HTML field’s content. The name would be Project.get_description_excerpt in the example above.
Customization
It’s not possible (yet), sorry.
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
Built Distribution
File details
Details for the file django_prose_editor-0.1.1.tar.gz
.
File metadata
- Download URL: django_prose_editor-0.1.1.tar.gz
- Upload date:
- Size: 76.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.24.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11cd2be95f61d1be43209bc0f8ba56ab45bce157591f9114b9a77b5aa1a51134 |
|
MD5 | 1609a94929cc10a0a2e8bd54e4b41c1a |
|
BLAKE2b-256 | 36a61b393c56cc8f952528dee9772f18126d50ca9475da969488645c725292d2 |
File details
Details for the file django_prose_editor-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: django_prose_editor-0.1.1-py3-none-any.whl
- Upload date:
- Size: 77.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.24.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4638a4b89f9a08dcdca9c82c3e9762d4dd16747aec750cc40e59d89733cc42a7 |
|
MD5 | c6db5b2b683e9fc36ece9d4f67a89f25 |
|
BLAKE2b-256 | 5b8cc052291196c041571f3176c0cdace3857183f3dba378635c3f01adf2ae3b |