How can I automate placement of a link prior to each header in a markdown file?

I would like to have a link that points to a table of contents before every header in my markdown pages, but writing the following for each header is quite tedious:

<a class="button" href="#toc">&#9650;</a>
## A second level heading

What’s the simplest and cleanest way to automate this? CSS doesn’t allow HTML in content: fields.

Possibly Javascript would be the simplest way to add the TOC links as a progressive enhancement to the page.

Thanks for your reply, Chuck. I was hoping to do this without JavaScript.

I’ve seen an Jekyll injection example, but it seemed very complex for something that ought to be simple. I’ll find the link.


Another option might be to use a Liquid include as a macro for headers. For example (untested code):

{% include toclink.html content="## A second level heading" %}

toclink.html would be something like:

<a class="button" href="#toc">&#9650;</a>
{{ include.content | markdownify }}