Skip to content

maxpoletaev/pypograph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Pypograph

Simple typographic tool for Python/Django.

Usage

from pypograph import Typograph
from pypograph import rules

typograph = Typograph([rules.QuoteRule, rules.DashRule])
typograph.typo('- Это "типограф"?') # -> '— Это «типограф»?'

Usage with Django

Add pypograph to INSTALLED_APPS and try:

{% load pypograph %}

{% typo %}
  <p>- Это "типограф"?</p>
{% endtypo %}

{% content|typo %}

You can configure rules by adding TYPOGRAPH_RULES into your setting.py:

TYPOGRAPH_RULES = [
    'pypograph.rules.DashRule',
    ('pypograph.rules.QuoteRule', {'quotes': '“”'}),
]

Сustom rules

from pypograph.rules import BaseRule
from pypograph import Typograph


class MyOwnRule(BaseRule):
    config = {
      'from': 'a',
      'to': 'b',
    }

    def process(self, text):
        return text.replace(self.config['from'], self.config['to'])


typograph = Typograph([MyOwnRule])
typograph.typo('abc') # -> 'bbc'

Testing

$ python -m unittest pypograph.tests

About

Simple typographic tool for Python/Django

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages