File: check_toc.py

package info (click to toggle)
fpdf2 2.8.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 53,860 kB
  • sloc: python: 39,487; sh: 133; makefile: 12
file content (15 lines) | stat: -rw-r--r-- 446 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 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, Table Of Contents will be broken'
            )