Skip to content

Commit

Permalink
Add syntax highlighting in README
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchainz committed Sep 28, 2021
1 parent 3bd6255 commit 52af3fa
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ Setup

pip install django-bleach

2. Add ``django-bleach`` to your ``INSTALLED_APPS``::
2. Add ``django-bleach`` to your ``INSTALLED_APPS``:

.. code-block:: python
INSTALLED_APPS = [
# ...
Expand All @@ -53,7 +55,9 @@ Setup
3. Select some sensible defaults for the allowed tags, attributes and styles;
and the behaviour when unknown tags are encountered. Each of these are
optional, and default to using the ``bleach`` defaults. See the
`bleach documentation`_::
`bleach documentation`_:

.. code-block:: python
# Which HTML tags are allowed
BLEACH_ALLOWED_TAGS = ['p', 'b', 'i', 'u', 'em', 'strong', 'a']
Expand All @@ -75,10 +79,12 @@ Setup
4. Select the default widget for bleach fields. This defaults to
``django.forms.Textarea``, but you will probably want to replace it with a
WYSIWYG editor, or something similar::
WYSIWYG editor, or something similar:

.. code-block:: python
# Use the CKEditorWidget for bleached HTML fields
BLEACH_DEFAULT_WIDGET = 'wysiwyg.widgets.WysiwygWidget'
BLEACH_DEFAULT_WIDGET = 'wysiwyg.widgets.WysiwygWidget'
I use `django-ckeditor`_ in my projects, but what you use is up to you.

Expand All @@ -90,7 +96,9 @@ In your models

``django-bleach`` provides three ways of creating bleached output. The simplest
way of including user-editable HTML content that is automatically sanitised is
by using the ``BleachField`` model field::
by using the ``BleachField`` model field:

.. code-block:: python
# in app/models.py
Expand Down Expand Up @@ -135,15 +143,19 @@ In your templates
*****************

If you have a piece of content from somewhere that needs to be printed in a
template, you can use the ``bleach`` filter::
template, you can use the ``bleach`` filter:

.. code-block:: django
{% load bleach_tags %}
{{ some_unsafe_content|bleach }}
If filter has no arguments it uses default settings defined in your
application settings. You can override allowed tags by specifying them
as a parameter to the filter::
as a parameter to the filter:

.. code-block:: django
{{ some_unsafe_content|bleach:"p,span" }}
Expand Down

0 comments on commit 52af3fa

Please sign in to comment.