phpmarkdownparsedown

PHP Parsedown get all headings


I use Parsedown for transforming my Markdown into HTML like:

$pd->text('# My First heading');

In want automatically use the first site heading (h1) as an entry for a custom menu. I already had a look into the source, but couldn't figure out a good way to get all headings.

Perhaps there is something in elements function. Does anyone has an idea to get all or at least the first heading.


Solution

  • Author of Parsedown here.

    You should be able to achieve this by creating an extension that overrides the blockHeader method. Basically, the overriding method should modify the result of the parent method.

    Have a look at the Parsedown wiki for more info.