dokuwiki-plugin-dw2pdf icon indicating copy to clipboard operation
dokuwiki-plugin-dw2pdf copied to clipboard

Handling internal links

Open splitbrain opened this issue 1 month ago • 1 comments

@Klap-in I just stumbled upon code you added in 60e59de7:

https://github.com/splitbrain/dokuwiki-plugin-dw2pdf/blob/5da2fd39d25f9489291fdfeb61686f4613d5cbaa/renderer.php#L248-L254

The code here checks if a given link is in the list of currently exported pages. If so, it is rewritten to a PDF-Anchor.

However when exporting a PDF that consists of multiple pages (like a namespace or book creator export), each page is rendered separately and cached:

https://github.com/splitbrain/dokuwiki-plugin-dw2pdf/blob/5da2fd39d25f9489291fdfeb61686f4613d5cbaa/action.php#L396

So if a page was previously exported on it's own, it will be cached with only links to itself being rewritten. In a future namespace export, the cached result will be used.

Of course during development you will probably never notice, because you will nearly always purge all caches. And even in live systems you will only notice where page exports and namespace exports somehow overlap...

Anyway unless I miss something crucial, this has been subtly broken for about a decade now. I see these options to address this:

  1. keep the mechanism as is with it's subtle brokenness - I don't really like it, because it's wrong and not deterministic.
  2. only ever resolve links to the own page as PDF-internal - easiest to implement, but probably not what users expect
  3. do not cache individual page render results and only cache final PDFs - makes sense, but it means if only one page of a namespace changed all exported pages need to be re-rendered
  4. adjust the links not within the renderer, but in the rendered HTML output of the renderer - This probably means we have to parse HTML with regexp or maybe PHP's DOM parser (might increase minimum PHP version).

I feel like either 3 or 4 are the most sensible approaches. What do you think?

splitbrain avatar Nov 24 '25 14:11 splitbrain