Given an HTML element of a known ID that potentially spans multiple pages (for example, a <section> element containing many paragraphs), is there any straightforward way to get the range of pages that it spans? Assuming that this range will never be non-consecutive, the page numbers of the first and last pages on which any part of that element appears would also suffice.
(A Javascript-based solution is fine, since it'll almost certainly require some scripting to correctly format the resulting page range anyway.)
Yes, the
box-tracking API allows you to find this information with JavaScript, and you can then log it to the console or feed it back into Prince for index-generation or what have you via a two-pass solution, let me know if you need any tips on this!
I see – so something like the attached would be the proper way to handle it?
(I may be overcomplicating things here; do an element's boxes have any guaranteed ordering, or is it necessary to assume – as my test code presently does – that the page numbers of the boxes may appear in any arbitrary order?)
- pagespantest.html 28.4 kB
Yep, that looks great!
The boxes should appear in document order, so you could just compare the first and last box, but being overly cautious doesn't do any harm in this case.
("document order" can get a bit complicated in the presence of page floats and footnotes, but should still at least be in page order).