Add markdown blob support
This commit is contained in:
parent
d3bf98ea00
commit
f62ca211eb
2
git-arr
2
git-arr
@ -174,6 +174,8 @@ def with_utils(f):
|
|||||||
'can_colorize': utils.can_colorize,
|
'can_colorize': utils.can_colorize,
|
||||||
'colorize_diff': utils.colorize_diff,
|
'colorize_diff': utils.colorize_diff,
|
||||||
'colorize_blob': utils.colorize_blob,
|
'colorize_blob': utils.colorize_blob,
|
||||||
|
'can_markdown': utils.can_markdown,
|
||||||
|
'markdown_blob': utils.markdown_blob,
|
||||||
'abort': bottle.abort,
|
'abort': bottle.abort,
|
||||||
'smstr': git.smstr,
|
'smstr': git.smstr,
|
||||||
}
|
}
|
||||||
|
14
utils.py
14
utils.py
@ -12,6 +12,10 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
pygments = None
|
pygments = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
import markdown
|
||||||
|
except ImportError:
|
||||||
|
markdown = None
|
||||||
|
|
||||||
def shorten(s, width = 60):
|
def shorten(s, width = 60):
|
||||||
if len(s) < 60:
|
if len(s) < 60:
|
||||||
@ -41,6 +45,13 @@ def can_colorize(s):
|
|||||||
|
|
||||||
return True
|
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):
|
def colorize_diff(s):
|
||||||
lexer = lexers.DiffLexer(encoding = 'utf-8')
|
lexer = lexers.DiffLexer(encoding = 'utf-8')
|
||||||
formatter = HtmlFormatter(encoding = 'utf-8',
|
formatter = HtmlFormatter(encoding = 'utf-8',
|
||||||
@ -68,3 +79,6 @@ def colorize_blob(fname, s):
|
|||||||
|
|
||||||
return highlight(s, lexer, formatter)
|
return highlight(s, lexer, formatter)
|
||||||
|
|
||||||
|
def markdown_blob(s):
|
||||||
|
return markdown.markdown(s)
|
||||||
|
|
||||||
|
@ -36,7 +36,9 @@
|
|||||||
<a href="">{{!fname.html}}</a>
|
<a href="">{{!fname.html}}</a>
|
||||||
</h3>
|
</h3>
|
||||||
|
|
||||||
% if can_colorize(blob):
|
% if can_markdown(fname.unicode):
|
||||||
|
{{!markdown_blob(blob)}}
|
||||||
|
% elif can_colorize(blob):
|
||||||
{{!colorize_blob(fname.unicode, blob)}}
|
{{!colorize_blob(fname.unicode, blob)}}
|
||||||
% else:
|
% else:
|
||||||
<pre class="blob-body">
|
<pre class="blob-body">
|
||||||
|
Loading…
Reference in New Issue
Block a user