namedentities / README.rst

Named HTML entities are much neater and much easier to comprehend than numeric entities. And because they fall within the ASCII range, they're much safer to use in multiple contexts than Unicode and its various encodings (UTF-8 and such).

This module helps convert from numerical HTML entites and Unicode characters that fall outside the normal ASCII range into named entities.

Usage

Python 2:

from namedentities import named_entities

u = u'both em\u2014and–dashes…'
print named_entities(u)

yields:

both em—and–dashes…

Python 3:

from namedentities import named_entities

u = 'both em\u2014and–dashes…'
print(named_entities(u))
# same result

Or using the six cross-version compatibility library, either one:

from namedentities import named_entities
import six

u = six.u('both em\u2014and–dashes…')
six.print_(named_entities(u))
# same result

Recent Changes

  • Repackaged as a Python package, rather than independent modules.
  • Now successfully packaged for, and tests against, against Python 2.5, 2.6, 2.7, 3.2, and 3.3, as well as PyPy 1.7 (based on 2.7.2). Mutomated multi-version testing managed with pytest and tox.

Notes

  • Doesn't attempt to encode <, >, or & (or their numerical equivalents) to avoid interfering with HTML escaping.
  • This is basically a packaging of Ian Beck's work. Thank you, Ian!

Installation

pip install namedentities

To easy_install under a specific Python version (3.3 in this example):

python3.3 -m easy_install namedentities

(You may need to prefix these with "sudo " to authorize installation.)

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.