Skip to main content

Filters to enhance web typography, including support for Django & Jinja templates

Project description

Typogrify provides a set of custom filters that automatically apply various transformations to plain text in order to yield typographically-improved HTML. While often used in conjunction with Jinja and Django template systems, the filters can be used in any environment.

Installation

The following command will install via pip. Pay particular attention to the package name:

pip install typogrify

Alternatively, you can run the following command inside the project’s root directory:

python setup.py install

Last but not least, you can simply move the enclosed typogrify folder into your Python path.

Requirements

Python 2.3 and above is supported, including Python 3. The only dependency is SmartyPants, a Python port of a project by John Gruber.

Installing Jinja or Django is only required if you intend to use the optional template filters that are included for those frameworks.

Usage

The filters can be used in any environment by importing them from typogrify.filters:

from typogrify.filters import typogrify
content = typogrify(content)

For use with Django, you can add typogrify to the INSTALLED_APPS setting of any Django project in which you wish to use it, and then use {% load typogrify_tags %} in your templates to load the filters it provides.

Experimental support for Jinja is in typogrify.templatetags.jinja_filters.

Included filters

amp

Wraps ampersands in HTML with <span class="amp"> so they can be styled with CSS. Ampersands are also normalized to &amp;. Requires ampersands to have whitespace or an &nbsp; on both sides. Will not change any ampersand which has already been wrapped in this fashion.

caps

Wraps multiple capital letters in <span class="caps"> so they can be styled with CSS.

initial_quotes

Wraps initial quotes in <span class="dquo"> for double quotes or <span class="quo"> for single quotes. Works inside these block elements:

  • h1, h2, h3, h4, h5, h6

  • p

  • li

  • dt

  • dd

Also accounts for potential opening inline elements: a, em, strong, span, b, i.

smartypants

Applies SmartyPants.

typogrify

Applies all of the following filters, in order:

  • amp

  • widont

  • smartypants

  • caps

  • initial_quotes

widont

Based on Shaun Inman’s PHP utility of the same name, replaces the space between the last two words in a string with &nbsp; to avoid a final line of text with only one word.

Works inside these block elements:

  • h1, h2, h3, h4, h5, h6

  • p

  • li

  • dt

  • dd

Also accounts for potential closing inline elements: a, em, strong, span, b, i.

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

typogrify-2.0.1.tar.gz (7.5 kB view details)

Uploaded Source

File details

Details for the file typogrify-2.0.1.tar.gz.

File metadata

  • Download URL: typogrify-2.0.1.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for typogrify-2.0.1.tar.gz
Algorithm Hash digest
SHA256 14241121dd2b2d34b750d3c405f827abe0c29b2955372147c6ed776cb9cf2c95
MD5 4c91ce931567a2d9cd4674442a0afafa
BLAKE2b-256 c93548099930947d9118a92e07367fd57d764662e58f44b806e8a4a84e51277c

See more details on using hashes here.

Supported by

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