Print: link to page numbers

Question

Is there a way using TW to offer dynamic page numbers in the print version of a table of contents?

Background

If you view the print preview of http://scott.sauyet.com/Tiddlywiki/WIP/Charter/v8/ 1, you will see a table of contents that starts like this:


Those page numbers are at the moment, hard-coded. (As tiddler fields, not in HTML; we’re not barbarians here!) I would really like to have these autogenerated. While this is a static document, and I could live with the hardcoded versions; it means I’m really stuck with every layout decision I’ve made. I can’t change margins, font-size, etc, without risking having to redo these page numbers.

I would prefer do this with straight CSS. A 13-year old article from A List Apart shows a technique using target-counter:

a.xref:after {
  content: " (page " target-counter(attr(href, url), page) ")";
}

While that looks perfect and exactly what I need, when I tried it, it didn’t work. The reason, it turns out, is simple: target-counter has never been implemented in browsers. A List Apart got it to work because they were using a non-browser rendering engine that did offer such support. This used to be specified in the CSS Generated Content module, but has been dropped somewhere along the way.

I could try to import one of the two different CSS polyfill tools I’ve heard of. But they are both large and known to be buggy. They were both abandoned a decade ago. One author explained

I am no longer supporting this library for all the reasons I address in my post The Dark Side of Polyfilling CSS. If you choose to use this library, please make sure you read the post, so you fully understand the challenges and limitations involved in writing CSS polyfills.

If I did incorporate one of them, I would probably want to strip it down to a reasonable size, and then try to make it operate in my TW environment. It sounds like a great deal of work, with no promise of success at the end.

That’s why I’m wondering if anyone has faced this problem in TW, and if you had any success. Are there any TW techniques that would help with this? Even if you’ve tried and failed, I’d love to hear what you tried.

The Site

My Town’s Charter is online, but it’s only a scanned-image PDF. (In fact, the site is still pointing to the old version; at some point, I’m sure they’ll get around to updating it.) I really want the document to be searchable, link-able, and bookmark-able. I’ve taken it on myself to make a version where every Chapter, Section, Subsection, and Sub-subsection has its own URL, and are transcluded together into a single document.

This version was created by running OCR on that PDF, chopping the results into tiddlers, and wrapping a few templates around them. Because of the OCR and the cutting/pasting, there are likely still transcriptions errors, although I think there aren’t too many left. A little more information is in an earlier question.


Update: I just added another version, which cleans up the hard-coded page numbers, moving them from individual Section tiddlers into a common data dictionary. This should make manual maintenance easier, but it’s still a far cry from what I would like.


1A non-read-only version of the real site. In either of them you can toggle read-only mode with CTRL-SHIFT-/ or CTRL-SHIFT-1

1 Like

I have not the answer to your question, but I surprised with clever way you have included TOC before the first page! Nice solution :wink:

Thank you. :blush:

I was an early adopter of CSS. While I haven’t entirely kept up in recent years, I do find that I can come back to find useful ways of doing things with it.

… but there’s always something I can’t seem to do. Hence the current question.

1 Like