diff --git a/kallithea/lib/diffs.py b/kallithea/lib/diffs.py --- a/kallithea/lib/diffs.py +++ b/kallithea/lib/diffs.py @@ -192,7 +192,10 @@ class DiffProcessor(object): """, re.VERBOSE | re.MULTILINE) #used for inline highlighter word split - _token_re = re.compile(r'()(>|<|&|\W+?)') + _token_re = re.compile(r'()(>|<|&|\t| |\W+?)') + + _escape_re = re.compile(r'(&)|(<)|(>)|(\t)|( \n| $)') + def __init__(self, diff, vcs='hg', format='gitdiff', diff_limit=None): """ @@ -248,9 +251,20 @@ class DiffProcessor(object): 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('&', '&')\ - .replace('<', '<')\ - .replace('>', '>') + def substitute(m): + groups = m.groups() + if groups[0]: + return '&' + if groups[1]: + return '<' + if groups[2]: + return '>' + if groups[3]: + return '\t' + if groups[4] and m.start(): # skip 1st column with +/- + return ' ' + + return self._escape_re.sub(substitute, safe_unicode(string)) def _line_counter(self, l): """ diff --git a/kallithea/lib/helpers.py b/kallithea/lib/helpers.py --- a/kallithea/lib/helpers.py +++ b/kallithea/lib/helpers.py @@ -266,6 +266,18 @@ class CodeHtmlFormatter(HtmlFormatter): yield 0, '' +_whitespace_re = re.compile(r'(\t)|( )(?=\n|)') + +def _markup_whitespace(m): + groups = m.groups() + if groups[0]: + return '\t' + if groups[1]: + return ' ' + +def markup_whitespace(s): + return _whitespace_re.sub(_markup_whitespace, s) + def pygmentize(filenode, **kwargs): """ pygmentize function using pygments @@ -273,8 +285,8 @@ def pygmentize(filenode, **kwargs): :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 @@ def pygmentize_annotation(repo_name, fil 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): diff --git a/kallithea/public/css/style.css b/kallithea/public/css/style.css --- a/kallithea/public/css/style.css +++ b/kallithea/public/css/style.css @@ -4974,6 +4974,23 @@ table.code-difftable .del del { 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;