Skip to content

Fix #200 - Named page:first content:element ( ... ) is overwitten

Boris Budini requested to merge issue-200-named-page-first-content into main

Fix tools/pagedjs#200.

I made what I'll call an easy fix. But I don't think this is the best solution (explanation at the end).

This is based on the change made by the OP in its issue:

I've managed to find a fix but have no idea if it's the right way to sort it. In modules/generated-content/running-headers.js line:149 I changed:

if (parts[3] === "pagedjs_first_page" || parts[3].match(/pagedjs_[\w-]+_first_page/g) ) { // Added check for 1st named page

However, I changed 3 things:

  • His string.match(regexp) to a regexp.test(string), as it seems faster (~5-10%) after benchmarking;
  • The regexp itself, to ensure it matches exactly the pattern (from start to end, maybe overkill);
  • I removed the check for "pagedjs_first_page", as it seems like it is not possible to have this string as the last part when there are 4 parts (see the following code block, which is a log of some tests with selectors).
.pagedjs_page
.pagedjs_page.pagedjs_left_page
.pagedjs_page.pagedjs_right_page
.pagedjs_page.pagedjs_first_page
.pagedjs_page:nth-of-type(1)
.pagedjs_page.pagedjs_named_page.pagedjs_custom_page:nth-of-type(1)
.pagedjs_page.pagedjs_named_page.pagedjs_custom_page.pagedjs_custom_first_page // HERE
.pagedjs_page.pagedjs_named_page.pagedjs_custom_page.pagedjs_right_page
.pagedjs_page.pagedjs_named_page.pagedjs_custom_page.pagedjs_left_page

As you can see above, selecting @page custom:first gives "pagedjs_custom_first_page" as the last part. I think the problem comes from there: it was expected to give "pagedjs_first_page".

This is why I said that this fix may not be the best one. I think it would be better to check for a string that will stay the same for any named page (for example: "pagedjs_named_first_page"). But it means that we would need to change the part that creates the selectors we're reading in orderSelectors()/pageWeight(), and I have no clue of where this logic is located, how it works, or if it could break something (I assume this is done by css-tree?).

Merge request reports