Simple typographic tool for Python/Django.
from pypograph import Typograph
from pypograph import rules
typograph = Typograph([rules.QuoteRule, rules.DashRule])
typograph.typo('- Это "типограф"?') # -> '— Это «типограф»?'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': '“”'}),
]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'$ python -m unittest pypograph.tests