ToC with links and numbered headings
See original GitHub issueHello - first thank you a lot for this project. Amazing work and quality!
We are currently trying to get our TOC working again, which we used to generate in Apache FOP
- TOC for all header headings (using #652 and https://github.com/Kozea/WeasyPrint/issues/23#issuecomment-320909718 )
- Add level based indentation for TOC entries
- Ensure page numbers are correctly and prepend the toc
- Make a TOC entry link to its chapter
- Add the “numbering” to the header itself ( so Chapter A in the content is
1. ChapterA
andFirst Subchapter of A
is1.1 First Subchapter of A
Make a TOC entry link to its chapter
Since we use make_bookmark_tree
to extract all the bookmarks and target
seem to be the coordinates for the link, i’am yet not sure how to actually make this a valid <a href="#anchor">
based link ( or similar ). Any hints on that?
in write_pdf
i found
link_attribs = 'page={} pos=[{} {}]'.format(
page + 1, int(round(x * scale)),
int(round(y * scale)))
Which seem to be about what i need, but how is that used inside the toc? AFAICs it is used for the “outline page” ( MATA PAGE ) of the PDF
surface.add_outline(
levels.pop(), title, link_attribs,
cairo.PDF_OUTLINE_FLAG_OPEN if state == 'open' else 0)
But can i use this for the inline TOC somehow?
Add the “numbering” to the header itself
I’am not sure if that is possible at all. The bookmarks have been already generated at self.bookmarks
… not sure but i support this is done via _gather_links_and_bookmarks()
What would be the best way to add this numbering ( inline numbering ) for the chapters?
Thank you a lot!
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (6 by maintainers)
I think that we probably said everything that could be said for table of contents. Feel free to reopen if you have more questions about this!
You’re right. @speakASAP Could you please open a new issue?