def test_placeable_punctuation(): assert (general.PunctuationPlaceable.parse( 'These, are not. Special: punctuation; marks! Or are "they"?') is None) assert general.PunctuationPlaceable.parse( "Downloading…")[1] == general.PunctuationPlaceable(["…"])
WHITESPACE_RE = re.compile('^ +| +$|[\r\n\t] +| {2,}') def fancy_spaces(text): """Highlight spaces to make them easily visible.""" def replace(match): fancy_space = '<span class="translation-space"> </span>' if match.group().startswith(' '): return fancy_space * len(match.group()) return match.group()[0] + fancy_space * (len(match.group()) - 1) return WHITESPACE_RE.sub(replace, text) PUNCTUATION_RE = general.PunctuationPlaceable().regex def fancy_punctuation_chars(text): """Wrap punctuation chars found in the ``text`` around tags.""" def replace(match): fancy_special_char = ('<span class="highlight-punctuation ' 'js-editor-copytext">%s</span>') return fancy_special_char % match.group() return PUNCTUATION_RE.sub(replace, text) @register.filter @stringfilter def fancy_highlight(text):
def test_placeable_punctuation(): assert general.PunctuationPlaceable.parse( u'These, are not. Special: punctuation; marks! Or are "they"?') is None assert general.PunctuationPlaceable.parse( u'Downloading…')[1] == general.PunctuationPlaceable([u'…'])