Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Shenlin
/
markdown-view
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
lintry
2018-01-09 17:42:37 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
4e7108395f1a51e1a52165f16a7d8e5827cf7fb4
4e710839
1 parent
3e1a8bb3
配置toc输出
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
7 deletions
lib/mdview.js
server.js
lib/mdview.js
View file @
4e71083
"use strict"
;
const
fs
=
require
(
'fs'
);
/**
* 渲染md文件,输出html
* @param opts 选项
* @return {MarkdownIt}
* @constructor
*
* opts:
* toc: true/false 是否显示[TOC]
* parseTokens: true/false 是否同时解析md输出结果tokens
*/
function
MarkdownIt
(
opts
)
{
if
(
!
(
this
instanceof
MarkdownIt
))
{
return
new
MarkdownIt
(
opts
);
}
opts
=
opts
||
{};
let
plugin
=
require
(
'markdown-it-github-toc'
).
default
;
const
md
=
require
(
'markdown-it'
)(
opts
.
options
)
.
use
(
plugin
,
{
anchorLinkSymbol
:
'¶'
});
const
md
=
require
(
'markdown-it'
)(
opts
.
options
);
if
(
opts
.
toc
)
{
md
.
use
(
require
(
'markdown-it-github-toc'
).
default
,
{
anchorLinkSymbol
:
''
})
}
this
.
renderFile
=
function
(
filename
)
{
if
(
!
filename
)
{
throw
new
Error
(
'filename can not be null!'
)
...
...
server.js
View file @
4e71083
...
...
@@ -3,7 +3,7 @@ const app = express();
const
config
=
require
(
'./init/config'
);
const
mdview
=
new
(
require
(
'./lib/mdview'
))({
parseTokens
:
true
}),
const
mdview
=
new
(
require
(
'./lib/mdview'
))({
parseTokens
:
true
,
toc
:
true
}),
path
=
require
(
'path'
);
const
MARKDOWN_FILE_BASE
=
path
.
resolve
(
process
.
cwd
(),
config
.
md
.
base_path
);
...
...
Please
register
or
login
to post a comment