Fix #1687 (1). Point links to the blocks containing their targets.

This commit is contained in:
Marshall T. Vandegrift 2009-01-29 13:39:45 -05:00
parent c362da37e2
commit 00518bad5a
2 changed files with 19 additions and 14 deletions

View File

@ -148,10 +148,6 @@ class MobiMLizer(object):
if bstate.pbreak: if bstate.pbreak:
etree.SubElement(body, MBP('pagebreak')) etree.SubElement(body, MBP('pagebreak'))
bstate.pbreak = False bstate.pbreak = False
if istate.ids:
for id in istate.ids:
etree.SubElement(body, XHTML('a'), attrib={'id': id})
istate.ids.clear()
bstate.istate = None bstate.istate = None
bstate.anchor = None bstate.anchor = None
parent = bstate.nested[-1] if bstate.nested else bstate.body parent = bstate.nested[-1] if bstate.nested else bstate.body
@ -186,14 +182,17 @@ class MobiMLizer(object):
wrapper.attrib['height'] = self.mobimlize_measure(vspace) wrapper.attrib['height'] = self.mobimlize_measure(vspace)
para.attrib['width'] = self.mobimlize_measure(indent) para.attrib['width'] = self.mobimlize_measure(indent)
elif tag == 'table' and vspace > 0: elif tag == 'table' and vspace > 0:
body = bstate.body
vspace = int(round(vspace / self.profile.fbase)) vspace = int(round(vspace / self.profile.fbase))
index = max((0, len(body) - 1))
while vspace > 0: while vspace > 0:
body.insert(index, etree.Element(XHTML('br'))) wrapper.addprevious(etree.Element(XHTML('br')))
vspace -= 1 vspace -= 1
if istate.halign != 'auto': if istate.halign != 'auto':
para.attrib['align'] = istate.halign para.attrib['align'] = istate.halign
if istate.ids:
last = bstate.body[-1]
for id in istate.ids:
last.addprevious(etree.Element(XHTML('a'), attrib={'id': id}))
istate.ids.clear()
pstate = bstate.istate pstate = bstate.istate
if tag in CONTENT_TAGS: if tag in CONTENT_TAGS:
bstate.inline = para bstate.inline = para

View File

@ -197,6 +197,7 @@ class Serializer(object):
def serialize_body(self): def serialize_body(self):
buffer = self.buffer buffer = self.buffer
self.anchor_offset = buffer.tell()
buffer.write('<body>') buffer.write('<body>')
# CybookG3 'Start Reading' link # CybookG3 'Start Reading' link
if 'text' in self.oeb.guide: if 'text' in self.oeb.guide:
@ -225,14 +226,17 @@ class Serializer(object):
or namespace(elem.tag) not in nsrmap: or namespace(elem.tag) not in nsrmap:
return return
tag = prefixname(elem.tag, nsrmap) tag = prefixname(elem.tag, nsrmap)
for attr in ('name', 'id'): # Previous layers take care of @name
if attr in elem.attrib: id = elem.attrib.pop('id', None)
href = '#'.join((item.href, elem.attrib[attr])) if id is not None:
self.id_offsets[href] = buffer.tell() href = '#'.join((item.href, id))
del elem.attrib[attr] offset = self.anchor_offset or buffer.tell()
if tag == 'a' and not elem.attrib \ self.id_offsets[href] = offset
and not len(elem) and not elem.text: if self.anchor_offset is not None and \
tag == 'a' and not elem.attrib and \
not len(elem) and not elem.text:
return return
self.anchor_offset = buffer.tell()
buffer.write('<') buffer.write('<')
buffer.write(tag) buffer.write(tag)
if elem.attrib: if elem.attrib:
@ -257,10 +261,12 @@ class Serializer(object):
if elem.text or len(elem) > 0: if elem.text or len(elem) > 0:
buffer.write('>') buffer.write('>')
if elem.text: if elem.text:
self.anchor_offset = None
self.serialize_text(elem.text) self.serialize_text(elem.text)
for child in elem: for child in elem:
self.serialize_elem(child, item) self.serialize_elem(child, item)
if child.tail: if child.tail:
self.anchor_offset = None
self.serialize_text(child.tail) self.serialize_text(child.tail)
buffer.write('</%s>' % tag) buffer.write('</%s>' % tag)
else: else: