From 937b2d1357e9e9d702519855bc78fe2cecc9b08e Mon Sep 17 00:00:00 2001 From: Demonstrandum Date: Thu, 6 Aug 2020 03:19:30 +0100 Subject: [PATCH] Add markdown rendering. --- highlight | 18 ++++++++++++++++-- requirements.txt | 1 + style.css | 8 ++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/highlight b/highlight index ba17566..89cd984 100755 --- 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('
') + print(rendered) + print('
') print(highlight(contents, lexer, FORMAT)) print('') print("Filename: {}; Lexer: {}.".format(filename, lexer), file=stderr) +print("Markdown was rendered in addition.", file=stderr) diff --git a/requirements.txt b/requirements.txt index 3d4b9d6..a496cb5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ Pygments +markdown diff --git a/style.css b/style.css index 66b1fd2..bb20ae7 100644 --- 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%); -- 2.39.2