Forum How do I...?

references to chapters (images) with complex counters

vivo
I have something like the following Css:

div.book { counter-reset: h1 h2 }
div.book h1 { counter-increment: h1; counter-reset: h2 }
div.book h2 { counter-increment: h2 }
div.book h1::before { content: counter(h1) " " }
div.book h2::before { 
    content: counter(h1) "." counter(h2) " "
}


Now I would like to create a cross reference to a chapter.
For references to a H1 chapter this is quite easy:

a[href]::after {
    content: " [See chapter " target-counter(attr(href), h1) "]"
}


But for references to chapters of "type" H2?
And what if I change a referenced chapter from H1 to H2 or vice versa?
mikeday
This should do the trick for referencing a H2 chapter:

a[href]::after {
    content: " [See chapter " target-counter(attr(href), h1) "." target-counter(attr(href), h2) "]"
}

However, this does require using a different cross-reference type depending on whether the link refers to a H1 or H2 chapter. The easiest way to manage this might be to create two different classes, and add a class attribute to each <a> element.

In the future, perhaps Prince could support a layer of indirection allowing this to be done automatically. For example, a new property could specify the cross-reference format on the element itself:

h1 { prince-xref-format: counter(h1) }
h2 { prince-xref-format: counter(h1) "." counter(h2) }

a[href]::after {
    content: " [See chapter " prince-xref(attr(href)) "]"
}

This example is purely hypothetical, as Prince does not support such a mechanism at this point, but it does seem that something like this would be useful to have.