Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support and use Prince for Books #662

Merged
merged 7 commits into from
Jul 26, 2023
Merged

Support and use Prince for Books #662

merged 7 commits into from
Jul 26, 2023

Conversation

arthurattwell
Copy link
Member

In addition to some CSS fixes implemented during testing, this supports and implements using Prince for Books as the default Prince version for PDF output. This is associated with electricbookworks/node-prince#4.

One important change here is that we now pass the book's stylesheet to Prince as a 'user stylesheet'. The advantage of this is that Prince will apply the stylesheet to any SVGs referenced in the document with img src="*.svg". In previous Prince versions, it was already the case that the book's CSS would apply to SVGs. This had the advantage of letting us apply the parent document's fonts to SVGs. The potential downside of loading the styles as a user stylesheet is that this appears to replace (not just 'extend') the CSS loaded by style tags in the HTML. For our use case, this is fine since we only ever load one stylesheet, but in theory one could reference multiple stylesheets in HTML, which may then be ignored when we load a user stylesheet. I think this is worth it, given the importance of loading fonts correctly in SVGs, without having to define font styles and paths to font files in individual SVG files.

The current version of Prince for Books appears to be based on Prince 14. We may soon switch to Prince 15 instead, given its support for a proper @sidenotes area. There is not yet a Prince for Books based on Prince 15.

Since Prince 14 (including Prince for Books) SVGs referenced
with <img src""> do not have access to the parent doc's CSS.
This means they don't get the parent doc's fonts, which we
have depended on. It will be much more onerous and fragile to
try to have each SVG load its own fonts. So by loading the CSS
as a user style sheet like this, Prince will apply the CSS
to all documents including SVGs referenced with <img src="">.

I've also added some failsafes and simpler logging so that
Prince problems are easier to spot in the output logs.
This helps make clear that a variant should often
inherit the default styles, and then override them.
This change depends on support for Prince for Books
being implemented in node-prince:
electricbookworks/node-prince#4
@netlify
Copy link

netlify bot commented Jun 23, 2023

Deploy Preview for electric-book ready!

Name Link
🔨 Latest commit 32e553c
🔍 Latest deploy log https://app.netlify.com/sites/electric-book/deploys/64957622f5db4c00079ca85b
😎 Deploy Preview https://deploy-preview-662--electric-book.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@arthurattwell arthurattwell merged commit 32e553c into master Jul 26, 2023
8 checks passed
@arthurattwell arthurattwell deleted the prince-books branch July 26, 2023 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant