]> git.cameronkatri.com Git - cgit.git/blob - filters/html-converters/md2html
md2html: use proper formatting for hr
[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 border: 2px solid #ccc;
90 }
91 .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 {
92 margin-top: 0;
93 padding-top: 0;
94 }
95 .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 {
96 margin-top: 0;
97 padding-top: 0;
98 }
99 .markdown-body h1+p, .markdown-body h2+p, .markdown-body h3+p, .markdown-body h4+p, .markdown-body h5+p, .markdown-body h6+p {
100 margin-top: 0;
101 }
102 .markdown-body li p.first {
103 display: inline-block;
104 }
105 .markdown-body ul, .markdown-body ol {
106 padding-left: 30px;
107 }
108 .markdown-body ul.no-list, .markdown-body ol.no-list {
109 list-style-type: none;
110 padding: 0;
111 }
112 .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 {
113 margin-top: 0px;
114 }
115 .markdown-body ul li p:last-of-type, .markdown-body ol li p:last-of-type {
116 margin-bottom: 0;
117 }
118 .markdown-body ul ul, .markdown-body ul ol, .markdown-body ol ol, .markdown-body ol ul {
119 margin-bottom: 0;
120 }
121 .markdown-body dl {
122 padding: 0;
123 }
124 .markdown-body dl dt {
125 font-size: 14px;
126 font-weight: bold;
127 font-style: italic;
128 padding: 0;
129 margin: 15px 0 5px;
130 }
131 .markdown-body dl dt:first-child {
132 padding: 0;
133 }
134 .markdown-body dl dt>:first-child {
135 margin-top: 0px;
136 }
137 .markdown-body dl dt>:last-child {
138 margin-bottom: 0px;
139 }
140 .markdown-body dl dd {
141 margin: 0 0 15px;
142 padding: 0 15px;
143 }
144 .markdown-body dl dd>:first-child {
145 margin-top: 0px;
146 }
147 .markdown-body dl dd>:last-child {
148 margin-bottom: 0px;
149 }
150 .markdown-body blockquote {
151 border-left: 4px solid #DDD;
152 padding: 0 15px;
153 color: #777;
154 }
155 .markdown-body blockquote>:first-child {
156 margin-top: 0px;
157 }
158 .markdown-body blockquote>:last-child {
159 margin-bottom: 0px;
160 }
161 .markdown-body table th {
162 font-weight: bold;
163 }
164 .markdown-body table th, .markdown-body table td {
165 border: 1px solid #ccc;
166 padding: 6px 13px;
167 }
168 .markdown-body table tr {
169 border-top: 1px solid #ccc;
170 background-color: #fff;
171 }
172 .markdown-body table tr:nth-child(2n) {
173 background-color: #f8f8f8;
174 }
175 .markdown-body img {
176 max-width: 100%;
177 -moz-box-sizing: border-box;
178 box-sizing: border-box;
179 }
180 .markdown-body span.frame {
181 display: block;
182 overflow: hidden;
183 }
184 .markdown-body span.frame>span {
185 border: 1px solid #ddd;
186 display: block;
187 float: left;
188 overflow: hidden;
189 margin: 13px 0 0;
190 padding: 7px;
191 width: auto;
192 }
193 .markdown-body span.frame span img {
194 display: block;
195 float: left;
196 }
197 .markdown-body span.frame span span {
198 clear: both;
199 color: #333;
200 display: block;
201 padding: 5px 0 0;
202 }
203 .markdown-body span.align-center {
204 display: block;
205 overflow: hidden;
206 clear: both;
207 }
208 .markdown-body span.align-center>span {
209 display: block;
210 overflow: hidden;
211 margin: 13px auto 0;
212 text-align: center;
213 }
214 .markdown-body span.align-center span img {
215 margin: 0 auto;
216 text-align: center;
217 }
218 .markdown-body span.align-right {
219 display: block;
220 overflow: hidden;
221 clear: both;
222 }
223 .markdown-body span.align-right>span {
224 display: block;
225 overflow: hidden;
226 margin: 13px 0 0;
227 text-align: right;
228 }
229 .markdown-body span.align-right span img {
230 margin: 0;
231 text-align: right;
232 }
233 .markdown-body span.float-left {
234 display: block;
235 margin-right: 13px;
236 overflow: hidden;
237 float: left;
238 }
239 .markdown-body span.float-left span {
240 margin: 13px 0 0;
241 }
242 .markdown-body span.float-right {
243 display: block;
244 margin-left: 13px;
245 overflow: hidden;
246 float: right;
247 }
248 .markdown-body span.float-right>span {
249 display: block;
250 overflow: hidden;
251 margin: 13px auto 0;
252 text-align: right;
253 }
254 .markdown-body code, .markdown-body tt {
255 margin: 0 2px;
256 padding: 0px 5px;
257 border: 1px solid #eaeaea;
258 background-color: #f8f8f8;
259 border-radius: 3px;
260 }
261 .markdown-body code {
262 white-space: nowrap;
263 }
264 .markdown-body pre>code {
265 margin: 0;
266 padding: 0;
267 white-space: pre;
268 border: none;
269 background: transparent;
270 }
271 .markdown-body .highlight pre, .markdown-body pre {
272 background-color: #f8f8f8;
273 border: 1px solid #ccc;
274 font-size: 13px;
275 line-height: 19px;
276 overflow: auto;
277 padding: 6px 10px;
278 border-radius: 3px;
279 }
280 .markdown-body pre code, .markdown-body pre tt {
281 margin: 0;
282 padding: 0;
283 background-color: transparent;
284 border: none;
285 }
286 ''')
287 sys.stdout.write(HtmlFormatter(style='pastie').get_style_defs('.highlight'))
288 sys.stdout.write('''
289 </style>
290 ''')
291 sys.stdout.write("<div class='markdown-body'>")
292 sys.stdout.flush()
293 # Note: you may want to run this through bleach for sanitization
294 markdown.markdownFromFile(
295 output_format="html5",
296 extensions=[
297 "markdown.extensions.fenced_code",
298 "markdown.extensions.codehilite",
299 "markdown.extensions.tables",
300 "markdown.extensions.sane_lists",
301 TocExtension(anchorlink=True)],
302 extension_configs={
303 "markdown.extensions.codehilite":{"css_class":"highlight"}})
304 sys.stdout.write("</div>")