<nav id="$idprefix$TOC" role="doc-toc">
$if(toc-title)$
<h2 id="$idprefix$toc-title">$toc-title$</h2>
$endif$
$table-of-contents$
</nav>
``````
or just the last line but one if you don't want the nav element and title. Save that to something like `gen-toc.html` and invoke pandoc with `--template=gen-toc.html` added. You might want to place the template in the templates subdirectory of your pandoc user directory (both of which you may have to create; see `pandoc --help` for where) so that you can use it from anywhere.