mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
When creating and using id assertions in CFI check that the ID is unique
This commit is contained in:
parent
b63ca39143
commit
d153d026e9
@ -238,7 +238,14 @@ def encode(doc, node, offset, tail):
|
|||||||
index -= 1
|
index -= 1
|
||||||
# Add id assertions for robustness where possible
|
# Add id assertions for robustness where possible
|
||||||
id = node.id
|
id = node.id
|
||||||
idspec = ('[' + escape_for_cfi(id) + ']') if id else ''
|
idspec = ''
|
||||||
|
if id:
|
||||||
|
try:
|
||||||
|
multiples = document.querySelectorAll('#' + id)
|
||||||
|
except:
|
||||||
|
multiples = None
|
||||||
|
if multiples and multiples.length < 2:
|
||||||
|
idspec = ('[' + escape_for_cfi(id) + ']')
|
||||||
cfi = '/' + index + idspec + cfi
|
cfi = '/' + index + idspec + cfi
|
||||||
node = p
|
node = p
|
||||||
|
|
||||||
@ -268,6 +275,11 @@ def node_for_path_step(parent, target, assertion):
|
|||||||
if assertion:
|
if assertion:
|
||||||
q = document.getElementById(assertion)
|
q = document.getElementById(assertion)
|
||||||
if q:
|
if q:
|
||||||
|
try:
|
||||||
|
multiples = document.querySelectorAll('#' + assertion)
|
||||||
|
except:
|
||||||
|
multiples = None
|
||||||
|
if multiples and multiples.length < 2:
|
||||||
return q
|
return q
|
||||||
is_element = target % 2 == 0
|
is_element = target % 2 == 0
|
||||||
target //= 2
|
target //= 2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user