]> git.cameronkatri.com Git - cgit.git/blob - filters/html-converters/md2html
global: replace references to 'sha1' with 'oid'
[cgit.git] / filters / html-converters / md2html
1 #!/usr/bin/env python3
2 import markdown
3 import sys
4 import io
5 from pygments.formatters import HtmlFormatter
6 from markdown.extensions.toc import TocExtension
7 sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8')
8 sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
9 sys.stdout.write('''
10 <style>
11 .markdown-body {
12 font-size: 14px;
13 line-height: 1.6;
14 overflow: hidden;
15 }
16 .markdown-body>*:first-child {
17 margin-top: 0 !important;
18 }
19 .markdown-body>*:last-child {
20 margin-bottom: 0 !important;
21 }
22 .markdown-body a.absent {
23 color: #c00;
24 }
25 .markdown-body a.anchor {
26 display: block;
27 padding-left: 30px;
28 margin-left: -30px;
29 cursor: pointer;
30 position: absolute;
31 top: 0;
32 left: 0;
33 bottom: 0;
34 }
35 .markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4, .markdown-body h5, .markdown-body h6 {
36 margin: 20px 0 10px;
37 padding: 0;
38 font-weight: bold;
39 -webkit-font-smoothing: antialiased;
40 cursor: text;
41 position: relative;
42 }
43 .markdown-body h1 .mini-icon-link, .markdown-body h2 .mini-icon-link, .markdown-body h3 .mini-icon-link, .markdown-body h4 .mini-icon-link, .markdown-body h5 .mini-icon-link, .markdown-body h6 .mini-icon-link {
44 display: none;
45 color: #000;
46 }
47 .markdown-body h1:hover a.anchor, .markdown-body h2:hover a.anchor, .markdown-body h3:hover a.anchor, .markdown-body h4:hover a.anchor, .markdown-body h5:hover a.anchor, .markdown-body h6:hover a.anchor {
48 text-decoration: none;
49 line-height: 1;
50 padding-left: 0;
51 margin-left: -22px;
52 top: 15%;
53 }
54 .markdown-body h1:hover a.anchor .mini-icon-link, .markdown-body h2:hover a.anchor .mini-icon-link, .markdown-body h3:hover a.anchor .mini-icon-link, .markdown-body h4:hover a.anchor .mini-icon-link, .markdown-body h5:hover a.anchor .mini-icon-link, .markdown-body h6:hover a.anchor .mini-icon-link {
55 display: inline-block;
56 }
57 div#cgit .markdown-body h1 a.toclink, div#cgit .markdown-body h2 a.toclink, div#cgit .markdown-body h3 a.toclink, div#cgit .markdown-body h4 a.toclink, div#cgit .markdown-body h5 a.toclink, div#cgit .markdown-body h6 a.toclink {
58 color: black;
59 }
60 .markdown-body h1 tt, .markdown-body h1 code, .markdown-body h2 tt, .markdown-body h2 code, .markdown-body h3 tt, .markdown-body h3 code, .markdown-body h4 tt, .markdown-body h4 code, .markdown-body h5 tt, .markdown-body h5 code, .markdown-body h6 tt, .markdown-body h6 code {
61 font-size: inherit;
62 }
63 .markdown-body h1 {
64 font-size: 28px;
65 color: #000;
66 }
67 .markdown-body h2 {
68 font-size: 24px;
69 border-bottom: 1px solid #ccc;
70 color: #000;
71 }
72 .markdown-body h3 {
73 font-size: 18px;
74 }
75 .markdown-body h4 {
76 font-size: 16px;
77 }
78 .markdown-body h5 {
79 font-size: 14px;
80 }
81 .markdown-body h6 {
82 color: #777;
83 font-size: 14px;
84 }
85 .markdown-body p, .markdown-body blockquote, .markdown-body ul, .markdown-body ol, .markdown-body dl, .markdown-body table, .markdown-body pre {
86 margin: 15px 0;
87 }
88 .markdown-body hr {
89 background: transparent url("/dirty-shade.png") repeat-x 0 0;
90 border: 0 none;
91 color: #ccc;
92 height: 4px;
93 padding: 0;
94 }
95 .markdown-body>h2:first-child, .markdown-body>h1:first-child, .markdown-body>h1:first-child+h2, .markdown-body>h3:first-child, .markdown-body>h4:first-child, .markdown-body>h5:first-child, .markdown-body>h6:first-child {
96 margin-top: 0;
97 padding-top: 0;
98 }
99 .markdown-body a:first-child h1, .markdown-body a:first-child h2, .markdown-body a:first-child h3, .markdown-body a:first-child h4, .markdown-body a:first-child h5, .markdown-body a:first-child h6 {
100 margin-top: 0;
101 padding-top: 0;
102 }
103 .markdown-body h1+p, .markdown-body h2+p, .markdown-body h3+p, .markdown-body h4+p, .markdown-body h5+p, .markdown-body h6+p {
104 margin-top: 0;
105 }
106 .markdown-body li p.first {
107 display: inline-block;
108 }
109 .markdown-body ul, .markdown-body ol {
110 padding-left: 30px;
111 }
112 .markdown-body ul.no-list, .markdown-body ol.no-list {
113 list-style-type: none;
114 padding: 0;
115 }
116 .markdown-body ul li>:first-child, .markdown-body ul li ul:first-of-type, .markdown-body ul li ol:first-of-type, .markdown-body ol li>:first-child, .markdown-body ol li ul:first-of-type, .markdown-body ol li ol:first-of-type {
117 margin-top: 0px;
118 }
119 .markdown-body ul li p:last-of-type, .markdown-body ol li p:last-of-type {
120 margin-bottom: 0;
121 }
122 .markdown-body ul ul, .markdown-body ul ol, .markdown-body ol ol, .markdown-body ol ul {
123 margin-bottom: 0;
124 }
125 .markdown-body dl {
126 padding: 0;
127 }
128 .markdown-body dl dt {
129 font-size: 14px;
130 font-weight: bold;
131 font-style: italic;
132 padding: 0;
133 margin: 15px 0 5px;
134 }
135 .markdown-body dl dt:first-child {
136 padding: 0;
137 }
138 .markdown-body dl dt>:first-child {
139 margin-top: 0px;
140 }
141 .markdown-body dl dt>:last-child {
142 margin-bottom: 0px;
143 }
144 .markdown-body dl dd {
145 margin: 0 0 15px;
146 padding: 0 15px;
147 }
148 .markdown-body dl dd>:first-child {
149 margin-top: 0px;
150 }
151 .markdown-body dl dd>:last-child {
152 margin-bottom: 0px;
153 }
154 .markdown-body blockquote {
155 border-left: 4px solid #DDD;
156 padding: 0 15px;
157 color: #777;
158 }
159 .markdown-body blockquote>:first-child {
160 margin-top: 0px;
161 }
162 .markdown-body blockquote>:last-child {
163 margin-bottom: 0px;
164 }
165 .markdown-body table th {
166 font-weight: bold;
167 }
168 .markdown-body table th, .markdown-body table td {
169 border: 1px solid #ccc;
170 padding: 6px 13px;
171 }
172 .markdown-body table tr {
173 border-top: 1px solid #ccc;
174 background-color: #fff;
175 }
176 .markdown-body table tr:nth-child(2n) {
177 background-color: #f8f8f8;
178 }
179 .markdown-body img {
180 max-width: 100%;
181 -moz-box-sizing: border-box;
182 box-sizing: border-box;
183 }
184 .markdown-body span.frame {
185 display: block;
186 overflow: hidden;
187 }
188 .markdown-body span.frame>span {
189 border: 1px solid #ddd;
190 display: block;
191 float: left;
192 overflow: hidden;
193 margin: 13px 0 0;
194 padding: 7px;
195 width: auto;
196 }
197 .markdown-body span.frame span img {
198 display: block;
199 float: left;
200 }
201 .markdown-body span.frame span span {
202 clear: both;
203 color: #333;
204 display: block;
205 padding: 5px 0 0;
206 }
207 .markdown-body span.align-center {
208 display: block;
209 overflow: hidden;
210 clear: both;
211 }
212 .markdown-body span.align-center>span {
213 display: block;
214 overflow: hidden;
215 margin: 13px auto 0;
216 text-align: center;
217 }
218 .markdown-body span.align-center span img {
219 margin: 0 auto;
220 text-align: center;
221 }
222 .markdown-body span.align-right {
223 display: block;
224 overflow: hidden;
225 clear: both;
226 }
227 .markdown-body span.align-right>span {
228 display: block;
229 overflow: hidden;
230 margin: 13px 0 0;
231 text-align: right;
232 }
233 .markdown-body span.align-right span img {
234 margin: 0;
235 text-align: right;
236 }
237 .markdown-body span.float-left {
238 display: block;
239 margin-right: 13px;
240 overflow: hidden;
241 float: left;
242 }
243 .markdown-body span.float-left span {
244 margin: 13px 0 0;
245 }
246 .markdown-body span.float-right {
247 display: block;
248 margin-left: 13px;
249 overflow: hidden;
250 float: right;
251 }
252 .markdown-body span.float-right>span {
253 display: block;
254 overflow: hidden;
255 margin: 13px auto 0;
256 text-align: right;
257 }
258 .markdown-body code, .markdown-body tt {
259 margin: 0 2px;
260 padding: 0px 5px;
261 border: 1px solid #eaeaea;
262 background-color: #f8f8f8;
263 border-radius: 3px;
264 }
265 .markdown-body code {
266 white-space: nowrap;
267 }
268 .markdown-body pre>code {
269 margin: 0;
270 padding: 0;
271 white-space: pre;
272 border: none;
273 background: transparent;
274 }
275 .markdown-body .highlight pre, .markdown-body pre {
276 background-color: #f8f8f8;
277 border: 1px solid #ccc;
278 font-size: 13px;
279 line-height: 19px;
280 overflow: auto;
281 padding: 6px 10px;
282 border-radius: 3px;
283 }
284 .markdown-body pre code, .markdown-body pre tt {
285 margin: 0;
286 padding: 0;
287 background-color: transparent;
288 border: none;
289 }
290 ''')
291 sys.stdout.write(HtmlFormatter(style='pastie').get_style_defs('.highlight'))
292 sys.stdout.write('''
293 </style>
294 ''')
295 sys.stdout.write("<div class='markdown-body'>")
296 sys.stdout.flush()
297 # Note: you may want to run this through bleach for sanitization
298 markdown.markdownFromFile(
299 output_format="html5",
300 extensions=[
301 "markdown.extensions.fenced_code",
302 "markdown.extensions.codehilite",
303 "markdown.extensions.tables",
304 TocExtension(anchorlink=True)],
305 extension_configs={
306 "markdown.extensions.codehilite":{"css_class":"highlight"}})
307 sys.stdout.write("</div>")