Mixins

Mixins are configurations for Processors.

class typus.mixins.EnQuotes

Provides English quotes configutation for typus.processors.Quotes processor.

>>> en_typus('He said "\'Winnie-the-Pooh\' is my favorite book!".')
'He said “‘Winnie-the-Pooh’ is my favorite book!”.'
class typus.mixins.RuQuotes

Provides Russian quotes configutation for typus.processors.Quotes processor.

>>> ru_typus('Он сказал: "\'Винни-Пух\' -- моя любимая книга!".')
'Он сказал: «„Винни-Пух“ — моя любимая книга!».'
class typus.mixins.EnRuExpressions

This class holds most of Typus functionality for English and Russian languages. It works with typus.processors.Expressions.

expr_abbrs()

Adds narrow non-breakable space and replaces whitespaces between shorten words.

expr_apostrophe()

Replaces single quote with apostrophe.

>>> en_typus("She'd, I'm, it's, don't, you're, he'll, 90's")
'She’d, I’m, it’s, don’t, you’re, he’ll, 90’s'

Note

By the way it works with any omitted word. But then again, why not?

expr_complex_symbols()

Replaces complex symbols with Unicode characters. Doesn’t care about case-sensitivity and handles Cyrillic-Latin twins like c and с.

>>> en_typus('(c)(с)(C)(r)(R)...')
'©©©®®…'
Character map
± ® ©
<- -> +- or +− <= >= /= ==
(tm) (sm)
expr_del_positional_spaces()

Removes spaces before and after certain symbols.

expr_digit_spaces()

Replaces whitespace with non-breakable space after 4 (and less) length digits if word or digit without comma or math operators found afterwards: 3 apples 40 000 bucks 400 + 3 Skips: 4000 bucks 40 000,00 bucks

expr_linebreaks()

Converts line breaks to unix-style and removes extra breaks if found more than two in a row.

>>> en_typus('foo\r\nbar\n\n\nbaz')
'foo\nbar\n\nbaz'
expr_math()

Puts minus and multiplication symbols between pair and before single digits.

>>> en_typus('3 - 3 = 0')
'3 − 3 = 0'
>>> en_typus('-3 degrees')
'−3 degrees'
>>> en_typus('3 x 3 = 9')
'3 × 3 = 9'
>>> en_typus('x3 better!')
'×3 better!'

Important

Should run after mdash and phones expressions.

expr_mdash()

Replaces dash with mdash.

>>> en_typus('foo -- bar')  # adds non-breakable space after `foo`
'foo — bar'
expr_pairs()

Replaces whitespace with non-breakable space after 1-2 length words.

expr_phones()

Replaces dash with ndash in phone numbers which should be a trio of 2-4 length digits.

>>> en_typus('111-00-00'), en_typus('00-111-00'), en_typus('00-00-111')
('111–00–00', '00–111–00', '00–00–111')
expr_primes()

Replaces quotes with prime after digits.

>>> en_typus('3\' 5" long')
'3′ 5″ long'

Caution

Won’t break “4”, but fails with ” 4”.

expr_ranges()

Replaces dash with mdash in ranges. Supports float and negative values. Tries to not mess with minus: skips if any math operator or word was found after dash: 3-2=1, 24-pin. NOTE: _range_ should not have spaces between dash: 2-3 and left side should be less than right side.

expr_rep_positional_spaces()

Replaces whitespaces after and before certain symbols with non-breakable space.

expr_ruble()

Replaces руб and р (with or without dot) after digits with ruble symbol.

>>> en_typus('1000 р.')
'1000 ₽'

Caution

Drops the dot at the end of sentence if match found in there.

expr_spaces()

Trims spaces at the beginning and end of the line and remove extra spaces within.

>>> en_typus('   foo bar  ')
'foo bar'

Caution

Doesn’t work correctly with nbsp (replaces with whitespace).

expr_units()

Puts non-breakable space between digits and units.

>>> en_typus('1mm', debug=True), en_typus('1mm')
('1_mm', '1 mm')
expr_vulgar_fractions()

Replaces vulgar fractions with appropriate unicode characters.

>>> en_typus('1/2')
'½'