lintry

配置toc输出

1 "use strict"; 1 "use strict";
2 const fs = require('fs'); 2 const fs = require('fs');
3 3
4 +/**
5 + * 渲染md文件,输出html
6 + * @param opts 选项
7 + * @return {MarkdownIt}
8 + * @constructor
9 + *
10 + * opts:
11 + * toc: true/false 是否显示[TOC]
12 + * parseTokens: true/false 是否同时解析md输出结果tokens
13 + */
4 function MarkdownIt (opts) { 14 function MarkdownIt (opts) {
5 if (!(this instanceof MarkdownIt)) { 15 if (!(this instanceof MarkdownIt)) {
6 return new MarkdownIt(opts); 16 return new MarkdownIt(opts);
7 } 17 }
8 18
9 opts = opts || {}; 19 opts = opts || {};
10 - let plugin = require('markdown-it-github-toc').default;
11 -
12 - const md = require('markdown-it')(opts.options)
13 - .use(plugin, {
14 - anchorLinkSymbol: '¶'
15 - });
16 20
21 + const md = require('markdown-it')(opts.options);
22 + if (opts.toc) {
23 + md.use(require('markdown-it-github-toc').default, {
24 + anchorLinkSymbol: ''
25 + })
26 + }
17 this.renderFile = function (filename) { 27 this.renderFile = function (filename) {
18 if (!filename) { 28 if (!filename) {
19 throw new Error('filename can not be null!') 29 throw new Error('filename can not be null!')
......
...@@ -3,7 +3,7 @@ const app = express(); ...@@ -3,7 +3,7 @@ const app = express();
3 3
4 const config = require('./init/config'); 4 const config = require('./init/config');
5 5
6 -const mdview = new (require('./lib/mdview'))({parseTokens: true}), 6 +const mdview = new (require('./lib/mdview'))({parseTokens: true, toc: true}),
7 path = require('path'); 7 path = require('path');
8 8
9 const MARKDOWN_FILE_BASE = path.resolve(process.cwd(), config.md.base_path); 9 const MARKDOWN_FILE_BASE = path.resolve(process.cwd(), config.md.base_path);
......