commit 937b2d1357e9e9d702519855bc78fe2cecc9b08e
parent 90a85134ce69eb5470a8248ebe7bdadc588e5d1e
Author: Demonstrandum <moi@knutsen.co>
Date: Thu, 6 Aug 2020 03:19:30 +0100
Add markdown rendering.
Diffstat:
3 files changed, 25 insertions(+), 2 deletions(-)
diff --git 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)
diff --git a/requirements.txt b/requirements.txt
@@ -1,2 +1,3 @@
Pygments
+markdown
diff --git 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%);