]> git.armaanb.net Git - stagit.git/commitdiff
Add markdown rendering.
authorDemonstrandum <moi@knutsen.co>
Thu, 6 Aug 2020 02:19:30 +0000 (03:19 +0100)
committerDemonstrandum <moi@knutsen.co>
Thu, 6 Aug 2020 02:19:30 +0000 (03:19 +0100)
highlight
requirements.txt
style.css

index ba17566d7d88492e957142078fd95ccb381312b7..89cd98459dd0c9b691392f70d3678f84b7a438f1 100755 (executable)
--- a/highlight
+++ b/highlight
@@ -22,7 +22,16 @@ except pygments.util.ClassNotFound:
 
 if lexer is None:
     from pygments.lexers import TextLexer
-    lexer = TextLexer
+    lexer = TextLexer()
+
+rendered = None
+if lexer.__class__ is pygments.lexers.MarkdownLexer:
+    from markdown import markdown
+    rendered = markdown(contents, extensions=[
+        'codehilite',
+        'extra',
+        'sane_lists'
+    ])
 
 FORMAT = HtmlFormatter(
     style='murphy',
@@ -31,9 +40,14 @@ FORMAT = HtmlFormatter(
     lineanchors='loc',
     anchorlinenos=True)
 
+if rendered:
+    print('<article class="markup markdown">')
+    print(rendered)
+    print('</article>')
 print(highlight(contents, lexer, FORMAT))
 print('<style>')
-print(FORMAT.get_style_defs('.highlight'))
+print(FORMAT.get_style_defs(''))
 print('</style>')
 
 print("Filename: {}; Lexer: {}.".format(filename, lexer), file=stderr)
+print("Markdown was rendered in addition.", file=stderr)
index 3d4b9d6ba007042ac14b668f7723b40c49066b11..a496cb5484d50e445e09b125fb0008ac0cb3a63c 100644 (file)
@@ -1,2 +1,3 @@
 Pygments
+markdown
 
index 66b1fd23306c7e19211e71568c8298f81dad8e29..bb20ae7c94b37e8741537945539c52183e373fea 100644 (file)
--- a/style.css
+++ b/style.css
@@ -41,6 +41,14 @@ a.line {
     overflow-x: scroll;
 }
 
+article.markup {
+    border: 2px solid #00000017;
+    border-radius: 10px;
+    font-family: sans-serif;
+    padding: 1em 2.5em;
+    margin: 2em 0;
+}
+
 .linenos {
        margin-right: 0;
        border-right: 1px solid rgb(0 0 0 / 8%);