Make embedding markdown and images configurable per-repo
This patch introduces the embed_markdown and embed_images configuration options, so users can enable and disable those features on a per-repository basis. Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
This commit is contained in:
parent
a42d7da6a4
commit
54026b7585
5
git-arr
5
git-arr
@ -55,6 +55,8 @@ def load_config(path):
|
||||
'web_url_file': 'web_url',
|
||||
'git_url': '',
|
||||
'git_url_file': 'cloneurl',
|
||||
'embed_markdown': 'yes',
|
||||
'embed_images': 'no',
|
||||
}
|
||||
|
||||
config = configparser.SafeConfigParser(defaults)
|
||||
@ -115,6 +117,9 @@ def load_config(path):
|
||||
if not r.info.git_url and os.path.isfile(git_url_file):
|
||||
r.info.git_url = open(git_url_file).read()
|
||||
|
||||
r.info.embed_markdown = config.getboolean(s, 'embed_markdown')
|
||||
r.info.embed_images = config.getboolean(s, 'embed_images')
|
||||
|
||||
repos[r.name] = r
|
||||
|
||||
def find_git_dir(path):
|
||||
|
15
utils.py
15
utils.py
@ -48,21 +48,24 @@ def can_colorize(s):
|
||||
|
||||
return True
|
||||
|
||||
def can_markdown(fname):
|
||||
def can_markdown(repo, fname):
|
||||
"""True if we can process file through markdown, False otherwise."""
|
||||
if markdown is None:
|
||||
return False
|
||||
|
||||
if not repo.info.embed_markdown:
|
||||
return False
|
||||
|
||||
return fname.endswith(".md")
|
||||
|
||||
def can_embed_image(fname):
|
||||
def can_embed_image(repo, fname):
|
||||
"""True if we can embed image file in HTML, False otherwise."""
|
||||
exts = [ 'jpg', 'jpeg', 'png', 'gif' ]
|
||||
if '.' in fname and fname.split('.')[-1].lower() in exts:
|
||||
return True
|
||||
|
||||
if not repo.info.embed_images:
|
||||
return False
|
||||
|
||||
return (('.' in fname) and
|
||||
(fname.split('.')[-1].lower() in [ 'jpg', 'jpeg', 'png', 'gif' ]))
|
||||
|
||||
def colorize_diff(s):
|
||||
lexer = lexers.DiffLexer(encoding = 'utf-8')
|
||||
formatter = HtmlFormatter(encoding = 'utf-8',
|
||||
|
@ -36,9 +36,9 @@
|
||||
<a href="">{{!fname.html}}</a>
|
||||
</h3>
|
||||
|
||||
% if can_embed_image(fname.unicode):
|
||||
% if can_embed_image(repo, fname.unicode):
|
||||
{{!embed_image_blob(repo, dirname.raw, fname.raw)}}
|
||||
% elif can_markdown(fname.unicode):
|
||||
% elif can_markdown(repo, fname.unicode):
|
||||
{{!markdown_blob(blob)}}
|
||||
% elif can_colorize(blob):
|
||||
{{!colorize_blob(fname.unicode, blob)}}
|
||||
|
Loading…
Reference in New Issue
Block a user