From 91539b8134f6bd967b5dc44f95345ef1686a2897 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Dec 15 2016 12:13:57 +0000 Subject: [PATCH 1/2] Only split the line if the content we want to split is in it --- diff --git a/pagure/ui/filters.py b/pagure/ui/filters.py index 4f7efdb..1cb41b0 100644 --- a/pagure/ui/filters.py +++ b/pagure/ui/filters.py @@ -281,7 +281,7 @@ def blame_loc(loc, repo, username, blame): # Happens at the end of the file, since we are using idx + 1 continue - if line.startswith('' in line: line = line.split('
')[1]
 
         output.append(

From 8bec250deafdd83df71f15f70e11774f20605830 Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon 
Date: Dec 15 2016 12:14:29 +0000
Subject: [PATCH 2/2] Convert to byte before guessing the encoding and try highlighting the content


This mimic the behavior used in the view_file endpoint and should bring
a little more stability to the blame feature.

---

diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py
index bd94814..ba41e46 100644
--- a/pagure/ui/repo.py
+++ b/pagure/ui/repo.py
@@ -725,6 +725,12 @@ def view_blame_file(repo, filename, username=None, namespace=None):
         LOG.exception('File could not be decoded')
         flask.abort(500, 'File could not be decoded')
 
+    lexer = TextLexer()
+    content = highlight(
+        content,
+        lexer,
+        HtmlFormatter(noclasses=True, style="tango")
+    )
     blame = repo_obj.blame(filename)
 
     return flask.render_template(