summaryrefslogtreecommitdiffstats
path: root/.backups/md2html
blob: 7ab4c6eb9581b95e46264aaebe04e2d85b436006 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python3
# TODO: replace this with an actual markdown library that isnt shit :3
import markdown
import sys
import io
from pygments.formatters import HtmlFormatter
from markdown.extensions.toc import TocExtension
sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8')
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
sys.stdout.write('''
<style>
@import url("/cgit-assets.git/plain/markdown.css");
''')
sys.stdout.write(HtmlFormatter(style='one-dark').get_style_defs('.highlight'))
sys.stdout.write('''
</style>   
''')
sys.stdout.write("<div class='markdown-body'>")
sys.stdout.flush()
# Note: you may want to run this through bleach for sanitization
markdown.markdownFromFile(
        output_format="html5",
        extensions=[
                "markdown.extensions.fenced_code",
                "markdown.extensions.codehilite",
                "markdown.extensions.tables",
                TocExtension(anchorlink=True)],
        extension_configs={
                "markdown.extensions.codehilite":{"css_class":"highlight"}})
sys.stdout.write("</div>")