Skip to content

Commit 216bb6e

Browse files
ashwinvisshizhong.lszpeter-liu
authored
Changes to #90 (#99)
* add theme param;add night theme style * comments * add theme param support * follow ashwinvis's advices * Rename night -> dark * Increase tries for port check again --------- Co-authored-by: shizhong.lsz <[email protected]> Co-authored-by: Starfury.Tech <[email protected]>
1 parent 6abe3d8 commit 216bb6e

File tree

10 files changed

+947
-28
lines changed

10 files changed

+947
-28
lines changed

css/themes/dark/github-markdown.css

Lines changed: 782 additions & 0 deletions
Large diffs are not rendered by default.
File renamed without changes.

css/themes/darkness/github-markdown.css

Lines changed: 0 additions & 9 deletions
This file was deleted.

css/themes/darkness/github-syntax-highlight.css

Lines changed: 0 additions & 11 deletions
This file was deleted.
File renamed without changes.
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
3+
github.com style (c) Vasily Polovnyov <[email protected]>
4+
5+
*/
6+
7+
.hljs {
8+
display: block;
9+
overflow-x: auto;
10+
padding: 0.5em;
11+
color: #333;
12+
background: #f8f8f8;
13+
-webkit-text-size-adjust: none;
14+
}
15+
16+
.hljs-comment,
17+
.diff .hljs-header,
18+
.hljs-javadoc {
19+
color: #998;
20+
font-style: italic;
21+
}
22+
23+
.hljs-keyword,
24+
.css .rule .hljs-keyword,
25+
.hljs-winutils,
26+
.nginx .hljs-title,
27+
.hljs-subst,
28+
.hljs-request,
29+
.hljs-status {
30+
color: #a71d5d;
31+
}
32+
33+
.hljs-number,
34+
.hljs-hexcolor,
35+
.ruby .hljs-constant {
36+
color: #0086b3;
37+
}
38+
39+
.hljs-string,
40+
.hljs-tag .hljs-value,
41+
.hljs-phpdoc,
42+
.hljs-dartdoc,
43+
.tex .hljs-formula {
44+
color: #df5000;
45+
}
46+
47+
.hljs-title,
48+
.hljs-id,
49+
.scss .hljs-preprocessor {
50+
color: #900;
51+
}
52+
53+
.hljs-list .hljs-keyword,
54+
.hljs-subst {
55+
font-weight: normal;
56+
}
57+
58+
.hljs-class .hljs-title,
59+
.hljs-type,
60+
.vhdl .hljs-literal,
61+
.tex .hljs-command {
62+
color: #795da3;
63+
}
64+
65+
.hljs-tag,
66+
.hljs-tag .hljs-title,
67+
.hljs-rules .hljs-property,
68+
.django .hljs-tag .hljs-keyword {
69+
color: #000080;
70+
font-weight: normal;
71+
}
72+
73+
.hljs-attribute,
74+
.hljs-variable,
75+
.lisp .hljs-body {
76+
color: #008080;
77+
}
78+
79+
.hljs-regexp {
80+
color: #009926;
81+
}
82+
83+
.hljs-symbol,
84+
.ruby .hljs-symbol .hljs-string,
85+
.lisp .hljs-keyword,
86+
.clojure .hljs-keyword,
87+
.scheme .hljs-keyword,
88+
.tex .hljs-special,
89+
.hljs-prompt {
90+
color: #990073;
91+
}
92+
93+
.hljs-built_in {
94+
color: #795da3;
95+
}
96+
97+
.hljs-preprocessor,
98+
.hljs-pragma,
99+
.hljs-pi,
100+
.hljs-doctype,
101+
.hljs-shebang,
102+
.hljs-cdata {
103+
color: #999;
104+
font-weight: bold;
105+
}
106+
107+
.hljs-deletion {
108+
background: #fdd;
109+
}
110+
111+
.hljs-addition {
112+
background: #dfd;
113+
}
114+
115+
.diff .hljs-change {
116+
background: #0086b3;
117+
}
118+
119+
.hljs-chunk {
120+
color: #aaa;
121+
}

index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
<meta charset="utf-8">
66
<meta http-equiv="X-UA-Compatible" content="IE=edge">
77
<meta http-equiv="Content-Language" content="en">
8-
<link rel="stylesheet" type="text/css" href="/css/github-syntax-highlight.css">
9-
<link rel="stylesheet" type="text/css" href="/css/github-markdown.css">
8+
<!-- theme stylesheets are dynamic loaded in index.js, according to 'theme' param -->
9+
<!-- <link rel="stylesheet" type="text/css" href="/css/github-syntax-highlight.css"> -->
10+
<!-- <link rel="stylesheet" type="text/css" href="/css/github-markdown.css"> -->
1011
<link rel="stylesheet" type="text/css" href="/css/mjpage-html.css">
1112
<style>
1213
.markdown-body {
@@ -26,7 +27,6 @@
2627
<script src="/node_modules/mermaid/dist/mermaid.min.js"></script>
2728
<script src="/socket.io/socket.io.min.js"></script>
2829
<script src="/index.js"></script>
29-
</script>
3030
</head>
3131
<body>
3232
<div class="container">

index.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,30 @@ function setDisconnected(isDisconnected) {
6161
document.getElementById('con-error').style.display =
6262
isDisconnected ? 'block' : 'none';
6363
}
64+
65+
66+
function loadStyle(src) {
67+
return new Promise(function (resolve, reject) {
68+
let link = document.createElement('link');
69+
link.href = src;
70+
link.rel = 'stylesheet';
71+
72+
link.onload = () => resolve(link);
73+
link.onerror = () => reject(new Error(`Style load error for ${src}`));
74+
75+
document.head.append(link);
76+
});
77+
}
78+
79+
// register func on window.onload may not best way
80+
// but the in-line script in index.html may request more feature(unsafe-content-allowed)
81+
// and more flexable js-lib(etc jquery) is heavier too much
82+
window.onload = function(){
83+
// dynamic load style according to *theme* params
84+
let searchParams = new URLSearchParams(window.location.search);
85+
let theme = searchParams.get("theme") || "light";
86+
let themePath = "/css/themes/" + theme + "/";
87+
loadStyle(themePath + "github-markdown.css");
88+
loadStyle(themePath + "github-syntax-highlight.css");
89+
}
90+

src/cli.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ const process = require('process'),
66
exec = require('child_process').exec,
77
os = require('os'),
88
fs = require('fs'),
9-
path = require('path');
9+
path = require('path'),
10+
url = require('url');
1011

1112
const argv = require('minimist')(process.argv.slice(2), {
1213
string: ['browser'],
@@ -192,7 +193,10 @@ function httpHandler(req, res) {
192193
let isIndexFile = /^\/(index\.html)?(\?|$)/.test(req.url);
193194
let pkgRoot = path.dirname(__dirname);
194195
let cwd = process.cwd();
195-
let mount = cwd && !fs.existsSync(pkgRoot + req.url) ? cwd : pkgRoot;
196+
197+
let filePath = url.parse(req.url, false).pathname;
198+
199+
let mount = cwd && !fs.existsSync(pkgRoot + filePath) ? cwd : pkgRoot;
196200
if (githubUrl) {
197201
addSecurityHeaders(req, res, false);
198202
// Serve the file out of the current working directory
@@ -210,7 +214,7 @@ function httpHandler(req, res) {
210214
}
211215

212216
// Otherwise serve the file from the directory this module is in
213-
send(req, req.url, {root: mount})
217+
send(req, filePath, {root: mount})
214218
.pipe(res);
215219
}
216220
break;
@@ -264,7 +268,12 @@ function onListening() {
264268
argv.browser = 'xdg-open';
265269
}
266270
}
267-
let cmd = argv.browser + ' http://localhost:' + argv.port + '/';
271+
let cmd = argv.browser + ' http://localhost:' + argv.port + '/?';
272+
// add theme param if present
273+
if (argv.theme){
274+
cmd += 'theme=' + argv.theme;
275+
}
276+
268277
if (argv.debug) {
269278
console.log("Run the following to manually open browser: \n " + cmd);
270279
} else {

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
118118
def send(self, via, markdown_file):
119119
# Wait some time to ensure the server has launched
120120
# TODO: find a better way: signal? return code? daemon?
121-
for tries in range(3):
121+
for tries in range(10):
122122
if port_in_use(self.port):
123123
break
124124
else:

0 commit comments

Comments
 (0)