laravelmarkdowncommonmark

How to add id to headers in markdown commonmark php


I am using the laravel markdown extension https://github.com/GrahamCampbell/Laravel-Markdown

It is a wrapper for https://github.com/thephpleague/commonmark

Does anyone know what this would be called, or how do I enable the ability to add ids manually in markdown?

I came across this article, but the curly brackets don't work. https://uhded.com/add-id-header-markdown

# Header Exmaple {#header-example}

I want to add the anchor IDs to navigation to link to various sections of the documentation.

Any help or guidance on how I can go about making this would be much appreciated.


Solution

  • I just learned that this was something you need to enable in commonmark

    https://commonmark.thephpleague.com/2.2/extensions/attributes/

    You need to go to markdown.php file and add the attributes class

        'extensions' => [
            League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension::class,
            League\CommonMark\Extension\Table\TableExtension::class,
            League\CommonMark\Extension\Autolink\AutolinkExtension::class,
            Torchlight\Commonmark\V2\TorchlightExtension::class,
            League\CommonMark\Extension\ExternalLink\ExternalLinkExtension::class,
            League\CommonMark\Extension\TaskList\TaskListExtension::class,
            // attributes extension 
            League\CommonMark\Extension\Attributes\AttributesExtension::class,
        ],