GrahamCampbell / Laravel-Markdown

A CommonMark wrapper for Laravel
https://gjcampbell.co.uk/
MIT License
1.32k stars 139 forks source link

Best practice for configuring extensions #154

Closed extrabright closed 3 years ago

extrabright commented 3 years ago

I am trying to figure our what is the best way to customize a CommonMark extension. For example I want to add the Table of Contents Extenstion.

I added the class in the config file and it works great. However, I would like to customize it using the available options for this extension:

// Set your configuration
$config = [
    // Extension defaults are shown below
    // If you're happy with the defaults, feel free to remove them from this array
    'table_of_contents' => [
        'html_class' => 'table-of-contents',
        'position' => 'top',
        'style' => 'bullet',
        'min_heading_level' => 1,
        'max_heading_level' => 6,
        'normalize' => 'relative',
        'placeholder' => null,
    ],
];

Could you point me to the right direction?

xscode-auto-reply[bot] commented 3 years ago

Thanks for getting in touch. I'll get to your issue soon! :rocket:

For urgent issues and priority support, please visit https://xscode.com/grahamcampbell/Laravel-Markdown.

GrahamCampbell commented 3 years ago

Thanks for the question.

I am trying to figure our what is the best way to customize a CommonMark extension. For example I want to add the Table of Contents Extenstion.

The package you link to is not a table of contents extension, but a table exception. Moreover, both of them are dead, and should not be used. You should instead use the implementation of contents provided in the main https://github.com/thephpleague/commonmark package.

However, I would like to customize it using the available options for this extension:

  1. Add League\CommonMark\Extension\TableOfContents\TableOfContentsExtension::class to your markdown config file extension array.
  2. Add that config literally into the markdown.php config file you have.

The default looks something like:

image

You can literally just append your config to the end:

image