commonmark icon indicating copy to clipboard operation
commonmark copied to clipboard

Heading levels

Open eereeska opened this issue 2 years ago • 3 comments

Description

Please, add ability to control allowed heading levels such as CKEditor do

Example

It can be via config, similar to heading_permalink:

'heading_permalink' => [
    'min_heading_level' => 1,
    'max_heading_level' => 6,
],

To:

'headings' => [
    'min_level' => 2,
    'max_level' => 4,
],

So # H1 will became ## H2 & ###### H6 became #### H4 (closest allowed one)

Did this project help you today? Did it make you happy in any way?

Definitely love it ❤️

eereeska avatar Aug 05 '23 14:08 eereeska

bump

eereeska avatar Dec 19 '23 00:12 eereeska

Would this mean that e.g. with min_level=2 a heading with one asterisk # Head would be rendered as <h2>?

A use case that I often have is that a document with headings needs to be rendered both standalone (where it's headings would be as written) and also as subsections (where the headings would all be dropped down a level). Is that the sort of thing that this would accomplish?

samwilson avatar Mar 20 '24 07:03 samwilson

This suggestion makes sense to me.

I'd recommend we create a separate extension for it, perhaps called LimitHeadingsExtension or something similar. That extension could observe the DocumentParsedEvent and run some code to adjust the heading levels throughout the parsed AST.

Anyone interested in contributing this? 😉

colinodell avatar Apr 02 '24 19:04 colinodell