Flayms / Markdown2Pdf

.NET library for converting markdown to PDF.
https://www.nuget.org/packages/Markdown2Pdf/
MIT License
5 stars 1 forks source link

The TOC have an unordered list item page #91

Open ABatenev opened 3 months ago

ABatenev commented 3 months ago

If I have an unordered list in the md file and it is followed by headers with the same names, then TOC takes the pages of the list, not the header. For example: Test.md Test.pdf

Flayms commented 3 months ago

The current code to detect the page numbers is really simple (and also inefficient), it creates the PDF, then searches for the names of the headers and saves the page numbers it finds: https://github.com/Flayms/Markdown2Pdf/blob/0ee3761590aa02aa12d5f9956d229a813e41bbde/Markdown2Pdf/Services/TableOfContentsCreator.cs#L103-L145

This obviously causes issues when the header names exist somewhere else in the PDF. I don't see an easy way to resolve this though, PDF analysis is quite difficult. It's difficult to know what on a page is a header or to which page a link is pointing.

I am open for ideas or PRs on a better way of handling this.