File: check_toc.py

package info (click to toggle)
fpdf2 2.8.7-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 114,352 kB
  • sloc: python: 50,410; sh: 133; makefile: 12
file content (16 lines) | stat: -rw-r--r-- 483 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Context: https://github.com/squidfunk/mkdocs-material/discussions/8252

from mkdocs.plugins import BasePlugin


class InvalidPageStructure(Exception):
    pass


class CheckTocPlugin(BasePlugin):
    def on_page_content(self, html, *, page, config, files):
        if len(page.toc) > 1:
            raise InvalidPageStructure(
                f'Page "{page.url}" has to many #top-level headings ({len(page.toc)}),'
                " Table Of Contents will be broken"
            )