Fix bug in ml classes where some tags were missed.

This commit is contained in:
John Schember 2009-05-26 17:41:46 -04:00
parent b92c2dc002
commit 1fd7c704d2
2 changed files with 47 additions and 45 deletions

View File

@ -98,25 +98,27 @@ class FB2MLizer(object):
return u'' return u''
tag = barename(elem.tag) tag = barename(elem.tag)
tag_count = 0
if tag == 'img': if tag == 'img':
fb2_text += '<image xlink:herf="#%s" />' % os.path.basename(elem.attrib['src']) fb2_text += '<image xlink:herf="#%s" />' % 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')
fb2_tag = TAG_MAP.get(tag, 'p') if fb2_tag and fb2_tag not in tag_stack:
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 tag_count += 1
fb2_text += '<%s>' % fb2_tag fb2_text += '<%s>' % style_tag
tag_stack.append(fb2_tag) tag_stack.append(style_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)
if hasattr(elem, 'text') and elem.text != None and elem.text.strip() != '':
fb2_text += elem.text fb2_text += elem.text
for item in elem: for item in elem:

View File

@ -153,39 +153,39 @@ class PMLMLizer(object):
#if style['page-break-before'] == 'always': #if style['page-break-before'] == 'always':
# text += '\\p' # 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. # Proccess tags that contain text.
if hasattr(elem, 'text') and elem.text != None and elem.text.strip() != '': 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) text += self.elem_text(elem, tag_stack)
for item in elem: for item in elem: