mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Tests for encoding with range wrappers
This commit is contained in:
parent
77e5bea56f
commit
5f0440364a
@ -213,6 +213,10 @@ def encode(doc, node, offset, tail):
|
|||||||
if not node.firstChild:
|
if not node.firstChild:
|
||||||
node.appendChild(document.createTextNode(''))
|
node.appendChild(document.createTextNode(''))
|
||||||
node = node.firstChild
|
node = node.firstChild
|
||||||
|
elif node.dataset.calibreRangeWrapper:
|
||||||
|
if not node.firstChild:
|
||||||
|
node.appendChild(document.createTextNode(''))
|
||||||
|
node = node.firstChild
|
||||||
if is_text_node(node):
|
if is_text_node(node):
|
||||||
offset = offset or 0
|
offset = offset or 0
|
||||||
if node.parentNode and node.parentNode.dataset.calibreRangeWrapper:
|
if node.parentNode and node.parentNode.dataset.calibreRangeWrapper:
|
||||||
|
@ -51,3 +51,22 @@ def cfi_roundtripping():
|
|||||||
assert_equal(decode(path_to_span), {'node': span})
|
assert_equal(decode(path_to_span), {'node': span})
|
||||||
assert_equal(encode(document, span.firstChild, 1), f'{path_to_span}/1:1')
|
assert_equal(encode(document, span.firstChild, 1), f'{path_to_span}/1:1')
|
||||||
assert_equal(decode(f'{path_to_span}/1:1'), {'node': span.firstChild, 'offset': 1})
|
assert_equal(decode(f'{path_to_span}/1:1'), {'node': span.firstChild, 'offset': 1})
|
||||||
|
|
||||||
|
|
||||||
|
@test
|
||||||
|
def cfi_with_range_wrappers():
|
||||||
|
document.body.appendChild(E.p('abc'))
|
||||||
|
p = document.body.firstChild
|
||||||
|
path_to_p = encode(document, p)
|
||||||
|
p.appendChild(E.span('def', data_calibre_range_wrapper='1'))
|
||||||
|
rw1 = p.lastChild
|
||||||
|
p.appendChild(document.createTextNode('123'))
|
||||||
|
assert_equal(encode(document, p.firstChild, 1), f'{path_to_p}/1:1')
|
||||||
|
assert_equal(encode(document, rw1), f'{path_to_p}/1:3')
|
||||||
|
assert_equal(encode(document, rw1.firstChild, 1), f'{path_to_p}/1:4')
|
||||||
|
assert_equal(encode(document, p.lastChild, 1), f'{path_to_p}/1:7')
|
||||||
|
p.appendChild(E.span('456', E.i('789'), data_calibre_range_wrapper='2'))
|
||||||
|
assert_equal(encode(document, p.lastChild.firstChild, 1), f'{path_to_p}/1:10')
|
||||||
|
itag = p.querySelector('i')
|
||||||
|
assert_equal(encode(document, itag), f'{path_to_p}/2')
|
||||||
|
assert_equal(encode(document, itag.firstChild, 2), f'{path_to_p}/2/1:2')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user