git » git-arr » commit f62ca21

Add markdown blob support

author Vanya Sergeev
2013-10-13 13:28:51 UTC
committer Alberto Bertogli
2013-11-02 19:03:59 UTC
parent d3bf98ea006f9949b16ad10f7d2c88d6809b8619

Add markdown blob support

git-arr +2 -0
utils.py +14 -0
views/blob.html +3 -1

diff --git a/git-arr b/git-arr
index 173a6b2..8890563 100755
--- a/git-arr
+++ b/git-arr
@@ -174,6 +174,8 @@ def with_utils(f):
         'can_colorize': utils.can_colorize,
         'colorize_diff': utils.colorize_diff,
         'colorize_blob': utils.colorize_blob,
+        'can_markdown': utils.can_markdown,
+        'markdown_blob': utils.markdown_blob,
         'abort': bottle.abort,
         'smstr': git.smstr,
     }
diff --git a/utils.py b/utils.py
index 801580e..9e3ca59 100644
--- a/utils.py
+++ b/utils.py
@@ -12,6 +12,10 @@ try:
 except ImportError:
     pygments = None
 
+try:
+    import markdown
+except ImportError:
+    markdown = None
 
 def shorten(s, width = 60):
     if len(s) < 60:
@@ -41,6 +45,13 @@ def can_colorize(s):
 
     return True
 
+def can_markdown(fname):
+    """True if we can process file through markdown, False otherwise."""
+    if markdown is None:
+        return False
+
+    return fname.endswith(".md")
+
 def colorize_diff(s):
     lexer = lexers.DiffLexer(encoding = 'utf-8')
     formatter = HtmlFormatter(encoding = 'utf-8',
@@ -68,3 +79,6 @@ def colorize_blob(fname, s):
 
     return highlight(s, lexer, formatter)
 
+def markdown_blob(s):
+    return markdown.markdown(s)
+
diff --git a/views/blob.html b/views/blob.html
index 283bbcd..6244fc7 100644
--- a/views/blob.html
+++ b/views/blob.html
@@ -36,7 +36,9 @@
     <a href="">{{!fname.html}}</a>
 </h3>
 
-% if can_colorize(blob):
+% if can_markdown(fname.unicode):
+{{!markdown_blob(blob)}}
+% elif can_colorize(blob):
 {{!colorize_blob(fname.unicode, blob)}}
 % else:
 <pre class="blob-body">