Forum How do I...?

...get cross-references to work? :(


first off, i want to say that prince is amazing. as soon as i get everything figured out and working with my system, i'm going to stop using the demo buy the full version. amazing software from what i've seen so far, keep up the good work.

on to the problem...

i've generated a toc in the beginning of my html document. the anchor links within the toc are relative (ie <a href="#example">example</a>) and my anchors are set correctly for the target (ie <a id="example" name="example">example should link here</a>). i'm also using generated content css of:

.toc a[href]::after { content: leader('. ') target-counter(attr(href), page); }

the problem is that when the content is generated in the pdf, the toc links all point to page 1, instead of the correct page. am i missing something?

thanks in advance.
I can only reproduce this problem when the element being referenced is an empty inline element, with no content, no padding and no border, like this:
<a id="chapter1"></a>

It appears that since an inline element with no content, padding or border has no effect on the document, it is being removed and is unavailable for linking. Adding some content to the element or linking to a block element instead is a suitable workaround, and we will fix the problem in a future release of Prince.

Thank you for reporting the issue! :)
i didn't even list that in my example :shock: good troubleshooting

but yes, that appears to be it, my inline anchor tags don't have any content.

looking forward to the next release :)
for anyone else having the problem, the solution was relatively easy..

did a regex-replace of '@<a(.*?)></a>@s' with '<a$1>&nbsp;</a>'
You mention in your example:

<a id="name">&nbsp;</a>

But don't anchors traditionally use the "name" attribute? My pages all use

<a name="name">&nbsp;</a>

However all references on my table of contents point to "page 0", despite my introduction of the non-breaking space.
Prince currently only supports the id attribute for links, because this is the recommended practice for XHTML. The id attribute can also occur on other elements, allowing paragraphs, headings or tables to be the target of a link without requiring empty anchor elements in the document at all.

However, traditional HTML does use the name attribute on anchor elements, so we will investigate adding support for this usage in a future release of Prince. Thanks for reporting the issue! :)