Skip to content

Commit d5dcd5f

Browse files
committed
First pass at #1 - dark mode support.
By default, no changes to program behavior unless you use the new `-style` arg.
1 parent d7c863c commit d5dcd5f

File tree

5 files changed

+235
-8
lines changed

5 files changed

+235
-8
lines changed

README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ Usage: npx github-readme-to-html [options]
1515
1616
Options:
1717
-i, --input <filename> The input readme/markdown file (default: "README.md")
18+
-d, --dir <dirname> The output directory (default: "./dist")
1819
-o, --output <filename> The output HTML file (default: "index.html")
20+
-s, --style <mode> The style mode to use, either 'light' or 'dark' (default: "light")
1921
-t, --title <title> The page title (default: "Read Me")
2022
-h, --help display help for command
2123
```
@@ -33,12 +35,18 @@ All output goes to ./dist
3335
- .
3436
```
3537

36-
### Example
38+
### Example - Default Light Mode
3739

3840
Input: [ORIGINAL.md](ORIGINAL.md)
3941

4042
Output: https://github-readme-to-html.netlify.app/
4143

44+
### Example - Dark Mode
45+
46+
Input: [ORIGINAL.md](ORIGINAL.md)
47+
48+
Output: https://github-readme-to-html-darkmode.netlify.app/
49+
4250
### Testing
4351
To test local changes:
4452
```

index.js

+25-6
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,49 @@ const { program } = require('commander');
66
const footnotes = require('showdown-footnotes');
77
const highlight = require("showdown-highlight");
88

9-
const distDir = './dist';
10-
11-
const cssFile = __dirname + '/style.css'; //inside our module
12-
13-
const hljsCssFile = require.resolve('highlight.js/styles/github.css')
14-
159
program
1610
.option(
1711
'-i, --input <filename>',
1812
'The input readme/markdown file',
1913
'README.md'
2014
)
15+
.option(
16+
'-d, --dir <dirname>',
17+
'The output directory',
18+
"./dist"
19+
)
2120
.option('-o, --output <filename>', 'The output HTML file', 'index.html')
21+
.option(
22+
'-s, --style <mode>',
23+
'The style mode to use, either \'light\' or \'dark\'',
24+
"light"
25+
)
2226
.option('-t, --title <title>', 'The page title', 'Read Me');
2327

2428
program.parse(process.argv);
2529
const options = program.opts();
2630

2731
const readmeFile = './' + options.input;
32+
const styleMode = options.style;
2833
const pageTitle = options.title;
34+
const distDir = options.dir;
2935
const outputFile = distDir + '/' + options.output;
3036
const assetsDirSource = './assets/';
3137
const assetsDirTarget = distDir + '/assets';
3238

39+
40+
// style defaults to 'light'
41+
let cssFileName = 'style-light.css';
42+
let hljsCssFileName = 'github.css';
43+
44+
if (styleMode === "dark") {
45+
cssFileName = 'style-dark.css';
46+
hljsCssFileName = 'github-dark-dimmed.css';
47+
}
48+
49+
const cssFile = __dirname + '/' + cssFileName; //inside our module
50+
const hljsCssFile = require.resolve('highlight.js/styles/' + hljsCssFileName);
51+
3352
const converter = new showdown.Converter({
3453
ghCompatibleHeaderId: true,
3554
simpleLineBreaks: true,

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"prettier": "^2.2.1"
2121
},
2222
"scripts": {
23-
"start": "node index.js -i ORIGINAL.md -o index.html -t \"Read Me\"",
23+
"light": "node index.js -i ORIGINAL.md -o index.html -t \"Read Me\"",
24+
"dark": "node index.js -i ORIGINAL.md -o index.html -t \"Read Me\" -s \"dark\" -d \"dist-dark\"",
2425
"test": "node index.js -i HLJS-TEST.md"
2526
},
2627
"repository": {

style-dark.css

+199
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
body {
2+
font: 400 16px/1.5 'Helvetica Neue', Helvetica, Arial, sans-serif;
3+
color: #f0f6fc;
4+
background-color: #0d1117;
5+
-webkit-text-size-adjust: 100%;
6+
-webkit-font-feature-settings: 'kern' 1;
7+
-moz-font-feature-settings: 'kern' 1;
8+
-o-font-feature-settings: 'kern' 1;
9+
font-feature-settings: 'kern' 1;
10+
font-kerning: normal;
11+
padding: 30px;
12+
}
13+
14+
@media only screen and (max-width: 600px) {
15+
body {
16+
padding: 5px;
17+
}
18+
19+
main {
20+
padding: 0px 20px 20px 20px !important;
21+
}
22+
}
23+
24+
main {
25+
margin: 0px;
26+
max-width: 900px;
27+
border: 1px solid rgba(61, 68, 77, 0.7);
28+
padding: 10px 40px;
29+
padding-bottom: 20px;
30+
border-radius: 2px;
31+
margin-left: auto;
32+
margin-right: auto;
33+
}
34+
35+
hr {
36+
color: rgba(61, 68, 77, 0.7);
37+
background-color: rgba(61, 68, 77, 0.7);
38+
height: 1px;
39+
flex: 0 1 auto;
40+
margin: 1em 0;
41+
padding: 0;
42+
border: none;
43+
}
44+
45+
/**
46+
* Links
47+
*/
48+
a {
49+
color: #0366d6;
50+
text-decoration: none;
51+
}
52+
a:visited {
53+
color: #0366d6;
54+
}
55+
a:hover {
56+
color: #0366d6;
57+
text-decoration: underline;
58+
}
59+
60+
pre {
61+
/* in light mode, this has a background-color
62+
but that looks janky in dark mode */
63+
border-radius: 3px;
64+
font-size: 85%;
65+
line-height: 1.45;
66+
overflow: auto;
67+
padding: 16px;
68+
}
69+
70+
/**
71+
* Code blocks
72+
*/
73+
74+
code {
75+
background-color: #151b23;
76+
border-radius: 3px;
77+
font-size: 85%;
78+
margin: 0;
79+
word-wrap: break-word;
80+
padding: 0.2em 0.4em;
81+
font-family: SFMono-Regular, Consolas, Liberation Mono, Menlo, Courier,
82+
monospace;
83+
}
84+
85+
pre > code {
86+
background-color: transparent;
87+
border: 0;
88+
display: inline;
89+
line-height: inherit;
90+
margin: 0;
91+
overflow: visible;
92+
padding: 0;
93+
word-wrap: normal;
94+
font-size: 100%;
95+
}
96+
97+
/**
98+
* Blockquotes
99+
*/
100+
blockquote {
101+
margin-left: 30px;
102+
margin-top: 0px;
103+
margin-bottom: 16px;
104+
border-left-width: 3px;
105+
padding: 0 1em;
106+
color: #828282;
107+
border-left: 4px solid #3d444d;
108+
padding-left: 15px;
109+
font-size: 18px;
110+
letter-spacing: -1px;
111+
font-style: italic;
112+
}
113+
blockquote * {
114+
font-style: normal !important;
115+
letter-spacing: 0;
116+
color: #6a737d !important;
117+
}
118+
119+
/**
120+
* Tables
121+
*/
122+
table {
123+
border-spacing: 2px;
124+
display: block;
125+
font-size: 14px;
126+
overflow: auto;
127+
width: 100%;
128+
margin-bottom: 16px;
129+
border-spacing: 0;
130+
border-collapse: collapse;
131+
}
132+
133+
td {
134+
padding: 6px 13px;
135+
border: 1px solid #3d444d;
136+
}
137+
138+
th {
139+
font-weight: 600;
140+
padding: 6px 13px;
141+
border: 1px solid #3d444d;
142+
}
143+
144+
tr {
145+
background-color: #0d1117;
146+
border-top: 1px solid #c6cbd1;
147+
}
148+
149+
table tr:nth-child(2n) {
150+
background-color: #151b23;
151+
}
152+
153+
/**
154+
* Others
155+
*/
156+
157+
img {
158+
max-width: 100%;
159+
}
160+
161+
p {
162+
line-height: 24px;
163+
font-weight: 400;
164+
font-size: 16px;
165+
color: #f0f6fc;
166+
}
167+
168+
ul {
169+
margin-top: 0;
170+
}
171+
172+
li {
173+
color: #f0f6fc;
174+
font-size: 16px;
175+
font-weight: 400;
176+
line-height: 1.5;
177+
}
178+
179+
li + li {
180+
margin-top: 0.25em;
181+
}
182+
183+
body {
184+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial,
185+
sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
186+
color: #f0f6fc;
187+
}
188+
189+
a:visited {
190+
color: #0366d6;
191+
}
192+
193+
h1,
194+
h2,
195+
h3 {
196+
border-bottom: 1px solid rgba(61, 68, 77, 0.7);
197+
color: #f0f6fc;
198+
/* Darker */
199+
}

style.css style-light.css

File renamed without changes.

0 commit comments

Comments
 (0)