Replace [TOC] markers with tables of contents in your exports


Here is a custom template based on “Styled HTML” that will substitute [TOC] markers with tables of contents (mostly for backward compatibility with SEv4).


<!DOCTYPE html>

  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="" />

{{#if pdf}}
<body class="stackedit stackedit--pdf">
<body class="stackedit">
  <div class="stackedit__html">{{#transformToc files.0.content.toc}}{{{files.0.content.html}}}{{/transformToc}}</div>



Handlebars.registerHelper('transformToc', function (toc, options) {
  var result = options.fn(this);
  var toc = '<div class="toc">' +, toc) + '</div>';
  return new Handlebars.SafeString(
    result.replace(/\[toc\]/gi, toc)

How to use the table of contents from the side bar?

Sorry to revive the topic, but here it returns an error:
TypeError: options.fn is not a function.

Is it normal?


Maybe you are not using the best approach to activate this mechanism
in the menu, go to Templates and add a new template, copy and paste the above Template and the above Helper, give a name to your template. (“Styled HML with TOC” is note the good one)
in your document source, add [TOC]
in the menu, export with your new template