Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

counter-reset CSS property doesn't work properly with Bindery #16

Closed
teddybradford opened this issue Aug 14, 2017 · 13 comments
Closed

counter-reset CSS property doesn't work properly with Bindery #16

teddybradford opened this issue Aug 14, 2017 · 13 comments

Comments

@teddybradford
Copy link
Contributor

I'm trying to number figures [1,2,3,...] that resets each chapter, but can't use counter-reset properly with Bindery because each page is its own context.

Counter-increment in CSS 2.1 requires that its counter be within the scope of the counter-reset, otherwise "implementations should behave as though a 'counter-reset' had reset the counter to 0"

Do you have any ideas on how to accomplish this with Bindery?

@evnbr
Copy link
Owner

evnbr commented Aug 15, 2017

Wow I didn't even know CSS counters were a thing. I did special-case <ol> numbering, but looks like there's no easy way for js to get the value of counters (or even read pseudo elements).

I will look into this in a bit. Ideally, bindery could move the counters up a level to some wrapper element around the pages and you wouldn't have to do anything. If not, you'd have to use counters in html or javascript or jekyll or something...

@evnbr
Copy link
Owner

evnbr commented Aug 15, 2017

okay, it does look like moving the counter up a level could work. Can you share exactly how you're using them? You aren't using any fancy nested counters, are you?

@evnbr
Copy link
Owner

evnbr commented Aug 15, 2017

more simply, you could apply the css counter to the document rather than an element that gets split. would that work?

@teddybradford
Copy link
Contributor Author

The way I'm trying to implement the counters, which works in a normal HTML page flow (aka, binderyjs disabled):

.post-header {
  counter-reset: figure;
}

figcaption {
  counter-increment: figure;
}

figcaption::before {
  content: "[ " counter(figure) " ] ";
}

At each .post-header, the counter resets, and adds the counter number at each figure with that has a figcaption.

With bindery enabled, the counter is always 1 for all figcaptions.

@evnbr
Copy link
Owner

evnbr commented Aug 16, 2017 via email

@teddybradford
Copy link
Contributor Author

teddybradford commented Aug 16, 2017

I need a class given to each div[.📖-spread-wrapper.📖-two-page-size] that contains a .post-header to accomplish what I'm trying to do; adding the counter-reset to the body works for the initial reset, but the .post-header counter-reset never resets for the figures outside the div context.

Is there a rule that lets you add a class to a page that contains an element?

@evnbr
Copy link
Owner

evnbr commented Aug 16, 2017

Ah i see, what a pain. At that point your hardly using css counters any more.

There could be, that sounds potentially useful. Then you could do things like 'don't put running headers on the first page of a chapter' or 'make the text white on full-bleed images' or something.

@teddybradford
Copy link
Contributor Author

teddybradford commented Aug 16, 2017

It would also allow you to style those sorts of things differently for certain pages, which could be pretty useful. (like if you wanted footers to use a different style for gallery pages)

@evnbr
Copy link
Owner

evnbr commented Aug 16, 2017

any ideas of what the api should be like? off the top of my head:
Bindery.PageContains({ selector: '.gallery', pageClass: 'gallery-page' })

@teddybradford
Copy link
Contributor Author

I think something like Bindery.AddClassToPage() makes more sense. Bindery.PageContains() sounds like it would return a boolean.

@evnbr
Copy link
Owner

evnbr commented Aug 23, 2017

@teddybradford Seems I misunderstood css counters. AddClassToPage wouldn't solve the css counter problem— bindery will add an arbitrary number of wrapper elements to create spreads and add crop marks, which would reset the counter again. You'd need something more like AddClassToOutermostWrapper, which would be confusing and change depending on your print settings.

In addition, any of those solutions break on booklet printing. The fundamental problem here is that bindery won't necessarily keep dom content in the same order that it started.

In the event I can't come up with a better alternative, what would you think about Bindery including its own counter? It could work like:

Bindery.Counter({
  selector: 'figcaption .number',
  reset: '. post-header',
  increment: 'figure',
  replace: function(element, counterNumber) {
    element.textContent = counterNumber;
    return element;
  }
});

@teddybradford
Copy link
Contributor Author

Ah, I see. A counter function like that looks like it would work, though!

@evnbr evnbr closed this as completed in 7ca3332 Sep 6, 2017
@evnbr
Copy link
Owner

evnbr commented Sep 6, 2017

Example: https://evanbrooks.info/bindery/examples/10_counters/
Docs: https://evanbrooks.info/bindery/docs/#counter

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants