From 1fd7c704d22efe67d50b5288131af74666df638b Mon Sep 17 00:00:00 2001 From: John Schember Date: Tue, 26 May 2009 17:41:46 -0400 Subject: [PATCH] Fix bug in ml classes where some tags were missed. --- src/calibre/ebooks/fb2/fb2ml.py | 30 ++++++++-------- src/calibre/ebooks/pml/pmlml.py | 62 ++++++++++++++++----------------- 2 files changed, 47 insertions(+), 45 deletions(-) diff --git a/src/calibre/ebooks/fb2/fb2ml.py b/src/calibre/ebooks/fb2/fb2ml.py index f10cf95e87..81600b9624 100644 --- a/src/calibre/ebooks/fb2/fb2ml.py +++ b/src/calibre/ebooks/fb2/fb2ml.py @@ -98,25 +98,27 @@ class FB2MLizer(object): return u'' tag = barename(elem.tag) + tag_count = 0 + if tag == 'img': fb2_text += '' % os.path.basename(elem.attrib['src']) - tag_count = 0 - if hasattr(elem, 'text') and elem.text != None and elem.text.strip() != '': - fb2_tag = TAG_MAP.get(tag, 'p') - if fb2_tag and fb2_tag not in tag_stack: + + fb2_tag = TAG_MAP.get(tag, 'p') + if fb2_tag and fb2_tag not in tag_stack: + tag_count += 1 + fb2_text += '<%s>' % fb2_tag + tag_stack.append(fb2_tag) + + # Processes style information + for s in STYLES: + style_tag = s[1].get(style[s[0]], None) + if style_tag: tag_count += 1 - fb2_text += '<%s>' % fb2_tag - tag_stack.append(fb2_tag) - - # Processes style information - for s in STYLES: - style_tag = s[1].get(style[s[0]], None) - if style_tag: - tag_count += 1 - fb2_text += '<%s>' % style_tag - tag_stack.append(style_tag) + fb2_text += '<%s>' % style_tag + tag_stack.append(style_tag) + if hasattr(elem, 'text') and elem.text != None and elem.text.strip() != '': fb2_text += elem.text for item in elem: diff --git a/src/calibre/ebooks/pml/pmlml.py b/src/calibre/ebooks/pml/pmlml.py index 01f777caae..2f2feeb981 100644 --- a/src/calibre/ebooks/pml/pmlml.py +++ b/src/calibre/ebooks/pml/pmlml.py @@ -153,39 +153,39 @@ class PMLMLizer(object): #if style['page-break-before'] == 'always': # text += '\\p' + pml_tag = TAG_MAP.get(tag, None) + if pml_tag and pml_tag not in tag_stack: + tag_count += 1 + text += '\\%s' % pml_tag + tag_stack.append(pml_tag) + + # Special processing of tags that require an argument. + # Anchors links + if tag in LINK_TAGS and 'q' not in tag_stack: + href = elem.get('href') + if href and '://' not in href: + if '#' in href: + href = href.partition('#')[2] + href = os.path.splitext(os.path.basename(href))[0] + tag_count += 1 + text += '\\q="#%s"' % href + tag_stack.append('q') + # Anchor ids + id_name = elem.get('id') + if id_name: + text += '\\Q="%s"' % os.path.splitext(id_name)[0] + + # Processes style information + for s in STYLES: + style_tag = s[1].get(style[s[0]], None) + if style_tag and style_tag not in tag_stack: + tag_count += 1 + text += '\\%s' % style_tag + tag_stack.append(style_tag) + # margin + # Proccess tags that contain text. if hasattr(elem, 'text') and elem.text != None and elem.text.strip() != '': - pml_tag = TAG_MAP.get(tag, None) - if pml_tag and pml_tag not in tag_stack: - tag_count += 1 - text += '\\%s' % pml_tag - tag_stack.append(pml_tag) - - # Special processing of tags that require an argument. - # Anchors links - if tag in LINK_TAGS and 'q' not in tag_stack: - href = elem.get('href') - if href and '://' not in href: - if '#' in href: - href = href.partition('#')[2] - href = os.path.splitext(os.path.basename(href))[0] - tag_count += 1 - text += '\\q="#%s"' % href - tag_stack.append('q') - # Anchor ids - id_name = elem.get('id') - if id_name: - text += '\\Q="%s"' % os.path.splitext(id_name)[0] - - # Processes style information - for s in STYLES: - style_tag = s[1].get(style[s[0]], None) - if style_tag and style_tag not in tag_stack: - tag_count += 1 - text += '\\%s' % style_tag - tag_stack.append(style_tag) - # margin - text += self.elem_text(elem, tag_stack) for item in elem: