Git Product home page Git Product logo

typogrify's Introduction

Typogrify GitHub Actions CI: continuous integration status PyPI Version

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:

python -m pip install typogrify

Requirements

Python 3.6 and above is supported. 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.

Development

To set up your development environment, first clone the project. Then create and activate a new virtual environment. From within the project, run:

python -m pip install invoke
invoke setup

Each time you make changes to Typogrify, there are two things to do regarding tests: check that the existing tests pass, and add tests for any new features or bug fixes. You can run the tests via:

invoke tests

In addition to running the test suite, it is important to also ensure that any lines you changed conform to code style guidelines. You can check that via:

invoke lint

typogrify's People

Contributors

aravindavk avatar barrysteyn avatar chrisdrackett avatar justinmayer avatar jyelloz avatar kwpolska avatar laurentb avatar mcepl avatar mintchaos avatar navilan avatar richleland avatar ubernostrum 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.