Add support for document-level configuration parameters in fence markers
Summary
Extend the fence marker system to support additional document-level configuration parameters beyond the currently implemented max-depth.
Current State
The plugin currently supports only one document-level parameter:
<!-- mtoc-start max-depth=2 -->
This allows documents to override the global headings.max_depth configuration.
Motivation
Users often need to customize TOC generation for specific documents without modifying their global configuration. Common scenarios include:
- Documents hosted on different platforms (GitHub vs GitLab) requiring different link formats
- Documents with different formatting standards (indentation, markers)
- Documents with specific headings to exclude
- Mixed repositories with varying style requirements
Proposed Configuration Parameters
High Priority
-
link-format- Override link formatting style- Example:
<!-- mtoc-start link-format=gitlab --> - Values:
gfm,gitlab,bitbucket,generic
- Example:
-
markers- Override list markers- Example:
<!-- mtoc-start markers=1. --> - Values:
*,-,+,1., or comma-separated for cycling
- Example:
-
exclude- Document-specific heading exclusion patterns- Example:
<!-- mtoc-start exclude=^TOC$,^Table.*Contents$ --> - Values: Comma-separated Lua patterns
- Example:
Medium Priority
-
before-toc- Include headings before TOC location- Example:
<!-- mtoc-start before-toc=true --> - Values:
true,false
- Example:
-
indent-size- Override indentation size- Example:
<!-- mtoc-start indent-size=4 --> - Values: Integer
- Example:
-
cycle-markers- Enable marker cycling- Example:
<!-- mtoc-start markers=*,+,- cycle-markers=true --> - Values:
true,false
- Example:
Low Priority
-
padding-lines- Blank lines before/after TOC- Example:
<!-- mtoc-start padding-lines=0 --> - Values: Integer
- Example:
Implementation Notes
The existing max-depth implementation (lua/mtoc/toc.lua:9-15, 229-244) provides a good pattern:
- Create parser functions like
parse_max_depth()for each parameter - Parse all parameters in
find_fences()and return them - Pass parameters to
gen_toc_list()to override config values - Use pattern:
value = fence_value or config.opts.section.value
Example multi-parameter fence:
<!-- mtoc-start max-depth=3 link-format=gitlab markers=1. indent-size=4 -->
Related Code
-
lua/mtoc/toc.lua:9-15-parse_max_depth()function -
lua/mtoc/toc.lua:229-244-find_fences()function -
lua/mtoc/toc.lua:284-387-gen_toc_list()function -
lua/mtoc/config.lua- Configuration defaults
Acceptance Criteria
-
Support multiple parameters in a single fence marker -
Parameters override global configuration without modifying it -
Maintain backward compatibility with existing max-depthparameter -
Update documentation with examples -
Add tests for parameter parsing