Skip to main content

A Python library for hyphenating HTML in your Django project

Project description

<pre><code> ___ _ _ _
___ ___| _| |_ ___| |_ _ _ ___| |_ ___ ___
|_ -| . | _| _|___| | | | . | | -_| |
|___|___|_| |_| |_|_|_ | _|_|_|___|_|_|
|___|_| </code></pre>

A Python library for hyphenating HTML in your Django project.

Repurposed from Filipe Fortes' "excellent AppEngine app":

h2. Features

* Use the <code>&shy;</code> "HTML entity": to hyphenate text. Works well with "text-align:justify;":
* Can be called as a function from inside Python code or as a filter in the Django template
* Supports more than 25 languages
* Supports Python 2.5, 2.6 and 2.7 and Django 1.0-1.4

h2. Getting started

Install it.

<pre><code>$ pip install django-softhyphen</code></pre>

Add it to the INSTALLED_APPS in your

<pre><code>INSTALLED_APPS = (

Use it in as a function.

<pre><code>>> from softhyphen.html import hyphenate
>>> hyphenate("<h1>I love hyphenation</h1>")
"<h1>I love hy&shy;phen&shy;a&shy;tion</h1>"
>>> # It is English by default, but you can provide another language.
>>> hyphenate("<h1>Me encanta guiones</h1>", language="es-es")
<h1>Me en&shy;can&shy;ta gu&shy;io&shy;nes</h1></code></pre>

Or use it as a template filter.

<pre><code>{% load softhyphen_tags %}
{{ text|softhyphen }}
{# You can specify another language as an argument. English is the default #}
{{ text|softhyphen:"es-es" }}</code></pre>

(Warning! Because of its overhead, the filter is not recommended in production if it needs to run each time the page loads.)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-softhyphen-0.15.tar.gz (1.0 MB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page