Skip to content

Commit

Permalink
Merge branch 'master' of github.com:timvink/mkdocs-enumerate-headings…
Browse files Browse the repository at this point in the history
…-plugin
  • Loading branch information
timvink committed Feb 20, 2023
2 parents 91ae3c6 + 53b1cc3 commit 69b2600
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,15 @@ plugins:
exclude:
- index.md
- another_page.md
restart_increment_after:
- second_section.md
```

- **`toc_depth`** (default `0`): Up to which level the table of contents should be enumerated as well. Default is 0, which means the TOC is not enumerated at all. Max is 6 (showing all enumeration)
- **`strict`** (default `true`): Raise errors instead of warnings when first heading on a page is not a level one heading (single `#`) and your MkDocs theme has not inserted the page title as a heading 1 for you. Note that in `strict: false` mode the heading numbers might be incorrect between pages and before and after a level 1 heading.
- **`increment_across_pages`** (default `true`): Increment the chapter number for each new page (in the order they appear in the navigation). If disabled, each page will start from 1.
- **`exclude`** (default *not specified*): Specify a list of page source paths (one per line) that should not have enumeration (excluded from processing by this plugin). This can be useful for example to remove enumeration from the front page. The source path of a page is relative to your `docs/` folder. You can also use [globs](https://docs.python.org/3/library/glob.html) instead of source paths. For example, to exclude `docs/subfolder/page.md` specify in your `mkdocs.yml` a line under `exclude:` with `- subfolder/page.md`
- **`restart_increment_after`** (default *not specified*): Specify a list of page source paths (one per line) where enumeration should be restarted. This can be useful if you have multiple reports or tutorials in one mkdocs site. Paths behave as with `exclude` (can use globs).

## Contributing

Expand Down
6 changes: 6 additions & 0 deletions mkdocs_enumerate_headings_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class EnumerateHeadingsPlugin(BasePlugin):
("strict", config_options.Type(bool, default=True)),
("toc_depth", config_options.Type(int, default=0)),
("increment_across_pages", config_options.Type(bool, default=True)),
("restart_increment_after", config_options.Type(list, default=[])),
("exclude", config_options.Type(list, default=[])),
)

Expand Down Expand Up @@ -117,6 +118,11 @@ def on_nav(self, nav, config, files, **kwargs):
if self.config.get('increment_across_pages') is False:
chapter_counter = 0

# Optionally reset the counter for this page
restarting_pages = self.config.get("restart_increment_after", [])
if exclude(page.file.src_path, restarting_pages):
chapter_counter = 0

# Some markdown files could be used multiple times in the same navigation
# This would lead to unique page instances, but we'd like to only use (count) the chapter
# of the first occurence.
Expand Down

0 comments on commit 69b2600

Please sign in to comment.