changeset 4310:7c094db329b3

diff: show whitespace It could be considered to use the VisibleWhitespaceFilter instead ...
author Mads Kiilerich <madski@unity3d.com>
date Fri, 18 Jul 2014 18:44:54 +0200
parents 60ae17de2a8d
children e46de90d5554
files kallithea/lib/diffs.py kallithea/lib/helpers.py kallithea/public/css/style.css
diffstat 3 files changed, 50 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/diffs.py	Tue Dec 10 19:30:37 2013 +0100
+++ b/kallithea/lib/diffs.py	Fri Jul 18 18:44:54 2014 +0200
@@ -192,7 +192,10 @@
     """, re.VERBOSE | re.MULTILINE)
 
     #used for inline highlighter word split
-    _token_re = re.compile(r'()(&gt;|&lt;|&amp;|\W+?)')
+    _token_re = re.compile(r'()(&gt;|&lt;|&amp;|<u>\t</u>| <i></i>|\W+?)')
+
+    _escape_re = re.compile(r'(&)|(<)|(>)|(\t)|( \n| $)')
+
 
     def __init__(self, diff, vcs='hg', format='gitdiff', diff_limit=None):
         """
@@ -248,9 +251,20 @@
         if self.diff_limit is not None and self.cur_diff_size > self.diff_limit:
             raise DiffLimitExceeded('Diff Limit Exceeded')
 
-        return safe_unicode(string).replace('&', '&amp;')\
-                .replace('<', '&lt;')\
-                .replace('>', '&gt;')
+        def substitute(m):
+            groups = m.groups()
+            if groups[0]:
+                return '&amp;'
+            if groups[1]:
+                return '&lt;'
+            if groups[2]:
+                return '&gt;'
+            if groups[3]:
+                return '<u>\t</u>'
+            if groups[4] and m.start(): # skip 1st column with +/-
+                return ' <i></i>'
+
+        return self._escape_re.sub(substitute, safe_unicode(string))
 
     def _line_counter(self, l):
         """
--- a/kallithea/lib/helpers.py	Tue Dec 10 19:30:37 2013 +0100
+++ b/kallithea/lib/helpers.py	Fri Jul 18 18:44:54 2014 +0200
@@ -266,6 +266,18 @@
         yield 0, '</td></tr></table>'
 
 
+_whitespace_re = re.compile(r'(\t)|( )(?=\n|</div>)')
+
+def _markup_whitespace(m):
+    groups = m.groups()
+    if groups[0]:
+        return '<u>\t</u>'
+    if groups[1]:
+        return ' <i></i>'
+
+def markup_whitespace(s):
+    return _whitespace_re.sub(_markup_whitespace, s)
+
 def pygmentize(filenode, **kwargs):
     """
     pygmentize function using pygments
@@ -273,8 +285,8 @@
     :param filenode:
     """
     lexer = get_custom_lexer(filenode.extension) or filenode.lexer
-    return literal(code_highlight(filenode.content, lexer,
-                                  CodeHtmlFormatter(**kwargs)))
+    return literal(markup_whitespace(
+        code_highlight(filenode.content, lexer, CodeHtmlFormatter(**kwargs))))
 
 
 def pygmentize_annotation(repo_name, filenode, **kwargs):
@@ -361,7 +373,7 @@
             return uri
         return _url_func
 
-    return literal(annotate_highlight(filenode, url_func(repo_name), **kwargs))
+    return literal(markup_whitespace(annotate_highlight(filenode, url_func(repo_name), **kwargs)))
 
 
 def is_following_repo(repo_name, user_id):
--- a/kallithea/public/css/style.css	Tue Dec 10 19:30:37 2013 +0100
+++ b/kallithea/public/css/style.css	Fri Jul 18 18:44:54 2014 +0200
@@ -4974,6 +4974,23 @@
     text-decoration: none;
 }
 
+table.code-highlighttable div.code-highlight pre u:before,
+table.code-difftable td.code pre u:before {
+    content: "\21a6";
+    display: inline-block;
+    width: 0;
+}
+table.code-highlighttable div.code-highlight pre u,
+table.code-difftable td.code pre u {
+    color: rgba(0,0,0,0.15);
+}
+table.code-highlighttable div.code-highlight pre i,
+table.code-difftable td.code pre i {
+    border-style: solid;
+    border-left-width: 1px;
+    color: rgba(0,0,0,0.15);
+}
+
 /** LINE NUMBERS **/
 table.code-difftable .lineno {
     padding-left: 2px;