-
Notifications
You must be signed in to change notification settings - Fork 7
/
md-view.js
26 lines (23 loc) · 9.48 KB
/
md-view.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
'use strict';
var fs = require('fs');
var path = require('path');
var markdown = require('markdown-it')({
linkify: true,
typographer: true
});
var htmlHead = '<!DOCTYPE html><html><head><meta charset="utf-8"><title>',
htmlBody = '</title><style type="text/css">body{margin:0;padding:1em 2em}.markdown hr:after,.markdown hr:before{display:table;content:""}.markdown ol,.markdown td,.markdown th,.markdown ul{padding:0}@font-face{font-family:octicons-anchor;src:url(data:font/woff;charset=utf-8;base64,d09GRgABAAAAAAYcAA0AAAAACjQAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABGRlRNAAABMAAAABwAAAAca8vGTk9TLzIAAAFMAAAARAAAAFZG1VHVY21hcAAAAZAAAAA+AAABQgAP9AdjdnQgAAAB0AAAAAQAAAAEACICiGdhc3AAAAHUAAAACAAAAAj//wADZ2x5ZgAAAdwAAADRAAABEKyikaNoZWFkAAACsAAAAC0AAAA2AtXoA2hoZWEAAALgAAAAHAAAACQHngNFaG10eAAAAvwAAAAQAAAAEAwAACJsb2NhAAADDAAAAAoAAAAKALIAVG1heHAAAAMYAAAAHwAAACABEAB2bmFtZQAAAzgAAALBAAAFu3I9x/Nwb3N0AAAF/AAAAB0AAAAvaoFvbwAAAAEAAAAAzBdyYwAAAADP2IQvAAAAAM/bz7t4nGNgZGFgnMDAysDB1Ml0hoGBoR9CM75mMGLkYGBgYmBlZsAKAtJcUxgcPsR8iGF2+O/AEMPsznAYKMwIkgMA5REMOXicY2BgYGaAYBkGRgYQsAHyGMF8FgYFIM0ChED+h5j//yEk/3KoSgZGNgYYk4GRCUgwMaACRoZhDwCs7QgGAAAAIgKIAAAAAf//AAJ4nHWMMQrCQBBF/0zWrCCIKUQsTDCL2EXMohYGSSmorScInsRGL2DOYJe0Ntp7BK+gJ1BxF1stZvjz/v8DRghQzEc4kIgKw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bVltNikc2HTR7YKh9LBl9DADC0U/jLcBZDKrMhUBfQBvXRzLtFtjU9eNHKin0x5InTqb8lNpfKv1s1xHzTXRqgKzek/mb7nB8RZTCDhGEX3kK/8Q75AmUM/eLkfA+0Hi908Kx4eNsMgudg5GLdRD7a84npi+YxNr5i5KIbW5izXas7cHXIMAau1OueZhfj+cOcP3P8MNIWLyYOBuxL6DRylJ4cAAAB4nGNgYoAALjDJyIAOWMCiTIxMLDmZedkABtIBygAAAA==) format("woff")}.markdown{-webkit-text-size-adjust:100%;text-size-adjust:100%;color:#333;overflow:hidden;font-family:"Helvetica Neue",Helvetica,"Segoe UI",Arial,freesans,sans-serif;font-size:16px;line-height:1.6;word-wrap:break-word}.markdown strong{font-weight:700}.markdown h1{margin:.67em 0}.markdown img{border:0}.markdown input{color:inherit;margin:0;line-height:normal;font:13px/1.4 Helvetica,arial,nimbussansl,liberationsans,freesans,clean,sans-serif,"Segoe UI Emoji","Segoe UI Symbol"}.markdown html input[disabled]{cursor:default}.markdown input[type=checkbox]{box-sizing:border-box;padding:0}.markdown *{box-sizing:border-box}.markdown a{background-color:transparent;color:#4078c0;text-decoration:none}.markdown a:active,.markdown a:hover{outline:0;text-decoration:underline}.markdown hr:after{clear:both}.markdown blockquote{margin:0}.markdown h1,.markdown h2{padding-bottom:.3em;border-bottom:1px solid #eee}.markdown ol ol,.markdown ul ol{list-style-type:lower-roman}.markdown ol ol ol,.markdown ol ul ol,.markdown ul ol ol,.markdown ul ul ol{list-style-type:lower-alpha}.markdown dd{margin-left:0}.markdown code{font-family:Consolas,"Liberation Mono",Menlo,Courier,monospace}.markdown pre{font:12px Consolas,"Liberation Mono",Menlo,Courier,monospace;word-wrap:normal}.markdown .select::-ms-expand{opacity:0}.markdown .octicon{font:normal normal normal 16px/1 octicons-anchor;display:inline-block;text-decoration:none;text-rendering:auto;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.markdown .octicon-link:before{content:"\\f05c"}.markdown>:first-child{margin-top:0!important}.markdown>:last-child{margin-bottom:0!important}.markdown a:not([href]){color:inherit;text-decoration:none}.markdown .anchor{position:absolute;top:0;left:0;display:block;padding-right:6px;padding-left:30px;margin-left:-30px}.markdown .anchor:focus{outline:0}.markdown h1,.markdown h2,.markdown h3,.markdown h4,.markdown h5,.markdown h6{position:relative;margin-top:1em;margin-bottom:16px;font-weight:700;line-height:1.4}.markdown h1 .octicon-link,.markdown h2 .octicon-link,.markdown h3 .octicon-link,.markdown h4 .octicon-link,.markdown h5 .octicon-link,.markdown h6 .octicon-link{display:none;color:#000;vertical-align:middle}.markdown h1:hover .anchor,.markdown h2:hover .anchor,.markdown h3:hover .anchor,.markdown h4:hover .anchor,.markdown h5:hover .anchor,.markdown h6:hover .anchor{padding-left:8px;margin-left:-30px;text-decoration:none}.markdown h1:hover .anchor .octicon-link,.markdown h2:hover .anchor .octicon-link,.markdown h3:hover .anchor .octicon-link,.markdown h4:hover .anchor .octicon-link,.markdown h5:hover .anchor .octicon-link,.markdown h6:hover .anchor .octicon-link{display:inline-block}.markdown h1{font-size:2.25em;line-height:1.2}.markdown h1 .anchor{line-height:1}.markdown h2{font-size:1.75em;line-height:1.225}.markdown h2 .anchor{line-height:1}.markdown h3{font-size:1.5em;line-height:1.43}.markdown h3 .anchor,.markdown h4 .anchor{line-height:1.2}.markdown h4{font-size:1.25em}.markdown h5,.markdown h6{font-size:1em}.markdown h5 .anchor,.markdown h6 .anchor{line-height:1.1}.markdown h6{color:#777}.markdown blockquote,.markdown dl,.markdown ol,.markdown p,.markdown pre,.markdown table,.markdown ul{margin-top:0;margin-bottom:16px}.markdown hr{overflow:hidden;background:#e7e7e7;height:4px;padding:0;margin:16px 0;box-sizing:content-box;border:0}.markdown ol,.markdown ul{padding-left:2em}.markdown ol ol,.markdown ol ul,.markdown ul ol,.markdown ul ul{margin-top:0;margin-bottom:0}.markdown dl dt,.markdown li>p{margin-top:16px}.markdown dl{padding:0}.markdown dl dt{padding:0;font-size:1em;font-style:italic;font-weight:700}.markdown dl dd{padding:0 16px;margin-bottom:16px}.markdown blockquote{padding:0 15px;color:#777;border-left:4px solid #ddd}.markdown blockquote>:first-child{margin-top:0}.markdown blockquote>:last-child{margin-bottom:0}.markdown table{border-collapse:collapse;border-spacing:0;display:block;width:100%;overflow:auto;word-break:normal;word-break:keep-all}.markdown table th{font-weight:700}.markdown table td,.markdown table th{padding:6px 13px;border:1px solid #ddd}.markdown table tr{background-color:#fff;border-top:1px solid #ccc}.markdown table tr:nth-child(2n){background-color:#f8f8f8}.markdown img{max-width:100%;box-sizing:border-box}.markdown code{padding:.2em 0;margin:0;font-size:85%;background-color:rgba(0,0,0,.04);border-radius:3px}.markdown code:after,.markdown code:before{letter-spacing:-.2em;content:"\\00a0"}.markdown pre>code{padding:0;margin:0;font-size:100%;word-break:normal;white-space:pre;background:0 0;border:0}.markdown .highlight{margin-bottom:16px}.markdown .highlight pre,.markdown pre{padding:16px;overflow:auto;font-size:85%;line-height:1.45;background-color:#f7f7f7;border-radius:3px}.markdown .highlight pre{margin-bottom:0;word-break:normal}.markdown pre code{display:inline;max-width:initial;padding:0;overflow:initial;line-height:inherit;word-wrap:normal;background-color:transparent;border:0}.markdown pre code:after,.markdown pre code:before{content:normal}.markdown .pl-c{color:#969896}.markdown .pl-c1,.markdown .pl-s .pl-v{color:#0086b3}.markdown .pl-e,.markdown .pl-en{color:#795da3}.markdown .pl-s .pl-s1,.markdown .pl-smi{color:#333}.markdown .pl-ent{color:#63a35c}.markdown .pl-k{color:#a71d5d}.markdown .pl-pds,.markdown .pl-s,.markdown .pl-s .pl-pse .pl-s1,.markdown .pl-sr,.markdown .pl-sr .pl-cce,.markdown .pl-sr .pl-sra,.markdown .pl-sr .pl-sre{color:#183691}.markdown .pl-v{color:#ed6a43}.markdown .pl-id{color:#b52a1d}.markdown .pl-ii{background-color:#b52a1d;color:#f8f8f8}.markdown .pl-sr .pl-cce{color:#63a35c;font-weight:700}.markdown .pl-ml{color:#693a17}.markdown .pl-mh,.markdown .pl-mh .pl-en,.markdown .pl-ms{color:#1d3e81;font-weight:700}.markdown .pl-mq{color:teal}.markdown .pl-mi{color:#333;font-style:italic}.markdown .pl-mb{color:#333;font-weight:700}.markdown .pl-md{background-color:#ffecec;color:#bd2c00}.markdown .pl-mi1{background-color:#eaffea;color:#55a532}.markdown .pl-mdr{color:#795da3;font-weight:700}.markdown .pl-mo{color:#1d3e81}.markdown kbd{display:inline-block;padding:3px 5px;font:11px Consolas,"Liberation Mono",Menlo,Courier,monospace;line-height:10px;color:#555;vertical-align:middle;background-color:#fcfcfc;border:1px solid #ccc;border-bottom-color:#bbb;border-radius:3px;box-shadow:inset 0 -1px 0 #bbb}.markdown .task-list-item{list-style-type:none}.markdown .task-list-item+.task-list-item{margin-top:3px}.markdown .task-list-item input{margin:0 .35em .25em -1.6em;vertical-align:middle}.markdown :checked+.radio-label{z-index:1;position:relative;border-color:#4078c0}</style><body class="markdown">',
htmlClose = '</body></html>';
module.exports = function (filePath, opts, callback) {
fs.readFile(filePath, 'utf8', function (err, md) {
var html;
try {
if (!err) {
html = htmlHead + path.basename(filePath, '.md') + htmlBody + markdown.render(md) + htmlClose;
}
} catch (mdError) {
err = mdError;
}
callback(err, html);
});
};