kohheepeace / mr-pdf

Generate PDF for document website.
https://www.npmjs.com/package/mr-pdf
MIT License
125 stars 41 forks source link

TOC sub level does not have link to page #41

Open frank-mendez opened 2 years ago

frank-mendez commented 2 years ago

Table of Contents: only the first-level menu item actually has a hyperlink to the page, the sub-levels do not - is that a bug or by design? If it's not possible to hyperlink the sub-sections, then I'm not sure it makes much sense to have them listed in the TOC at all - it takes up 3 pages of the manual, has no page numbers nor links, so maybe better to only have the top level in the TOC

trijobe commented 2 years ago

In case its helpful to anyone in the interim: mr-pdf appears to find and remove elements matching the --excludeSelectors flag after inserting the PDF table of contents. So, in the interim while awaiting or proposing a fix, you can provide selectors that remove the broken entries based on the pattern used to create those entries. You might need to crawl the source if it changes, but the class names are currently toc-item-1, toc-item-2, and toc-item-3 for h1, h2, and h3 respectively.

npx mr-pdf --initialDocURLs="http://my-site/my-first-doc-page" --excludeSelectors=".pdf--hidden,.toc-item-3"
jean-humann commented 1 year ago

Hi @frank-mendez resolved in this PR from docs-to-pdf a fork of mr-pdf

hailaz commented 1 year ago

https://github.com/kohheepeace/mr-pdf/blob/master/src/utils.ts#L235

if (header.match(/id( )*=( )*"\S*"/g)) {
   return header.replace(/id( )*=( )*"\S*"/g, `id="${headerId}"`);
}

这里改一下可以修复