resolves #220 reset the page counter once per unique element
We now reset the page counter only once per (unique) element using the the data-ref
attribute. I've introduced a Map to keep track of the elements for which the counter-reset
directive has already been taken into account.
For instance, in the following example, the page counter will be reset on the page 3 but not on page 4 (because the <main>
elements have the same data-ref=20c98495-1baa-4425-bacd-552a0f2c491a
):
<div class="pagedjs_page pagedjs_right_page" data-page-number="3" id="page-3" data-break-before="right" data-break-after="page">
<!-- ... -->
<main data-ref="20c98495-1baa-4425-bacd-552a0f2c491a"
data-after-page="frontmatter" data-break-before="right"
data-counter-page-reset="1"
data-counter-reset="page"
data-split-to="20c98495-1baa-4425-bacd-552a0f2c491a"
data-split-original="true"
data-last-split-element="true"
data-align-last-split-element="auto">
<section data-ref="4512cdb3-a506-48b2-84ff-3ead9ec30948" data-break-after="page">
<h2 data-ref="7e3c92ba-8314-488e-8b8a-81b8ec7c23ea">Section 1</h2>
</section>
</main>
<!-- ... -->
</div>
<!-- ... -->
<div class="pagedjs_page pagedjs_left_page" data-page-number="4" id="page-4" data-break-after="page">
<!-- ... -->
<main data-ref="20c98495-1baa-4425-bacd-552a0f2c491a"
data-after-page="frontmatter"
data-counter-page-reset="1"
data-counter-reset="page"
data-split-from="20c98495-1baa-4425-bacd-552a0f2c491a"
data-split-to="20c98495-1baa-4425-bacd-552a0f2c491a"
data-last-split-element="true"
data-align-last-split-element="auto">
<section data-ref="410b77eb-6b6d-483d-90af-2b1ad04bbda1" data-previous-break-after="page" data-break-after="page">
<h2 data-ref="f45b6d93-2f12-40c7-9500-c68ad494359b">Section 2</h2>
</section>
</main>
<!-- ... -->
</div>
I guess another solution would be to remove the attribute data-counter-page-reset
on the "duplicated" elements but I wasn't sure when, where and how it should be done... but now that we have a test case with the expected behavior we can revisit the implementation if needed.
Also, I was a bit concerned about introducing unnecessary coupling between the chunker and the counter logic.
resolves #220 (closed)