mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
E-book viewer: Tighten heuristic used to detect footnote links. Do not consider a link that is the only content inside a block level tag as an endnote link, even if it is linked back to from its destination.
This commit is contained in:
parent
34ed37dceb
commit
aa0b0a197b
@ -40,6 +40,16 @@ get_epub_type = (node, possible_values) ->
|
|||||||
break
|
break
|
||||||
return epub_type
|
return epub_type
|
||||||
|
|
||||||
|
get_containing_block = (node) ->
|
||||||
|
until node?.tagName?.toLowerCase() in ['p', 'div', 'li', 'td', 'h1', 'h2', 'h2', 'h3', 'h4', 'h5', 'h6', 'body']
|
||||||
|
node = node.parentNode
|
||||||
|
if not node
|
||||||
|
break
|
||||||
|
return node
|
||||||
|
|
||||||
|
trim = (str) ->
|
||||||
|
return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '')
|
||||||
|
|
||||||
is_footnote_link = (node, url, linked_to_anchors) ->
|
is_footnote_link = (node, url, linked_to_anchors) ->
|
||||||
if not url or url.substr(0, 'file://'.length).toLowerCase() != 'file://'
|
if not url or url.substr(0, 'file://'.length).toLowerCase() != 'file://'
|
||||||
return false # Ignore non-local links
|
return false # Ignore non-local links
|
||||||
@ -68,7 +78,20 @@ is_footnote_link = (node, url, linked_to_anchors) ->
|
|||||||
eid = node.getAttribute('id') or node.getAttribute('name')
|
eid = node.getAttribute('id') or node.getAttribute('name')
|
||||||
if eid and linked_to_anchors.hasOwnProperty(eid)
|
if eid and linked_to_anchors.hasOwnProperty(eid)
|
||||||
# An <a href="..." id="..."> link that is linked back from some other
|
# An <a href="..." id="..."> link that is linked back from some other
|
||||||
# file in the spine, most likely a footnote
|
# file in the spine, most likely an endnote. We exclude links that are
|
||||||
|
# the only content of their parent block tag, as these are not likely
|
||||||
|
# to be endnotes.
|
||||||
|
cb = get_containing_block(node)
|
||||||
|
if not cb or cb.tagName.toLowerCase() == 'body'
|
||||||
|
return false
|
||||||
|
ltext = node.textContent
|
||||||
|
if not ltext
|
||||||
|
return false
|
||||||
|
ctext = cb.textContent
|
||||||
|
if not ctext
|
||||||
|
return false
|
||||||
|
if trim(ctext) == trim(ltext)
|
||||||
|
return false
|
||||||
return true
|
return true
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user