mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
FB2 Input: Add support for note and cite back references
FB2 Input: Add support for note and cite back references. Link pairs of type="note" and type="cite" now automatically generate the correct back reference. Fixes #1243714 [Fb2 return link is lost when converted to mobi or epub](https://bugs.launchpad.net/calibre/+bug/1243714)
This commit is contained in:
parent
3f6c88f0ae
commit
c20db472eb
@ -269,10 +269,15 @@
|
|||||||
</xsl:attribute>
|
</xsl:attribute>
|
||||||
<xsl:choose>
|
<xsl:choose>
|
||||||
<xsl:when test="(@type) = 'note'">
|
<xsl:when test="(@type) = 'note'">
|
||||||
|
<xsl:attribute name="link_note"></xsl:attribute>
|
||||||
<sup>
|
<sup>
|
||||||
<xsl:apply-templates/>
|
<xsl:apply-templates/>
|
||||||
</sup>
|
</sup>
|
||||||
</xsl:when>
|
</xsl:when>
|
||||||
|
<xsl:when test="(@type) = 'cite' and @id">
|
||||||
|
<xsl:attribute name="link_cite"><xsl:value-of select="@id"/></xsl:attribute>
|
||||||
|
<xsl:apply-templates/>
|
||||||
|
</xsl:when>
|
||||||
<xsl:otherwise>
|
<xsl:otherwise>
|
||||||
<xsl:apply-templates/>
|
<xsl:apply-templates/>
|
||||||
</xsl:otherwise>
|
</xsl:otherwise>
|
||||||
|
@ -87,6 +87,25 @@ class FB2Input(InputFormatPlugin):
|
|||||||
|
|
||||||
transform = etree.XSLT(styledoc)
|
transform = etree.XSLT(styledoc)
|
||||||
result = transform(doc)
|
result = transform(doc)
|
||||||
|
|
||||||
|
# Handle links of type note and cite
|
||||||
|
notes = {a.get('href')[1:]: a for a in result.xpath('//a[@link_note and @href]') if a.get('href').startswith('#')}
|
||||||
|
cites = {a.get('link_cite'): a for a in result.xpath('//a[@link_cite]') if not a.get('href', '')}
|
||||||
|
all_ids = {x for x in result.xpath('//*/@id')}
|
||||||
|
for cite, a in cites.iteritems():
|
||||||
|
note = notes.get(cite, None)
|
||||||
|
if note:
|
||||||
|
c = 1
|
||||||
|
while 'cite%d' % c in all_ids:
|
||||||
|
c += 1
|
||||||
|
if not note.get('id', None):
|
||||||
|
note.set('id', 'cite%d' % c)
|
||||||
|
all_ids.add(note.get('id'))
|
||||||
|
a.set('href', '#%s' % note.get('id'))
|
||||||
|
for x in result.xpath('//*[@link_note or @link_cite]'):
|
||||||
|
x.attrib.pop('link_note', None)
|
||||||
|
x.attrib.pop('link_cite', None)
|
||||||
|
|
||||||
for img in result.xpath('//img[@src]'):
|
for img in result.xpath('//img[@src]'):
|
||||||
src = img.get('src')
|
src = img.get('src')
|
||||||
img.set('src', self.binary_map.get(src, src))
|
img.set('src', self.binary_map.get(src, src))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user