Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new option 'restart_increment_after' #33

Merged
merged 1 commit into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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