Metadata-Version: 2.1
Name: django-evade
Version: 0.2
Summary: A Django template filter to convert HTML literals into named, decimal, or hexadecimal forms
Home-page: https://github.com/richardcornish/django-evade
Author: Richard Cornish
Author-email: rich@richardcornish.com
License: BSD
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Classifier: Framework :: Django :: 2.2
Classifier: Framework :: Django :: 3.1
Classifier: Framework :: Django :: 3.2
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Description-Content-Type: text/x-rst
License-File: LICENSE

Django Evade
************

|PyPI version|_ |Build status|_

.. |PyPI version| image::
   https://badge.fury.io/py/django-evade.svg
.. _PyPI version: https://pypi.org/project/django-evade/

.. |Build status| image::
   https://api.travis-ci.com/richardcornish/django-evade.svg?branch=main
.. _Build status: https://app.travis-ci.com/github/richardcornish/django-evade

**Django Evade** is a `Django <https://www.djangoproject.com/>`_ `template filter <https://docs.djangoproject.com/en/dev/howto/custom-template-tags/>`_ application to pseudo-randomly convert literal HTML characters into equivalent `named <https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references>`_, `numeric, or hexadecimal <https://en.wikipedia.org/wiki/Numeric_character_reference>`_ HTML character entity references.

Useful for obscuring ``mailto`` hyperlinks to prevent spammers from collecting e-mail addresses. Inspired by a `Django snippet <https://djangosnippets.org/snippets/216/>`_, but rewritten to use the `Format Specification Mini-Language <https://docs.python.org/3/library/string.html#formatspec>`_. The result is a more severe form of |escape|_, leading to the name "evade."

.. |escape| replace:: ``escape``
.. _escape: https://docs.djangoproject.com/en/dev/ref/templates/builtins/#escape

* `Package <https://pypi.org/project/django-evade/>`_
* `Source <https://github.com/richardcornish/django-evade>`_
* `Documentation <https://django-evade.readthedocs.io/>`_
* `Tests <https://app.travis-ci.com/github/richardcornish/django-evade>`_

Install
=======

.. code-block:: bash

   $ pip install django-evade

Add to ``settings.py``.

.. code-block:: python

   INSTALLED_APPS = [
       # ...
       "evade",
   ]

Usage
=====

.. code-block:: django

   {% load evade_tags %}

   {{ "me@example.com"|evade }}

One possible result:

.. code-block:: html

   &#x006D;&#x065;&commat;&#x65;&#x78;&#x61;&#x6d;&#112;&#x6C;&#x65;&period;&#x63;&#111;&#x6D;

Note the use of named (``&commat;``), decimal (``&#112;``), hexadecimal lowercase (``&#x6d;``), and hexadecimal uppercase (``&#x6C;``) forms, and the varying length of zero fills (``&#x006D;``, ``&#x065;``). Each character entity reference is pseudo-randomized.

Can also be imported as a standalone Python module:

.. code-block:: python

   >>> from evade import evade
   >>> evade("©")
   '&copy;'
   >>> evade("©")
   '&#169;'
   >>> evade("©")
   '&#x0a9;'


