]> gitweb.ps.run Git - ps-cgit/blobdiff - filters/html-converters/md2html
cgitrc: handle value "0" for max-repo-count
[ps-cgit] / filters / html-converters / md2html
index 138713d6f6b97f1519995bf0b2632e7fdbc8d892..59f43a84167f5b6c7822958b07a4d3afc0822e16 100755 (executable)
@@ -1,5 +1,12 @@
-#!/bin/sh
-cat <<_EOF
+#!/usr/bin/env python3
+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>
 .markdown-body {
     font-size: 14px;
@@ -42,10 +49,14 @@ cat <<_EOF
     line-height: 1;
     padding-left: 0;
     margin-left: -22px;
-    top: 15%}
+    top: 15%;
+}
 .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 {
     display: inline-block;
 }
+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 {
+    color: black;
+}
 .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 {
     font-size: inherit;
 }
@@ -75,11 +86,7 @@ cat <<_EOF
     margin: 15px 0;
 }
 .markdown-body hr {
-    background: transparent url("/dirty-shade.png") repeat-x 0 0;
-    border: 0 none;
-    color: #ccc;
-    height: 4px;
-    padding: 0;
+    border: 2px solid #ccc;
 }
 .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 {
     margin-top: 0;
@@ -276,8 +283,22 @@ cat <<_EOF
     background-color: transparent;
     border: none;
 }
+''')
+sys.stdout.write(HtmlFormatter(style='pastie').get_style_defs('.highlight'))
+sys.stdout.write('''
 </style>   
-_EOF
-echo "<div class='markdown-body'>"
-markdown_py -o html5
-echo "</div>"
+''')
+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",
+               "markdown.extensions.sane_lists",
+               TocExtension(anchorlink=True)],
+       extension_configs={
+               "markdown.extensions.codehilite":{"css_class":"highlight"}})
+sys.stdout.write("</div>")