question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ToC with links and numbered headings

See original GitHub issue

Hello - 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 and First Subchapter of A is 1.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:closed
  • Created 3 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
liZecommented, Aug 18, 2021

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!

0reactions
liZecommented, Jul 29, 2020

i would suggest creating a dedicated bug for this issue

You’re right. @speakASAP Could you please open a new issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To: Create a Clickable Table of Contents (TOC)
Under Styles at the top (when you are on the Home window in Word), click on Heading 1 (do this for each section...
Read more >
I want BOTH page numbers AND hyperlinks in my ToC - is that
Print Layout view will show the page numbers (and link each entry to the corresponding heading in the document).
Read more >
How to create a hyperlinked table of contents
Heading styles are numbered 1-9. The use of Heading 6 and 7 in the above sample is arbitrary. If you only have one...
Read more >
Create a table of contents link to relative pages in Word
In the Table of Contents dialog, keep Show page numbers, Right align page numbers and Use hyperlinks instead of page numbers options checked,...
Read more >
TOC Tips and Tricks - Suzanne S. Barnhill
The outline level of paragraphs in Word's built-in heading styles cannot be changed; if you look at the Paragraph dialog for a paragraph...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found