Showing
8 changed files
with
256 additions
and
29 deletions
| ... | @@ -9,7 +9,7 @@ if (!target) { | ... | @@ -9,7 +9,7 @@ if (!target) { |
| 9 | process.exit(1); | 9 | process.exit(1); |
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | -const mdview = require('../lib/mdview')(), | 12 | +const mdview = new (require('../lib/mdview')), |
| 13 | path = require('path'); | 13 | path = require('path'); |
| 14 | 14 | ||
| 15 | const filename = path.resolve(process.cwd(), target); | 15 | const filename = path.resolve(process.cwd(), target); | ... | ... |
| 1 | "use strict"; | 1 | "use strict"; |
| 2 | const fs = require('fs'); | 2 | const fs = require('fs'); |
| 3 | 3 | ||
| 4 | -function MarkdownIt(opts) { | 4 | +function MarkdownIt (opts) { |
| 5 | if (!(this instanceof MarkdownIt)) { | 5 | if (!(this instanceof MarkdownIt)) { |
| 6 | return new MarkdownIt(opts); | 6 | return new MarkdownIt(opts); |
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | opts = opts || {}; | 9 | opts = opts || {}; |
| 10 | 10 | ||
| 11 | - var md = require('markdown-it')(opts.options); | 11 | + const md = require('markdown-it')(opts.options); |
| 12 | 12 | ||
| 13 | - this.renderFile = function(filename) { | 13 | + this.renderFile = function (filename) { |
| 14 | if (!filename) { | 14 | if (!filename) { |
| 15 | throw new Error('filename can not be null!') | 15 | throw new Error('filename can not be null!') |
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | - try{ | 18 | + let result; |
| 19 | - var content = fs.readFileSync(filename).toString(); | 19 | + try { |
| 20 | - var result = md.render(content); | 20 | + const content = fs.readFileSync(filename).toString(); |
| 21 | - } catch(e) { | 21 | + result = md.render(content); |
| 22 | + } catch (e) { | ||
| 22 | result = md.render(` | 23 | result = md.render(` |
| 23 | -## 404 | 24 | +# 404 |
| 24 | *文件找不到!* | 25 | *文件找不到!* |
| 25 | `) | 26 | `) |
| 26 | } | 27 | } | ... | ... |
md/alg.png
0 → 100644
1010 KB
md/readme.md
0 → 100644
| 1 | +# 标题:如何编写帮助文档(H1) | ||
| 2 | + | ||
| 3 | +> 每个描述目标简历一个子目录,在子目录下建立readme.md编写当前文档,本文档内需要的图片也存放在此目录下。 | ||
| 4 | + | ||
| 5 | +## 章节:文章的主要结构(H2) | ||
| 6 | + | ||
| 7 | +### 小节:针对每个章节的具体描述(H3) | ||
| 8 | + | ||
| 9 | +#### 段落:小节内需要分层次描述时使用(H4) | ||
| 10 | + | ||
| 11 | +##### 节点:段落内需要重点提出时(H5) | ||
| 12 | + | ||
| 13 | +正文:每个文件用一个H1作为标题,后续章节可以用到H2-H5 | ||
| 14 | + | ||
| 15 | +可以使用截图描述操作界面 | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | +对于需要特殊指出的词语可以使用`反引号` | ||
| 20 | + | ||
| 21 | +**或者使用粗体重点提醒** | ||
| 22 | + | ||
| 23 | +> *在引用内可以使用斜体* | ||
| 24 | + | ||
| 25 | +也可用列表描述 | ||
| 26 | + | ||
| 27 | +- 使用无序列表 | ||
| 28 | +- 使用有序列表 | ||
| 29 | + | ||
| 30 | + | ||
| 31 | + | ||
| 32 | +通常很少会用到表格 | ||
| 33 | + | ||
| 34 | +| 标题1 | 标题2 | 标题3 | | ||
| 35 | +| ---- | ---- | ---- | | ||
| 36 | +| 内容1 | | | | ||
| 37 | +| | 内容2 | | | ||
| 38 | +| | | 内容3 | | ||
| 39 | + | ||
| 40 | +中间可以用到分割线(HR) | ||
| 41 | + | ||
| 42 | +---- | ||
| 43 | + | ||
| 44 | +分割线的上下有足够的空间 | ||
| 45 | + |
| ... | @@ -41,7 +41,12 @@ Some of these words <em>are emphasized also</em>.</p> | ... | @@ -41,7 +41,12 @@ Some of these words <em>are emphasized also</em>.</p> |
| 41 | Or, if you prefer, <strong>use two underscores instead</strong>.</p> | 41 | Or, if you prefer, <strong>use two underscores instead</strong>.</p> |
| 42 | ``` | 42 | ``` |
| 43 | 43 | ||
| 44 | +---- | ||
| 45 | + | ||
| 46 | + | ||
| 47 | + | ||
| 44 | ### LISTS | 48 | ### LISTS |
| 49 | + | ||
| 45 | Unordered (bulleted) lists use asterisks, pluses, and hyphens (*, +, and -) as list markers. These three markers are interchangable; this: | 50 | Unordered (bulleted) lists use asterisks, pluses, and hyphens (*, +, and -) as list markers. These three markers are interchangable; this: |
| 46 | 51 | ||
| 47 | * Candy. | 52 | * Candy. | ... | ... |
| ... | @@ -14,8 +14,8 @@ | ... | @@ -14,8 +14,8 @@ |
| 14 | "author": "lintry <shenlin00@gmail.com>", | 14 | "author": "lintry <shenlin00@gmail.com>", |
| 15 | "license": "MIT", | 15 | "license": "MIT", |
| 16 | "dependencies": { | 16 | "dependencies": { |
| 17 | - "express": "^4.14.0", | 17 | + "express": "^4.16.2", |
| 18 | - "github-markdown-css": "^2.4.1", | 18 | + "github-markdown-css": "^2.10.0", |
| 19 | - "markdown-it": "^8.0.1" | 19 | + "markdown-it": "^8.4.0" |
| 20 | } | 20 | } |
| 21 | } | 21 | } | ... | ... |
| 1 | -var express = require('express') | 1 | +const express = require('express'); |
| 2 | -var app = express() | 2 | +const app = express(); |
| 3 | 3 | ||
| 4 | -const mdview = require('./lib/mdview')(), | 4 | +const mdview = new (require('./lib/mdview')), |
| 5 | path = require('path'); | 5 | path = require('path'); |
| 6 | 6 | ||
| 7 | -const MARKDOWN_FILE_BASE = process.cwd(); | 7 | +const MARKDOWN_FILE_BASE = path.resolve(process.cwd(), 'md'); |
| 8 | 8 | ||
| 9 | app.use(express.static(__dirname + '/themes')); | 9 | app.use(express.static(__dirname + '/themes')); |
| 10 | +app.use(express.static(MARKDOWN_FILE_BASE)); | ||
| 10 | 11 | ||
| 11 | -function sendTemplate(filename, theme) { | 12 | +function sendTemplate (filename, theme) { |
| 13 | + //默认md | ||
| 14 | + if (!filename || filename.match(/.+\/$/)) { | ||
| 15 | + filename = (filename || '') + 'readme.md' | ||
| 16 | + } | ||
| 12 | let file = path.resolve(MARKDOWN_FILE_BASE, filename); | 17 | let file = path.resolve(MARKDOWN_FILE_BASE, filename); |
| 13 | - var result = mdview.renderFile(file); | 18 | + if (!path.parse(file).ext) { |
| 14 | - theme = theme || 'github-markdown'; | 19 | + //追加后缀 |
| 20 | + file += '.md' | ||
| 21 | + } | ||
| 22 | + let result = mdview.renderFile(file); | ||
| 23 | + theme = theme || 'metro-lake'; | ||
| 15 | return ` | 24 | return ` |
| 16 | <!DOCTYPE html> | 25 | <!DOCTYPE html> |
| 17 | <html> | 26 | <html> |
| ... | @@ -31,17 +40,11 @@ function sendTemplate(filename, theme) { | ... | @@ -31,17 +40,11 @@ function sendTemplate(filename, theme) { |
| 31 | `; | 40 | `; |
| 32 | } | 41 | } |
| 33 | 42 | ||
| 34 | -app.get('/', function (req, res) { | 43 | +app.get('/**', function (req, res) { |
| 35 | - var query = req.query; | 44 | + let url = req.url, urls = url.match(/^\/([\/\w]+)/) || [], query = req.query; |
| 36 | - res.send(sendTemplate('readme.md', query.t)); | 45 | + res.send(sendTemplate(urls[1], query.t)); |
| 37 | -}) | ||
| 38 | - | ||
| 39 | -app.get('/*.md', function(req, res){ | ||
| 40 | - var url = req.url, urls = url.match(/^\/([\/\w]+\.md)/), query = req.query; | ||
| 41 | - res.send(sendTemplate(urls[1]||'404.md', query.t)); | ||
| 42 | - console.log(query) | ||
| 43 | }) | 46 | }) |
| 44 | 47 | ||
| 45 | const PORT = 3000; | 48 | const PORT = 3000; |
| 46 | -app.listen(PORT) | 49 | +app.listen(PORT); |
| 47 | console.info(`Server is started up by binding ${PORT}. Visit http://localhost:${PORT}`); | 50 | console.info(`Server is started up by binding ${PORT}. Visit http://localhost:${PORT}`); | ... | ... |
themes/metro-lake/metro-lake.css
0 → 100644
| 1 | +/*--------------------------------------------------- | ||
| 2 | + LESS Elements 0.9 | ||
| 3 | + --------------------------------------------------- | ||
| 4 | + A set of useful LESS mixins | ||
| 5 | + More info at: http://lesselements.com | ||
| 6 | + ---------------------------------------------------*/ | ||
| 7 | +/** | ||
| 8 | + * https://github.com/rhiokim/markdown-css | ||
| 9 | + * made by rhio.kim | ||
| 10 | + */ | ||
| 11 | +::before, ::after, * { | ||
| 12 | + box-sizing: border-box; | ||
| 13 | +} | ||
| 14 | + | ||
| 15 | +.metro-lake { | ||
| 16 | + font-family: system, -apple-system, BlinkMacSystemFont, | ||
| 17 | + "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "STHeiti", "SimSun", | ||
| 18 | + "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", 'Segoe UI', | ||
| 19 | + AppleSDGothicNeo-Medium, "Malgun Gothic", Verdana, Tahoma, "Helvetica Neue", Helvetica, Arial, sans-serif; | ||
| 20 | + padding: 0; | ||
| 21 | + color: #333; | ||
| 22 | + font-size: 0.875rem; | ||
| 23 | + background: #ffffff; | ||
| 24 | + -webkit-font-smoothing: antialiased; | ||
| 25 | + word-wrap: break-word; | ||
| 26 | + -webkit-hyphens: auto; | ||
| 27 | + -ms-hyphens: auto; | ||
| 28 | + hyphens: auto; | ||
| 29 | +} | ||
| 30 | + | ||
| 31 | +.metro-lake a { | ||
| 32 | + color: #3269a0; | ||
| 33 | +} | ||
| 34 | + | ||
| 35 | +.metro-lake a:hover { | ||
| 36 | + color: #4183c4; | ||
| 37 | +} | ||
| 38 | + | ||
| 39 | +.metro-lake blockquote { | ||
| 40 | + border-left: 2px solid #666; | ||
| 41 | + padding: 0 15px; | ||
| 42 | + font-style: italic; | ||
| 43 | + color: #777; | ||
| 44 | +} | ||
| 45 | + | ||
| 46 | +.metro-lake h1, | ||
| 47 | +.metro-lake h2, | ||
| 48 | +.metro-lake h3, | ||
| 49 | +.metro-lake h4, | ||
| 50 | +.metro-lake h5 { | ||
| 51 | + font-weight: 400; | ||
| 52 | + color: #444; | ||
| 53 | + letter-spacing: 2px; | ||
| 54 | +} | ||
| 55 | + | ||
| 56 | +.metro-lake h1 { | ||
| 57 | + text-align: center; | ||
| 58 | + line-height: 2rem; | ||
| 59 | + font-size: 2rem; | ||
| 60 | +} | ||
| 61 | + | ||
| 62 | +.metro-lake h2 { | ||
| 63 | + font-size: 1.4rem; | ||
| 64 | + border-bottom: 1px solid #bbb; | ||
| 65 | + line-height: 1.6rem; | ||
| 66 | + padding-bottom: 0.8rem; | ||
| 67 | + text-align: center; | ||
| 68 | +} | ||
| 69 | + | ||
| 70 | +.metro-lake h2:before { | ||
| 71 | + content: '══'; | ||
| 72 | + font-weight: 100; | ||
| 73 | + letter-spacing: -1px; | ||
| 74 | + padding-right: 1rem; | ||
| 75 | + color: #888 | ||
| 76 | +} | ||
| 77 | +.metro-lake h2:after { | ||
| 78 | + content: '══'; | ||
| 79 | + font-weight: 100; | ||
| 80 | + letter-spacing: -1px; | ||
| 81 | + padding-left: 1rem; | ||
| 82 | + color: #888 | ||
| 83 | +} | ||
| 84 | + | ||
| 85 | +.metro-lake blockquote h2:before { | ||
| 86 | + content: ''; | ||
| 87 | + padding-right: 0; | ||
| 88 | +} | ||
| 89 | + | ||
| 90 | +.metro-lake h5 { | ||
| 91 | + font-weight: bold; | ||
| 92 | +} | ||
| 93 | +.metro-lake h6 { | ||
| 94 | + color: #666; | ||
| 95 | +} | ||
| 96 | + | ||
| 97 | +.metro-lake hr { | ||
| 98 | + border-top: none; | ||
| 99 | + border-right: none; | ||
| 100 | + border-bottom: 1px solid; | ||
| 101 | + border-left: none; | ||
| 102 | + border-color: #ddd; | ||
| 103 | + margin: 10px 0 10px; | ||
| 104 | +} | ||
| 105 | + | ||
| 106 | +.metro-lake p { | ||
| 107 | + line-height: 1.5rem; | ||
| 108 | +} | ||
| 109 | + | ||
| 110 | +.metro-lake p > code { | ||
| 111 | + color: #777777; | ||
| 112 | + font-size: 15px; | ||
| 113 | + padding: 3px; | ||
| 114 | +} | ||
| 115 | + | ||
| 116 | +.metro-lake pre > code { | ||
| 117 | + font-size: 14px; | ||
| 118 | + letter-spacing: -1px; | ||
| 119 | + font-weight: normal; | ||
| 120 | +} | ||
| 121 | + | ||
| 122 | +.metro-lake strong { | ||
| 123 | + font-weight: 600; | ||
| 124 | +} | ||
| 125 | + | ||
| 126 | +.metro-lake table { | ||
| 127 | + width: 100%; | ||
| 128 | + background-color: #fafafa; | ||
| 129 | +} | ||
| 130 | + | ||
| 131 | +.metro-lake table tr th, | ||
| 132 | +.metro-lake table tr td { | ||
| 133 | + border: 1px solid #e6e6e6; | ||
| 134 | +} | ||
| 135 | + | ||
| 136 | +.metro-lake table tr:nth-child(2n) { | ||
| 137 | + background-color: #f2f2f2; | ||
| 138 | +} | ||
| 139 | + | ||
| 140 | +/** | ||
| 141 | + * after less | ||
| 142 | + */ | ||
| 143 | +/* | ||
| 144 | +.haroopad { | ||
| 145 | + | ||
| 146 | + img { | ||
| 147 | + .bordered(@border-color, @border-color, @border-color, @border-color); | ||
| 148 | + .rounded(3px); | ||
| 149 | + .box-shadow(0 0 7px darken(@border-color, 18%)); | ||
| 150 | + | ||
| 151 | + &:hover { | ||
| 152 | + -webkit-animation-duration: 1s; | ||
| 153 | + -webkit-animation-delay: .2s; | ||
| 154 | + .pulse; | ||
| 155 | + } | ||
| 156 | + } | ||
| 157 | + | ||
| 158 | + h1 { | ||
| 159 | + -webkit-animation-duration: .5s; | ||
| 160 | + -webkit-animation-delay: .2s; | ||
| 161 | + .tada; | ||
| 162 | + } | ||
| 163 | + | ||
| 164 | + &>ul { | ||
| 165 | + &>li { | ||
| 166 | + -webkit-animation-duration: .5s; | ||
| 167 | + -webkit-animation-delay: .2s; | ||
| 168 | + .fadeInLeft; | ||
| 169 | + } | ||
| 170 | + } | ||
| 171 | + | ||
| 172 | +} | ||
| 173 | +*/ |
-
Please register or login to post a comment