From fe9f40e4a63b77d654f2742b32b7443445d0d42f Mon Sep 17 00:00:00 2001 From: John Schember Date: Sat, 28 Nov 2009 07:56:35 -0500 Subject: [PATCH] k and T code patches from WayneD. --- src/calibre/ebooks/pml/pmlconverter.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/calibre/ebooks/pml/pmlconverter.py b/src/calibre/ebooks/pml/pmlconverter.py index f4a959b3fc..ebb451a14b 100644 --- a/src/calibre/ebooks/pml/pmlconverter.py +++ b/src/calibre/ebooks/pml/pmlconverter.py @@ -36,6 +36,7 @@ class PML_HTMLizer(object): 't', 's', 'l', + 'k', 'T', 'Fn', 'Sd', @@ -67,6 +68,7 @@ class PML_HTMLizer(object): 'd': ('', ''), 'b': ('', ''), 'l': ('', ''), + 'k': ('', ''), 'FS': ('
', '
'), } @@ -91,6 +93,7 @@ class PML_HTMLizer(object): 'b': 'b', 'B': 'b', 'l': 'l', + 'k': 'k', 'Fn': 'a', 'Sd': 'a', 'FN': 'FS', @@ -107,6 +110,7 @@ class PML_HTMLizer(object): SPAN_STATES = [ 'l', + 'k', 'i', 'u', 'd', @@ -125,11 +129,11 @@ class PML_HTMLizer(object): pml = re.sub(r'(?mus).+?)">\s*(?P.*?)\s*', lambda match: '\\FN="fns-%s"%s\\FN' % (match.group('target'), match.group('text')) if match.group('text') else '', pml) pml = re.sub(r'(?mus).+?)">\s*(?P.*?)\s*', lambda match: '\\SB="fns-%s"%s\\SB' % (match.group('target'), match.group('text')) if match.group('text') else '', pml) - pml = prepare_string_for_xml(pml) - pml = re.sub(r'\\a(?P\d{3})', lambda match: '&#%s;' % match.group('num'), pml) pml = re.sub(r'\\U(?P[0-9a-f]{4})', lambda match: '%s' % my_unichr(int(match.group('num'), 16)), pml) + pml = prepare_string_for_xml(pml) + return pml def prepare_line(self, line): @@ -181,7 +185,7 @@ class PML_HTMLizer(object): if val[0]: if key == 'T': self.state['T'][0] = False - elif key in self.DIV_STATES: + if key in self.DIV_STATES: div.append(key) elif key in self.SPAN_STATES: span.append(key) @@ -238,6 +242,11 @@ class PML_HTMLizer(object): ss = [] if self.state[code][0]: + # Ignore multilple T's on the same line. They do not have a closing + # code. They get closed at the end of the line. + if code == 'T': + self.code_value(stream) + return text # Close all. for c in ss+ds: if self.state[c][0]: @@ -346,7 +355,7 @@ class PML_HTMLizer(object): text = self.process_code_simple('%s%s' % (c, l)) elif c == 'q': text = self.process_code_link(line) - elif c in 'crtTiIuobBl': + elif c in 'crtTiIuobBlk': text = self.process_code_div_span(c, line) elif c == 'm': empty = False @@ -384,7 +393,10 @@ class PML_HTMLizer(object): else: if c != ' ': empty = False - text = c + if self.state['k'][0]: + text = c.upper() + else: + text = c parsed.append(text) c = line.read(1)