pagedjs: Significant whitespace removed after page breaks

Thank you for filling in this gap that browser vendors don’t seem to care about. ❤️

When a block is split across two pages, it looks like its content is copied without preserving white space. This becomes a problem if that block had white-space: pre style, for example when formatting code:

image

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 15 (2 by maintainers)

Commits related to this issue

Most upvoted comments

Hey @jods4 The 2.0 was mostly about footnotes and long overdue merge request. (and all the work we manage to put into paged.js is not enough to fix everything as quickly as we’d like).

we have a meeting scheduled with @fchasen to check what we’re gonna work on next. This issue is part of that talk

(We really wish we could be faster, but we’re doing our best here.)

I debugged a bit this issue and my conclusion is this:

  • Layout#renderTo() skips, by default, text nodes that (1) have only white-space and (2) are direct child nodes of a block (container) node. See nextSignificantNode, isIgnorable and isContainer.
  • PRE elements are deep copied by Layout#renderTo() (because PRE is not considered a “container”). This ensures the white-space is preserved as long as the PRE element doesn’t have to be split between print pages.
  • When a PRE element is split between print pages, the break token ends up inside the PRE element (in the source content). Layout#renderTo() then continues from the break token handling each child node of the PRE element individually, as if they were outside of the PRE, thus skipping white-space only text nodes.

The break token points to the source content where there is a single PRE element, unlike the rendered content that has multiple (as a result of the split). This is why we can’t put the break token for the next print page “before the PRE”. It needs to be inside the PRE. Thus the only option I see is to modify isIgnorable to take into account if the parent element has white-space preserved.