Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A Python library for hyphenating HTML in your Django project

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 softhyphen
Octocat-spinner-32 .coveragerc
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 MANIFEST.in
Octocat-spinner-32 README.md
Octocat-spinner-32 quicktest.py
Octocat-spinner-32 requirements.txt
Octocat-spinner-32 scratch.py
Octocat-spinner-32 setup.py
Octocat-spinner-32 tox.ini
README.md
         ___ _       _           _
 ___ ___|  _| |_ ___| |_ _ _ ___| |_ ___ ___
|_ -| . |  _|  _|___|   | | | . |   | -_|   |
|___|___|_| |_|     |_|_|_  |  _|_|_|___|_|_|
                        |___|_|              

A Python library for hyphenating HTML in your Django project

Repurposed from Filipe Fortes' excellent AppEngine app.

Build Status PyPI version Coverage Status

Features

  • Use the ­ 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

Getting started

Install it.

$ pip install django-softhyphen

Add it to the INSTALLED_APPS in your settings.py

INSTALLED_APPS = (
    ...
    'softhyphen',
    ...
)

Use it in as a function.

>>> 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>

Or use it as a template filter.

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

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

Something went wrong with that request. Please try again.