Package pology :: Package lang :: Package sr :: Module nobr

Module nobr

Equip text with no-break characters where possibly helpful.

The way text is wrapped in UI, by a general wrapping algorithm, is sometimes really not appropriate for Serbian ortography. For example, hyphen-separated case ending should not be wrapped. This module contains functions to heuristically replace ordinary with no-break characters, where such bad breaks can be expected.


Author: Chusslove Illich (Часлав Илић) <caslav.ilic@gmx.net>

License: GPLv3

Functions
(text) -> text
to_nobr_hyphens(mode=0, wchars='', unsafe=False)
Replace some ordinary hyphens with no-break hyphens [hook factory].
Variables
  nobrhyp_char = u''
  __package__ = 'pology.lang.sr'
Function Details

to_nobr_hyphens(mode=0, wchars='', unsafe=False)

 

Replace some ordinary hyphens with no-break hyphens [hook factory].

An ordinary hyphen is replaced in one of the following modes, as given by the mode parameter:

  • 0: if the hyphen is in between two letters, and either preceded or followed by at most four letters
  • 1: if the hyphen is in between two letters and followed by exactly one letter

Using the wchars parameter, some extra characters other than letters can be treated as equal to letters.

Note that the function by default substitutes the hyphen only if there are some Cyrillic letters (or an extra character) in the context, as otherwise the hyphen may be a part of URL, command, etc. This can be relaxed by setting unsafe to True, when all letters are treated equally.

Parameters:
  • mode (int) - replacement mode
  • wchars (string) - extra characters to consider parts of the word
  • unsafe (bool) - whether to replace hyphen even if no Cyrillic letters nearby
Returns: (text) -> text
type F1A hook