Giter VIP home page Giter VIP logo

django-softhyphen's Introduction

         ___ _       _           _
 ___ ___|  _| |_ ___| |_ _ _ ___| |_ ___ ___
|_ -| . |  _|  _|___|   | | | . |   | -_|   |
|___|___|_| |_|     |_|_|_  |  _|_|_|___|_|_|
                        |___|_|              

A Python library for hyphenating HTML in your Django project.

Repurposed from Filipe Fortes’ excellent AppEngine app.

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
  • Supports Python 2.5, 2.6 and 2.7 and Django 1.1-1.5

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

django-softhyphen's People

Contributors

palewire avatar epicserve avatar v-alexeev avatar streeter avatar dnx avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.