You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: readium/shared/src/main/java/org/readium/r2/shared/publication/services/content/iterators/HtmlResourceContentIterator.kt
+29-11Lines changed: 29 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -158,12 +158,19 @@ class HtmlResourceContentIterator(
158
158
privateval elements = mutableListOf<Content.Element>()
159
159
privatevar startIndex =0
160
160
161
+
/** Segments accumulated for the current element. */
Copy file name to clipboardExpand all lines: readium/shared/src/test/java/org/readium/r2/shared/publication/services/content/iterators/HtmlResourceContentIteratorTest.kt
+84Lines changed: 84 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -455,4 +455,88 @@ class HtmlResourceContentIteratorTest {
455
455
iterator(html).elements()
456
456
)
457
457
}
458
+
459
+
@Test
460
+
fun`iterating over an element containing both a text node and child elements`() = runTest {
461
+
val html ="""
462
+
<?xml version="1.0" encoding="UTF-8"?>
463
+
<html xmlns="http://www.w3.org/1999/xhtml">
464
+
<body>
465
+
<ol class="decimal" id="c06-list-0001">
466
+
<li id="c06-li-0001">Let's start at the top—the <i>source of ideas</i>.
467
+
<aside><div class="top hr"><hr/></div>
468
+
<section class="feature1">
469
+
<p id="c06-para-0019"><i>While almost everyone today claims to be Agile, what I've just described is very much a <i>waterfall</i> process.</i></p>
470
+
</section>
471
+
Trailing text
472
+
</li>
473
+
</ol>
474
+
</body>
475
+
</html>
476
+
"""
477
+
478
+
assertEquals(
479
+
listOf(
480
+
TextElement(
481
+
locator = locator(
482
+
selector ="#c06-li-0001",
483
+
highlight ="Let's start at the top—the source of ideas."
484
+
),
485
+
role =TextElement.Role.Body,
486
+
segments =listOf(
487
+
Segment(
488
+
locator = locator(
489
+
selector ="#c06-li-0001",
490
+
highlight ="Let's start at the top—the source of ideas."
491
+
),
492
+
text ="Let's start at the top—the source of ideas.",
493
+
attributes = emptyList()
494
+
),
495
+
),
496
+
attributes = emptyList()
497
+
),
498
+
TextElement(
499
+
locator = locator(
500
+
selector ="#c06-para-0019",
501
+
before =" top—the source of ideas.\n",
502
+
highlight ="While almost everyone today claims to be Agile, what I've just described is very much a waterfall process."
503
+
),
504
+
role =TextElement.Role.Body,
505
+
segments =listOf(
506
+
Segment(
507
+
locator = locator(
508
+
selector ="#c06-para-0019",
509
+
before =" top—the source of ideas.\n",
510
+
highlight ="While almost everyone today claims to be Agile, what I've just described is very much a waterfall process."
511
+
),
512
+
text ="While almost everyone today claims to be Agile, what I've just described is very much a waterfall process.",
513
+
attributes = emptyList()
514
+
)
515
+
),
516
+
attributes = emptyList()
517
+
),
518
+
TextElement(
519
+
locator = locator(
520
+
selector ="#c06-para-0019",
521
+
before ="e just described is very much a waterfall process.\n\n",
522
+
highlight ="Trailing text"
523
+
),
524
+
role =TextElement.Role.Body,
525
+
segments =listOf(
526
+
Segment(
527
+
locator = locator(
528
+
selector ="#c06-para-0019",
529
+
before ="e just described is very much a waterfall process.\n",
0 commit comments