-
-
Notifications
You must be signed in to change notification settings - Fork 710
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
Named pages #57
Comments
Hi. |
Awesome! The cascade happens in At the moment we compute styles for every type of page in advance, but with named pages I think it should be more lazy: the layout code (as pages are generated) would call back into the cascade to ask for the style of a given page. (The cascade would cache that result.) During layout, wherever we look at Then, in Good luck, and do ask questions or help as much as you need. |
Are there any plans to implement this feature? |
Hi @psmolenski . I haven’t heard from @hejsan since the message above, so I’m not aware of anyone working on this at the moment. I will gladly provide guidance to anyone interested in working on this. |
Hi again.
Hope this helps, although I'd love to see named pages happen. |
@hejsan, your script works perfectly. However, I couldn't find a way to add page numbers, which would be consistent throughout the whole final document. Until now, I have been using CSS counters ( I've tried using I was wondering, whether you have any ideas how to add page numbering? |
@psmolenski , that is bug #93. It will also probably require clarification in the spec: https://www.w3.org/Style/CSS/Tracker/issues/334 |
I'm trying to format books for publishing including all the related complexities with initial chapters and the like. Using named pages seemed like the right way to implement it. I was trying to grok the code to understand the problem so I figured I'd ask questions and make sure my understanding is correct. Since
Also from the specification, the scope would be important because the "next" page is based on the last item on the page. That way if you have an item that sets a page followed by a second item with a different page, the second page is covered. <style>
.p1 { page: page-1; }
.p2 { page: page-2; }
</style>
<p class='p1'>On first page because no break</p>
<p class='p2'>
On first page because still no break, if this is the last
on the page, the next page will be page-2.
</p> So, I would guess that the way to implement this is to:
Using the above rules, from my understanding of the specification, I could do initial chapter pages like this. <style>
@page chapter-first {
/* No headers, high top margin */
}
@page chapter {
/* Headers, low chapter */
}
div.chapter h1 { page: chapter-first; }
div.chapter p { page: chapter; }
</style>
<div class='chapter'>
<h1>Chapter 1</h1>
<p>It was a dark and stormy night...</p>
</div>
<div class='chapter'>
<h1>Chapter 2</h1>
<p>It was the best of times, it was the worst...</p>
</div> Does this make sense or seem probable for the code? |
This seems wrong. A page break is introduced between elements with a different value for the https://drafts.csswg.org/css-page/#using-named-pages
|
You are correct, I missed that. I would then amend a step that automatically puts a I do believe the scope on Now, my chapter example is wrong but going over the specification, I suspect it can't be done without a vendor flag since there is no pseudo selector for "first page after a forced page break". |
The “high top margin” can be on the chapter title rather than on the page. But yes, I believe that css-page level 3 does not provide something flexible enough to inhibit a page-margin box on the first page in a chapter. The only thing I can think of is a huge hack like this to mask it with a white rectangle: .chapter > h1::before {
content: "";
position: absolute;
/* bottom of this pseudo-element is placed at:
100% of the page’s height from the page’s bottom
which is the page’s top. */
bottom: 100%;
height: 3cm; /* same a margin-top in @page */
width: 100%;
background: white;
} |
Or just create a vendor pseudo class ( Is the overall suggestion reasonable? |
@SimonSapin: That hack almost worked but it puts the box underneath the text and I can't use |
Of course, it's not closed (yet). |
It's closed now! If anyone is interested (@dmoonfire @hejsan @psmolenski), I'd like to know if it works for your use cases. I've added some unit tests and tried with real-life documents, it fits my needs (and the spec I hope). There is room for improvements, including tests with page names, pseudo classes and specificity (easy), less stupid code (easy) and lazy style loading (hard). Please ask for help if you want to fix that! I'll release 0.40 soon if nothing's bad for anyone here. |
@liZe thanks for your great work! We tested the named pages feature and it runs just wonderful! No problems discovered on our test cases. |
@liZe: I did a quick ad-hoc test for my purposes and the named pages work out very nicely. I was happy to see that the My hack was to render each chapter twice (leading chapter page and then the rest), then use With this, it looks like I only need to render stuff twice: once for the front matter which doesn't have page numbers, and once for the main matter using named pages. That should significantly reduce the generation time, thank you! |
Happy to see that this feature is helpful! @dmoonfire I'd love to have HTML and PDF samples of your books if possible, and find what's missing to generate them without |
@liZe: Let me update my The final result can be seen here, https://fedran.com/sand-and-bone/dmoonfire-100-02-sand-and-bone-1.0.1.pdf (my novel is CC-BY-NC-SA, so no trouble putting it online). If you want to D/L a version (and have Node), there is a full demo with only a few chapters at https://gitlab.com/mfgames-writing-js/example-frankenstein. Running For the most part, I just need I haven't checked to see if |
I think that, if supported, this would reset the counter to 1 on every single page of the group of pages that share that "name". You’d need either:
|
Since the The problem with |
css3-page defines "named pages": http://dev.w3.org/csswg/css3-page/#using-named-pages
The only non-trivial part of this is the cascade. Currently we compute in advance styles for every possible page. With named pages we might want to do this lazily.
The text was updated successfully, but these errors were encountered: