alexandre-perrin / mkdocs-pandoc-plugin

The plugin is based on mkdocs-mk2pdf-plugin and aims to use pandoc as a generic engine to convert to many document format that pandoc suports.
https://github.com/HaoLiuHust/mkdocs-mk2pdf-plugin
MIT License
6 stars 3 forks source link

Maintain heading levels defined through mkdocs.yml #10

Open uniederer opened 1 month ago

uniederer commented 1 month ago

While testing your plugin, I came across the following problem:

If a mkdocs.yml file specifies a navigation structure with "empty" levels (as shown below), the structure is not maintained in the resulting PDF document.

nav:
  - Report Summary: summary.md
  - Weekly reports:
    - 2024:
      - September:
        - 2024.09.01: reports/2024.09.01.md
        - 2024.09.08: reports/2024.09.08.md

The expected behavior would be to have a chapter structure as follows:

Report Summary
Weekly reports
+- 2024
   +- September
      +- 2024.09.01
         +- <section structures as defined in the md-file>
      +- 2024.09.08
         +- <section structures as defined in the md-file>

However, the combined document uses the unmodified heading levels from each source document. As a result, the document's structure becomes inconsistent:

Report Summary
Weekly reports
2024.09.01
+- <section structures as defined in the md-file>
2024.09.08
+- <section structures as defined in the md-file>

This pull request provides a potential solution by altering the combining process in such a way, that the headings of the source files are aligned to their actual position in the structure of the document, based on the nav section of the configuration file. This is achieved by adding sufficient #-characters to the headings.

I've tested this proposal on my machine and it seems to solve the case outlined above. However, Python not being my primary programming language and me being even less familiar with MkDocs object model. it's defeinitely worth taking a closer look at the implementation and its impact. I'm pretty sure there is still room for improvement. Maybe its even worth considering to have this behaviour configurable.

I'm looking forward for your feedback, @alexandre-perrin .