I wonder if it’s possible to have some kind of automatic headline list from my markdown text…
for example what i am trying to accomplish is, when writing a very long article with multiple h2, h3, h4 markdown tags to have an automated way to list some sort of index based on headlines so a viewer can jump right into the topic of choice.
so basically the script is reading the $page->text() field and identifies each
tag and generates a list with id hopping links towards each headline.
Yes, that is possible. The Kirby site uses this to display a table of contents above the docs pages.
The code that does this is the toc plugin. Every occurrence of (toc) inside your Kirbytext content will then be replaced dynamically. You can extend the plugin to work with h3 and h4.
The Kirbytext post filter needs access to the Kirbytext content. What you can do is to prepend the table of contents instead of replacing the placeholder inside the filter. Then you wouldn’t need the placeholder in the content.
If the table of contents needs to be somewhere else on the page, you can modify the function to be not a filter but a normal function and pass the rendered Kirbytext content as an argument manually.
That’s a good question that came to my mind too. I couldn’t figure it out although getkirby.com does have the id-attributes. They are not within the textfile, anyone an idea how they are generated? @sashtown?
Works perfectly for me, thank you @sashtown. @carstengrimm: Did you change the jquery selectors to match your html code? My headings are in .main-content not in .text so I changed the code. I added German Umlauts too: