前提是你得有自己的服务器,代码是最新的~
修改

src/data/styledHtmlWithTocTemplate.html

源码改为:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{files.0.name}}</title>
<link rel="stylesheet" href="https://stackedit.io/style.css" />
</head>
{{#if pdf}}
<body class="stackedit stackedit--pdf">
{{else}}
<body class="stackedit">
{{/if}}
<div class="stackedit__html">{{#transformToc files.0.content.toc}}{{{files.0.content.html}}}{{/transformToc}}</div>
</body>
</html>

修改

src/services/templateWorker.js

增加一个helper:


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

重新编译:

npm run build

大功告成~

方法来自:https://community.stackedit.io/t/replace-toc-markers-with-tables-of-contents-in-your-exports/33

Related Posts: 自建StackEdit TOC失效的解决办法 :

留言

avatar