diff --git a/textile/core.py b/textile/core.py index d97f827e..045d9c95 100644 --- a/textile/core.py +++ b/textile/core.py @@ -56,33 +56,6 @@ def _normalize_newlines(string): return out -_glyph_defaults = { - 'quote_single_open': '‘', - 'quote_single_close': '’', - 'quote_double_open': '“', - 'quote_double_close': '”', - 'apostrophe': '’', - 'prime': '′', - 'prime_double': '″', - 'ellipsis': '…', - 'ampersand': '&', - 'emdash': '—', - 'endash': '–', - 'dimension': '×', - 'trademark': '™', - 'registered': '®', - 'copyright': '©', - 'half': '½', - 'quarter': '¼', - 'threequarters': '¾', - 'degrees': '°', - 'plusminus': '±', - 'fn_ref_pattern': '%(marker)s', - 'fn_foot_pattern': '%(marker)s', - 'nl_ref_pattern': '%(marker)s', -} - - class Textile(object): halign_re_s = r'(?:\<(?!>)|(?|\<\>|\=|[()]+(?! ))' valign_re_s = r'[\-^~]' @@ -121,6 +94,32 @@ class Textile(object): doctype_whitelist = ['xhtml', 'html5'] + glyph_definitions = { + 'quote_single_open': '‘', + 'quote_single_close': '’', + 'quote_double_open': '“', + 'quote_double_close': '”', + 'apostrophe': '’', + 'prime': '′', + 'prime_double': '″', + 'ellipsis': '…', + 'ampersand': '&', + 'emdash': '—', + 'endash': '–', + 'dimension': '×', + 'trademark': '™', + 'registered': '®', + 'copyright': '©', + 'half': '½', + 'quarter': '¼', + 'threequarters': '¾', + 'degrees': '°', + 'plusminus': '±', + 'fn_ref_pattern': '%(marker)s', + 'fn_foot_pattern': '%(marker)s', + 'nl_ref_pattern': '%(marker)s', + } + def __init__(self, restricted=False, lite=False, noimage=False, auto_link=False, get_sizes=False, html_type='xhtml'): """Textile properties that are common to regular textile and @@ -200,7 +199,7 @@ def __init__(self, restricted=False, lite=False, noimage=False, self.glyph_search_initial[4] = re.compile(r'(\S)"(?=\s|%s|$)' % self.pnct_re_s, re.U) - self.glyph_replace = [x % _glyph_defaults for x in ( + self.glyph_replace = [x % self.glyph_definitions for x in ( r'\1%(apostrophe)s\2', # apostrophe's r'\1%(apostrophe)s\2', # back in '88 r'\1%(quote_single_close)s', # single closing @@ -904,9 +903,9 @@ def fBlock(self, tag, atts, ext, cite, content): def formatFootnote(self, marker, atts='', anchor=True): if anchor: - pattern = _glyph_defaults['fn_foot_pattern'] + pattern = self.glyph_definitions['fn_foot_pattern'] else: - pattern = _glyph_defaults['fn_ref_pattern'] + pattern = self.glyph_definitions['fn_ref_pattern'] return pattern % {'atts': atts, 'marker': marker} def footnoteRef(self, text): diff --git a/textile/tests/__init__.py b/textile/tests/__init__.py index f3ba9858..a12056f8 100644 --- a/textile/tests/__init__.py +++ b/textile/tests/__init__.py @@ -590,3 +590,22 @@ def testHTML5(self): result = '\t
We use CSS.
' expect = textile.textile(test, html_type="html5") eq_(result, expect) + + +class SubclassingTests(): + """Test Textile subclassing ability.""" + def testChangeGlyphs(self): + class TextilePL(textile.Textile): + glyph_definitions = dict(textile.Textile.glyph_definitions, + quote_double_open = '„' + ) + + test = 'Test "quotes".' + expect = '\tTest „quotes”' + result = TextilePL().parse(test) + eq_(expect, result) + + # Base Textile is unchanged. + expect = '\t
Test “quotes”' + result = textile.textile(test) + eq_(expect, result)