Skip to content

"counter-reset: page;" doesn't work properly with web publications #522

Closed

Description

@butameron

I want to exclude book cover pages from page counter.
To do this, I tried to use web publications json and set @page :first { reset-counter: page; } to second document, because vivliostyle doesn't support named pages. however this doesn't work as I expected.

Steps to Reproduce

Open Vivliostyle with #x=http://url/to/testbook.json:

testbook.json

{
    "@context": [
        "https://schema.org",
        "https://www.w3.org/ns/wp-context"
    ],
    "type": "Book",
    "dateModified": "",
    "readingOrder": [
        "./test.html",
        "./test2.html"
    ]
}

test.html

<html>
    <head>
        <style>
            @page {
                size: A4;
                            
                @top-left {
                    content: counter(page);
                }

            }
            div { page-break-after: always; }
        </style>
    </head>
    <body>
        <div>
            A
        </div>
        <div>
            B
        </div>
    </body>
</html>

test2.html

<html>
    <head>
        <style>
            @page {
                size: A4;
                            
                @top-left {
                    content: counter(page);
                }

            }
            @page :first {
                counter-reset: page;
            }

            div { page-break-after: always; }
        </style>
    </head>
    <body>
        <div>
            C
        </div>
        <div>
            D
        </div>
    </body>
</html>

Expected result

Page A: page counter value = 1
Page B: page counter value = 2
Page C: page counter value = 1
Page D: page counter value = 2

Actual result

Page A: page counter value = 1
Page B: page counter value = 2
Page C: page counter value = 3
Page D: page counter value = 4

Activity

  1. spring-raining commented on May 19, 2019

    @spring-raining
    Member

    Thank you for the reporting! The page seems to be a counter of entire of a book so that it's may not acceptable for describing a document-wise page counter. In an environment of Vivliostyle, by defining the new counter which likes below works fine:

    test2.html

    <html>
        <head>
            <style>
                @page {
                    size: A4;
                    counter-increment: doc-page;
                    @top-left {
                        content: counter(doc-page);
                    }
                }
                body {
                    counter-reset: doc-page;
                }
                div { page-break-after: always; }
            </style>
        </head>
        <body>
            <div>
                C
            </div>
            <div>
                D
            </div>
        </body>
    </html>

    Hoping this answer your question.

  2. MurakamiShinyu commented on May 19, 2019

    @MurakamiShinyu
    Member

    Thanks @butameron for reporting the issue and @spring-raining for giving us a good workaround.

    There are some problems on CSS Paged Media spec and Vivliostyle.js implementation.

    In the spec, First-page pseudo-class: :first is defined as

    The :first pseudo-class matches the first printed page of a document.

    However, this spec is not very clear, when the document is a web publication, whether the :first matches only the first page of the web publication or matches first page of each sub-document (HTML) in the web publication.

    Also it is not clear whether the Page-based counters are for a whole web publication or for each sub-document in the web publication.

    (The problem is that the CSS Paged Media specification is not considered for publications composed of multiple HTML documents.)

    In the Vivliostyle.js implementation, the :first matches only the first page of the web publication, and the page-based counters count consecutive pages in a whole web publication. Therefore, the page counter is not reset at the first page of the second document even when @page :first { reset-counter: page; } is specified.

  3. butameron commented on May 23, 2019

    @butameron
    Author

    @spring-raining Thank you. It works

  4. changed the title [-]"reset-counter: page;" doesn't work properly with web publications json[/-] [+]"reset-counter: page;" doesn't work properly with web publications[/+] on Aug 24, 2019
  5. changed the title [-]"reset-counter: page;" doesn't work properly with web publications[/-] [+]"counter-reset: page;" doesn't work properly with web publications[/+] on Feb 27, 2021
  6. MurakamiShinyu commented on Feb 27, 2021

    @MurakamiShinyu
    Member

    Now, Vivliostyle.js v2.5.0 supports the :nth() page selector.

    See #700 feat(core): Support the :nth() page selector

    You can use @page :nth(1) { counter-reset: page; } to reset the page counter at each or a specific document in web publications (multi-document publications).

    Tests:
    https://raw.githack.com/vivliostyle/vivliostyle.js/master/packages/core/test/files/index.html#Nth_page_selector

    (source: https://github.com/vivliostyle/vivliostyle.js/tree/master/packages/core/test/files/nth-page)

    I believe this issue is now resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions