files: fixed unicode problems on image preview, and make images center, no-stretch.

This commit is contained in:
Marcin Kuzminski 2020-05-14 09:40:20 +02:00
parent 0021e33e42
commit 0127fbe62e
3 changed files with 7 additions and 4 deletions

View file

@ -1617,18 +1617,19 @@ def render_binary(repo_name, file_obj):
Choose how to render a binary file
"""
# unicode
filename = file_obj.name
# images
for ext in ['*.png', '*.jpg', '*.ico', '*.gif']:
for ext in ['*.png', '*.jpeg', '*.jpg', '*.ico', '*.gif']:
if fnmatch.fnmatch(filename, pat=ext):
alt = escape(filename)
src = route_path(
'repo_file_raw', repo_name=repo_name,
commit_id=file_obj.commit.raw_id,
f_path=file_obj.path)
return literal(
'<img class="rendered-binary" alt="{}" src="{}">'.format(alt, src))
'<img class="rendered-binary" alt="rendered-image" src="{}">'.format(src))
def renderer_from_filename(filename, exclude=None):

View file

@ -500,7 +500,7 @@ div.codeblock {
img.rendered-binary {
height: auto;
width: 100%;
width: auto;
}
.markdown-block {

View file

@ -115,7 +115,9 @@
%if c.file.is_binary:
<% rendered_binary = h.render_binary(c.repo_name, c.file)%>
% if rendered_binary:
<div class="text-center">
${rendered_binary}
</div>
% else:
<div>
${_('Binary file ({})').format(c.file.mimetype)}