Allow block elements with id attributes to be targets of <a href>

This commit is contained in:
Kovid Goyal 2007-06-29 07:20:44 +00:00
parent 3cf2b17af5
commit 7325a69fe3

View File

@ -228,6 +228,9 @@ class HTMLConverter(object):
# sometimes there are unterminated comments # sometimes there are unterminated comments
(re.compile(r"<\s*style.*?>(.*?)<\/\s*style\s*>", re.DOTALL|re.IGNORECASE), (re.compile(r"<\s*style.*?>(.*?)<\/\s*style\s*>", re.DOTALL|re.IGNORECASE),
lambda match: match.group().replace('<!--', '').replace('-->', '')), lambda match: match.group().replace('<!--', '').replace('-->', '')),
# remove <p> tags from within <a> tags
(re.compile(r'<a.*?>.*?(<p.*?>)', re.DOTALL|re.IGNORECASE),
lambda match: match.group().replace(match.group(1), '')),
] ]
# Fix Baen markup # Fix Baen markup
BAEN_SANCTIFY = [(re.compile(r'<\s*[Aa]\s+id="p[0-9]+"\s+name="p[0-9]+"\s*>\s*<\/[Aa]>'), BAEN_SANCTIFY = [(re.compile(r'<\s*[Aa]\s+id="p[0-9]+"\s+name="p[0-9]+"\s*>\s*<\/[Aa]>'),
@ -933,8 +936,8 @@ class HTMLConverter(object):
['png', 'jpg', 'bmp', 'jpeg']: ['png', 'jpg', 'bmp', 'jpeg']:
self.process_image(path, tag_css) self.process_image(path, tag_css)
else: else:
text = self.get_text(tag) text = self.get_text(tag, limit=1000)
if not text: if not text.strip():
text = "Link" text = "Link"
self.add_text(text, tag_css) self.add_text(text, tag_css)
self.links.append(HTMLConverter.Link(self.current_para.contents[-1], tag)) self.links.append(HTMLConverter.Link(self.current_para.contents[-1], tag))
@ -1081,6 +1084,8 @@ class HTMLConverter(object):
self.end_current_para() self.end_current_para()
if tagname.startswith('h'): if tagname.startswith('h'):
self.current_block.append(CR()) self.current_block.append(CR())
if tag.has_key('id'):
self.targets[tag['id']] = self.current_block
elif tagname in ['b', 'strong', 'i', 'em', 'span', 'tt', 'big']: elif tagname in ['b', 'strong', 'i', 'em', 'span', 'tt', 'big']:
self.process_children(tag, tag_css) self.process_children(tag, tag_css)
elif tagname == 'font': elif tagname == 'font':