https://github.com/f213/richtypo.py
The only web typograph that don't make a mess out of your text
https://github.com/f213/richtypo.py
english library python russian typography web
Last synced: 5 months ago
JSON representation
The only web typograph that don't make a mess out of your text
- Host: GitHub
- URL: https://github.com/f213/richtypo.py
- Owner: f213
- License: mit
- Archived: true
- Created: 2017-01-08T15:00:46.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2020-07-29T02:15:00.000Z (almost 6 years ago)
- Last Synced: 2025-12-07T22:47:33.999Z (6 months ago)
- Topics: english, library, python, russian, typography, web
- Language: Python
- Homepage:
- Size: 93.8 KB
- Stars: 8
- Watchers: 0
- Forks: 2
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Richtypo — the only web typograph tool that don't make a mess out of your text
Richtypo assumes that your text already has right dashes and quotes. The main concern is to add
non-breaking spaces to the right places.
This project is heavily inspired by Artem Sapegin's [richtypo](https://github.com/sapegin/richtypo.js/).
[](https://badge.fury.io/py/richtypo) [](https://travis-ci.org/f213/richtypo.py)
[](https://codecov.io/gh/f213/richtypo.py)
## Features
- Blazing fast, aimed for render-time usage.
- Native Russian support.
- HTML, Markdown and Plain-text aware, does not break your markup.
- Your text stays readable and indexable — richtypo does not produce HTML entities and other messy stuff.
- Easy integration with Jinja2, Django templates and any other language.
- Well tested Python3 and Python2 support. For py2 only unicode input is accepted.
- Easily extendable through smallest possible regular expressions defined in YAML with in-place specifications.
## Installation
```sh
pip install richtypo
```
## Usage
```python
from richtypo import Richtypo
r = Richtypo(ruleset='ru-lite')
well_done = r.richtypo(text)
```
### Jinja2 filter
```python
from richtypo.filter import filter
env = jinja2.Environment(
filters={
'richtypo': filter
}
)
```
Template:
```html
{{ text | richtypo('ru-lite') }}
```
### Django filter
```python
# your_app/templatetags/richtypo.py
from django import template
from django.template.defaultfilters import stringfilter
from django.utils.safestring import mark_safe
from richtypo.filter import filter as typograph
register = template.Library()
@register.filter
@stringfilter
def richtypo(value, ruleset='generic'):
return mark_safe(typograph(value, ruleset))
```
Template:
```html
{% load richtypo %}
{{ object.text | richtypo:"ru-lite"}}
```
## License
MIT