Skip to content

Commit ed10c42

Browse files
committed
- Committed theme templates
- Documented custom themes in README - Fixed linting issues in go.yml (CI)
1 parent 32edd0c commit ed10c42

File tree

7 files changed

+525
-80
lines changed

7 files changed

+525
-80
lines changed

.github/workflows/go.yml

+24-24
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# This workflow will build a golang project
2-
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
2+
# For more information see:
3+
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
4+
5+
---
36

47
name: Go
58

@@ -14,26 +17,23 @@ jobs:
1417
build:
1518
runs-on: ubuntu-latest
1619
steps:
17-
- uses: actions/checkout@v3
18-
19-
- name: Set up Go
20-
uses: actions/setup-go@v4
21-
with:
22-
go-version: '1.20'
23-
24-
- name: Build
25-
run: go build -v
26-
- name: Test
27-
run: |
28-
set -e
29-
go install github.com/go-critic/go-critic/cmd/gocritic@latest
30-
# go install golang.org/x/tools/cmd/goimports@latest
31-
go install golang.org/x/lint/golint@latest
32-
go install github.com/gordonklaus/ineffassign@latest
33-
pip install pre-commit
34-
pre-commit install
35-
pre-commit run --all-files
36-
go test -v
37-
38-
#- name: Test
39-
#run: go test -v
20+
- uses: actions/checkout@v3
21+
22+
- name: Set up Go
23+
uses: actions/setup-go@v4
24+
with:
25+
go-version: '1.20'
26+
27+
- name: Build
28+
run: go build -v
29+
- name: Test
30+
run: |
31+
set -e
32+
go install github.com/go-critic/go-critic/cmd/gocritic@latest
33+
# go install golang.org/x/tools/cmd/goimports@latest
34+
go install golang.org/x/lint/golint@latest
35+
go install github.com/gordonklaus/ineffassign@latest
36+
pip install pre-commit
37+
pre-commit install
38+
pre-commit run --all-files
39+
go test -v

README.md

+13-7
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ Both of the above are documented at [Go Docs](http://godocs.org).
1616

1717
## Features
1818

19-
- Syntax highlighting (for code blocks)
20-
- Dark and light themes
21-
- Pagination control (using horizontal lines - especially useful for presentations)
22-
- Page Footer (consisting of author, title and page number)
23-
- Support of non-Latin charsets and multiple fonts
19+
- [Syntax highlighting (for code blocks)](#syntax-highlighting)
20+
- [Dark and light themes](#custom-themes)
21+
- [Customised themes (by passing a JSON file to `md2pdf`)](#custom-themes)
22+
- [Support of non-Latin charsets and multiple fonts](#using-non-ascii-glyphsfonts)
23+
- [Pagination control (using horizontal lines - especially useful for presentations)](#additional-options)
24+
- [Page Footer (consisting of author, title and page number)](#additional-options)
2425

2526
## Supported Markdown elements
2627

@@ -61,8 +62,6 @@ This is a planned fix; [see here](https://github.com/mandolyte/mdtopdf/issues/1)
6162

6263
7. Tables are supported, but no attempt is made to ensure fit. You can, however, change the font size and spacing to make it smaller. See example.
6364

64-
65-
6665
## Installation
6766

6867
You can obtain the pre-built `md2pdf` binary for your OS and arch [here](https://github.com/mandolyte/mdtopdf/releases);
@@ -83,6 +82,13 @@ $ go install github.com/mandolyte/mdtopdf/cmd/md2pdf@latest
8382

8483
For examples, see `testdata/Markdown Documentation - Syntax.text` and `testdata/Markdown Documentation - Syntax.pdf`
8584

85+
## Custom themes
86+
87+
`md2pdf` supports both light and dark themes out of the box (use `--theme light` or `--theme dark` - no config required).
88+
89+
However, if you wish to customise the font faces, sizes and colours, you can use the JSONs in
90+
[custom_themes](./custom_themes) as a starting point. Edit to your liking and pass `--theme /path/to/json` to `md2pdf`
91+
8692
## Quick start
8793

8894
In the `cmd` folder is an example using the package. It demonstrates

cmd/md2pdf/md2pdf.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -143,21 +143,21 @@ func main() {
143143
themeFile := ""
144144
if *themeArg == "dark" {
145145
theme = mdtopdf.DARK
146-
}else if _, err := os.Stat(*themeArg); err == nil {
146+
} else if _, err := os.Stat(*themeArg); err == nil {
147147
theme = mdtopdf.CUSTOM
148148
themeFile = *themeArg
149149
}
150150

151151
params := mdtopdf.PdfRendererParams{
152-
Orientation: *orientation,
153-
Papersz: *pageSize,
154-
PdfFile: *output,
155-
TracerFile: *logFile,
156-
Opts: opts,
157-
Theme: theme,
158-
CustomThemeFile: themeFile,
159-
FontFile: *fontFile,
160-
FontName: *fontName,
152+
Orientation: *orientation,
153+
Papersz: *pageSize,
154+
PdfFile: *output,
155+
TracerFile: *logFile,
156+
Opts: opts,
157+
Theme: theme,
158+
CustomThemeFile: themeFile,
159+
FontFile: *fontFile,
160+
FontName: *fontName,
161161
}
162162

163163
pf := mdtopdf.NewPdfRenderer(params)
@@ -172,12 +172,12 @@ func main() {
172172
pf.Pdf.AddFont(*fontName, "", *fontFile)
173173
pf.Pdf.SetFont(*fontName, "", 12)
174174
pf.Normal = mdtopdf.Styler{
175-
Font: *fontName,
175+
Font: *fontName,
176176
Style: "",
177-
Size: 12, Spacing: 2,
177+
Size: 12, Spacing: 2,
178178
TextColor: pf.Normal.TextColor,
179179
}
180-
180+
181181
}
182182

183183
if *printFooter {

custom_themes/dark_theme.json

+217
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
{
2+
"Normal": {
3+
"Font": "Arial",
4+
"Style": "",
5+
"Size": 12,
6+
"Spacing": 2,
7+
"TextColor": {
8+
"Red": 255,
9+
"Green": 255,
10+
"Blue": 255
11+
},
12+
"FillColor": {
13+
"Red": 0,
14+
"Green": 0,
15+
"Blue": 0
16+
}
17+
},
18+
"Link": {
19+
"Font": "Arial",
20+
"Style": "b",
21+
"Size": 12,
22+
"Spacing": 2,
23+
"TextColor": {
24+
"Red": 100,
25+
"Green": 149,
26+
"Blue": 237
27+
},
28+
"FillColor": {
29+
"Red": 0,
30+
"Green": 0,
31+
"Blue": 0
32+
}
33+
},
34+
"Backtick": {
35+
"Font": "Times",
36+
"Style": "",
37+
"Size": 12,
38+
"Spacing": 2,
39+
"TextColor": {
40+
"Red": 211,
41+
"Green": 211,
42+
"Blue": 211
43+
},
44+
"FillColor": {
45+
"Red": 32,
46+
"Green": 35,
47+
"Blue": 37
48+
}
49+
},
50+
"Blockquote": {
51+
"Font": "Arial",
52+
"Style": "i",
53+
"Size": 12,
54+
"Spacing": 2,
55+
"TextColor": {
56+
"Red": 169,
57+
"Green": 169,
58+
"Blue": 169
59+
},
60+
"FillColor": {
61+
"Red": 0,
62+
"Green": 0,
63+
"Blue": 0
64+
}
65+
},
66+
"IndentValue": 0,
67+
"H1": {
68+
"Font": "Arial",
69+
"Style": "b",
70+
"Size": 24,
71+
"Spacing": 5,
72+
"TextColor": {
73+
"Red": 169,
74+
"Green": 169,
75+
"Blue": 169
76+
},
77+
"FillColor": {
78+
"Red": 0,
79+
"Green": 0,
80+
"Blue": 0
81+
}
82+
},
83+
"H2": {
84+
"Font": "Arial",
85+
"Style": "b",
86+
"Size": 21,
87+
"Spacing": 5,
88+
"TextColor": {
89+
"Red": 169,
90+
"Green": 169,
91+
"Blue": 169
92+
},
93+
"FillColor": {
94+
"Red": 0,
95+
"Green": 0,
96+
"Blue": 0
97+
}
98+
},
99+
"H3": {
100+
"Font": "Arial",
101+
"Style": "b",
102+
"Size": 20,
103+
"Spacing": 5,
104+
"TextColor": {
105+
"Red": 169,
106+
"Green": 169,
107+
"Blue": 169
108+
},
109+
"FillColor": {
110+
"Red": 0,
111+
"Green": 0,
112+
"Blue": 0
113+
}
114+
},
115+
"H4": {
116+
"Font": "Arial",
117+
"Style": "b",
118+
"Size": 18,
119+
"Spacing": 5,
120+
"TextColor": {
121+
"Red": 169,
122+
"Green": 169,
123+
"Blue": 169
124+
},
125+
"FillColor": {
126+
"Red": 0,
127+
"Green": 0,
128+
"Blue": 0
129+
}
130+
},
131+
"H5": {
132+
"Font": "Arial",
133+
"Style": "b",
134+
"Size": 16,
135+
"Spacing": 5,
136+
"TextColor": {
137+
"Red": 169,
138+
"Green": 169,
139+
"Blue": 169
140+
},
141+
"FillColor": {
142+
"Red": 0,
143+
"Green": 0,
144+
"Blue": 0
145+
}
146+
},
147+
"H6": {
148+
"Font": "Arial",
149+
"Style": "b",
150+
"Size": 14,
151+
"Spacing": 5,
152+
"TextColor": {
153+
"Red": 169,
154+
"Green": 169,
155+
"Blue": 169
156+
},
157+
"FillColor": {
158+
"Red": 0,
159+
"Green": 0,
160+
"Blue": 0
161+
}
162+
},
163+
"THeader": {
164+
"Font": "Arial",
165+
"Style": "b",
166+
"Size": 12,
167+
"Spacing": 2,
168+
"TextColor": {
169+
"Red": 169,
170+
"Green": 169,
171+
"Blue": 169
172+
},
173+
"FillColor": {
174+
"Red": 27,
175+
"Green": 27,
176+
"Blue": 27
177+
}
178+
},
179+
"TBody": {
180+
"Font": "Arial",
181+
"Style": "",
182+
"Size": 12,
183+
"Spacing": 2,
184+
"TextColor": {
185+
"Red": 128,
186+
"Green": 128,
187+
"Blue": 128
188+
},
189+
"FillColor": {
190+
"Red": 200,
191+
"Green": 200,
192+
"Blue": 200
193+
}
194+
},
195+
"Code": {
196+
"Font": "Times",
197+
"Style": "",
198+
"Size": 12,
199+
"Spacing": 2,
200+
"TextColor": {
201+
"Red": 211,
202+
"Green": 211,
203+
"Blue": 211
204+
},
205+
"FillColor": {
206+
"Red": 32,
207+
"Green": 35,
208+
"Blue": 37
209+
}
210+
},
211+
"Theme": 3,
212+
"BackgroundColor": {
213+
"Red": 0,
214+
"Green": 0,
215+
"Blue": 0
216+
}
217+
}

0 commit comments

Comments
 (0)