mkdocs-exporter icon indicating copy to clipboard operation
mkdocs-exporter copied to clipboard

Automatically create a table of contents from headers in generated PDF

Open SteveBehm opened this issue 1 year ago • 3 comments
trafficstars

Hello

I am wondering if it is possible to automatically generate a table of contents (TOC) when a PDF is created based off of the headers in the markdown file that is being converted to PDF?

If not, would this be something considered as an enhancement to the plugin?

Thank you!

SteveBehm avatar Jun 10 '24 18:06 SteveBehm

Hello @SteveBehm,

Currently, this feature is not implemented but could definitely be an enhancement to the plugin.

adrienbrignon avatar Jun 10 '24 19:06 adrienbrignon

We'd very much appreciate a table of contents as well, especially for PDF's containing many (hundreds of) pages.

As a side note: This implementation of a PDF expert is creative and significantly better than all previously implementations I've seen, great work!

AloysA avatar Aug 15 '24 20:08 AloysA

Hi,

Using these, the table of contents can be generated by the existing Markdown extensions.

  • pagename.md:
---

[TOC]

<span class="page-break"></span>
  • mkdocs.yml, using the toc extension:
# Pages extensions
markdown_extensions:
  - toc:
      permalink: true
      title: Table of contents
      title_class: toc-title
      toc_depth: 2-3
  • custom.css, hiding the TOC on my web generation (but that's my use case):
.toc {
  display: none;
}

.toc-title {
  font-size: 1.5625em;   
  font-weight: 300;  
}
  • pdf.scss, showing the configured TOC in PDF generated documentation:
.page-break {
  display: none;
  page-break-after: always;
}

.toc {
  display: initial;
}
  • Example: https://radiandevcore.gitlab.io/tools/pre-commit-crocodile/index.pdf

AdrianDC avatar Oct 28 '24 21:10 AdrianDC