diff --git a/pagure/templates/_repo_renderdiff.html b/pagure/templates/_repo_renderdiff.html index a3997a6..f3d898d 100644 --- a/pagure/templates/_repo_renderdiff.html +++ b/pagure/templates/_repo_renderdiff.html @@ -260,7 +260,7 @@ {% else %}
{% autoescape false %} - {{ patch | patch_to_diff | html_diff(linenos=None) | format_loc( + {{ patch | patch_to_diff | format_loc( filename=patch_new_file_path, commit=patch_new_id, prequest=pull_request, diff --git a/pagure/templates/patchfile.html b/pagure/templates/patchfile.html index fd1079a..f3a724e 100644 --- a/pagure/templates/patchfile.html +++ b/pagure/templates/patchfile.html @@ -16,7 +16,7 @@
{% autoescape false %} - {{ diff|html_diff }} + {{ diff }} {% endautoescape %}

diff --git a/pagure/ui/diff_style.py b/pagure/ui/diff_style.py deleted file mode 100644 index 44cfda4..0000000 --- a/pagure/ui/diff_style.py +++ /dev/null @@ -1,111 +0,0 @@ -# -*- coding: utf-8 -*- - -""" - (c) 2016-2017 - Copyright Red Hat Inc - - Authors: - Mark Reynolds - -""" - -from __future__ import unicode_literals - -from pygments.style import Style -from pygments.token import Keyword, Name, Comment, String, Error, \ - Number, Operator, Generic, Whitespace, Punctuation, Other, Literal - - -class DiffStyle(Style): # flake8: noqa - Ignore this entire file - """This style is based off of "tango", and has been updated to show the - background color of changed lines so that trailing white spaces can be - identified.""" - - background_color = "#f8f8f8" - default_style = "" - - styles = { - # No corresponding class for the following: - #Text: "", # class: '' - Whitespace: "underline #f8f8f8", # class: 'w' - Error: "#a40000 border:#ef2929", # class: 'err' - Other: "#000000", # class 'x' - - Comment: "italic #8f5902", # class: 'c' - Comment.Multiline: "italic #8f5902", # class: 'cm' - Comment.Preproc: "italic #8f5902", # class: 'cp' - Comment.Single: "italic #8f5902", # class: 'c1' - Comment.Special: "italic #8f5902", # class: 'cs' - - Keyword: "bold #204a87", # class: 'k' - Keyword.Constant: "bold #204a87", # class: 'kc' - Keyword.Declaration: "bold #204a87", # class: 'kd' - Keyword.Namespace: "bold #204a87", # class: 'kn' - Keyword.Pseudo: "bold #204a87", # class: 'kp' - Keyword.Reserved: "bold #204a87", # class: 'kr' - Keyword.Type: "bold #204a87", # class: 'kt' - - Operator: "bold #ce5c00", # class: 'o' - Operator.Word: "bold #204a87", # class: 'ow' - like keywords - - Punctuation: "bold #000000", # class: 'p' - - # Because special names such as Name.Class, Name.Function, etc. - # are not recognized as such later in the parsing, we choose them - # to look the same as ordinary variables. - Name: "#000000", # class: 'n' - Name.Attribute: "#c4a000", # class: 'na' - to be revised - Name.Builtin: "#204a87", # class: 'nb' - Name.Builtin.Pseudo: "#3465a4", # class: 'bp' - Name.Class: "#000000", # class: 'nc' - to be revised - Name.Constant: "#000000", # class: 'no' - to be revised - Name.Decorator: "bold #5c35cc", # class: 'nd' - to be revised - Name.Entity: "#ce5c00", # class: 'ni' - Name.Exception: "bold #cc0000", # class: 'ne' - Name.Function: "#000000", # class: 'nf' - Name.Property: "#000000", # class: 'py' - Name.Label: "#f57900", # class: 'nl' - Name.Namespace: "#000000", # class: 'nn' - to be revised - Name.Other: "#000000", # class: 'nx' - Name.Tag: "bold #204a87", # class: 'nt' - like a keyword - Name.Variable: "#000000", # class: 'nv' - to be revised - Name.Variable.Class: "#000000", # class: 'vc' - to be revised - Name.Variable.Global: "#000000", # class: 'vg' - to be revised - Name.Variable.Instance: "#000000", # class: 'vi' - to be revised - - # since the tango light blue does not show up well in text, we choose - # a pure blue instead. - Number: "bold #0000cf", # class: 'm' - Number.Float: "bold #0000cf", # class: 'mf' - Number.Hex: "bold #0000cf", # class: 'mh' - Number.Integer: "bold #0000cf", # class: 'mi' - Number.Integer.Long: "bold #0000cf", # class: 'il' - Number.Oct: "bold #0000cf", # class: 'mo' - - Literal: "#000000", # class: 'l' - Literal.Date: "#000000", # class: 'ld' - - String: "#4e9a06", # class: 's' - String.Backtick: "#4e9a06", # class: 'sb' - String.Char: "#4e9a06", # class: 'sc' - String.Doc: "italic #8f5902", # class: 'sd' - like a comment - String.Double: "#4e9a06", # class: 's2' - String.Escape: "#4e9a06", # class: 'se' - String.Heredoc: "#4e9a06", # class: 'sh' - String.Interpol: "#4e9a06", # class: 'si' - String.Other: "#4e9a06", # class: 'sx' - String.Regex: "#4e9a06", # class: 'sr' - String.Single: "#4e9a06", # class: 's1' - String.Symbol: "#4e9a06", # class: 'ss' - - Generic: "#000000", # class: 'g' - Generic.Deleted: 'bg:#ffdddd #a40000', # trac bg color - Generic.Inserted: 'bg:#ddffdd #00A000', # trac bg color - Generic.Emph: "italic #000000", # class: 'ge' - Generic.Error: "#ef2929", # class: 'gr' - Generic.Heading: "bold #000080", # class: 'gh' - Generic.Output: "italic #000000", # class: 'go' - Generic.Prompt: "#8f5902", # class: 'gp' - Generic.Strong: "bold #000000", # class: 'gs' - Generic.Subheading: "bold #800080", # class: 'gu' - Generic.Traceback: "bold #a40000", # class: 'gt' - } diff --git a/pagure/ui/filters.py b/pagure/ui/filters.py index b9840ac..01df37f 100644 --- a/pagure/ui/filters.py +++ b/pagure/ui/filters.py @@ -22,10 +22,6 @@ import flask import six from six.moves.urllib.parse import urlparse, parse_qsl -from pygments import highlight -from pygments.lexers.text import DiffLexer -from pygments.formatters import HtmlFormatter -from pygments.filters import VisibleWhitespaceFilter from jinja2 import escape import pagure.exceptions @@ -94,7 +90,7 @@ def format_loc(loc, commit=None, filename=None, tree_id=None, prequest=None, comments = {} if prequest and not isinstance(prequest, flask.wrappers.Request): for com in prequest.comments: - if commit and com.commit_id == commit \ + if commit and com.commit_id == commit.hex \ and com.filename == filename: if com.line in comments: comments[com.line].append(com) @@ -109,8 +105,6 @@ def format_loc(loc, commit=None, filename=None, tree_id=None, prequest=None, cnt = 1 for line in loc.split('\n'): - if line == '': - break if filename and commit: if isinstance(filename, str) and six.PY2: filename = filename.decode('UTF-8') @@ -152,14 +146,12 @@ def format_loc(loc, commit=None, filename=None, tree_id=None, prequest=None, if not line: output.append(line) continue - if line.startswith('')[1] + if line.startswith('@@'): if prequest and prequest.project_from: - rangeline = line.partition('font-weight: bold">@@ ')[2] \ - if line.partition('font-weight: bold">@@ ')[1] == \ - 'font-weight: bold">@@ ' else None + rangeline = line.partition('@@ ')[2] \ + if line.partition('@@ ')[1] == '@@ ' else None if rangeline: - rangeline = rangeline.split(' @@')[0] + rangeline = rangeline.split(' @@')[0] linenumber = rangeline.split('+')[1].split(',')[0] line = line + ' ' + \ - '' - output.append('

%s
' % line) + output.append( + '
%s
' % line) output.append('') tpl_edit = '
%s
' % line) + output.append( + '
%s
' % line) output.append('') output.append('') @@ -414,29 +408,6 @@ def markdown_filter(text): return pagure.lib.text2markdown(text) -@UI_NS.app_template_filter('html_diff') -def html_diff(diff, linenos='inline'): - """Display diff as HTML""" - if diff is None: - return - difflexer = DiffLexer() - # Do not give whitespaces the special Whitespace token type as this - # prevents the html formatter from picking up on trailing whitespaces in - # the diff. - difflexer.add_filter(VisibleWhitespaceFilter(wstokentype=False, tabs=True)) - - style = 'diffstyle' - - return highlight( - diff, - difflexer, - HtmlFormatter( - linenos=linenos, - noclasses=True, - style=style) - ) - - @UI_NS.app_template_filter('patch_to_diff') def patch_to_diff(patch): """Render a hunk as a diff""" diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index 4def7b5..7ca7ee2 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -33,12 +33,6 @@ import werkzeug from six import BytesIO from PIL import Image -from pygments import highlight -from pygments.formatters import HtmlFormatter -from pygments.lexers import guess_lexer_for_filename -from pygments.lexers.special import TextLexer -from pygments.util import ClassNotFound -from pygments.filters import VisibleWhitespaceFilter from sqlalchemy.exc import SQLAlchemyError from binaryornot.helpers import is_binary_string @@ -564,28 +558,8 @@ def view_file(repo, identifier, filename, username=None, namespace=None): # it. output_type = 'binary' if file_content is not None: - try: - lexer = guess_lexer_for_filename( - filename, - file_content - ) - except (ClassNotFound, TypeError): - lexer = TextLexer() - - style = "tango" - - if ext in ('.diff', '.patch'): - lexer.add_filter(VisibleWhitespaceFilter( - wstokentype=False, tabs=True)) - style = "diffstyle" - content = highlight( - file_content, - lexer, - HtmlFormatter( - noclasses=True, - style=style,) - ) output_type = 'file' + content = content.data.decode('utf-8') else: output_type = 'binary' elif not isbinary: @@ -752,12 +726,6 @@ 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, newest_commit=commit.oid.hex) return flask.render_template( diff --git a/setup.py b/setup.py index 2e971c6..38cdaf1 100644 --- a/setup.py +++ b/setup.py @@ -53,9 +53,6 @@ setup( include_package_data=True, install_requires=get_requirements(), entry_points=""" - [pygments.styles] - diffstyle = pagure.ui.diff_style:DiffStyle - [console_scripts] pagure-admin=pagure.cli.admin:main diff --git a/tests/test_pagure_flask_ui_fork.py b/tests/test_pagure_flask_ui_fork.py index 3447244..4dcc503 100644 --- a/tests/test_pagure_flask_ui_fork.py +++ b/tests/test_pagure_flask_ui_fork.py @@ -284,7 +284,7 @@ class PagureFlaskForktests(tests.Modeltests): # Test if the `open changed file icon` is displayed. self.assertIn( 'class="open_changed_file_icon_wrap">' '
', output_text) @@ -2058,7 +2058,7 @@ index 0000000..2a552bb # Test if the `open changed file icon` is displayed. self.assertIn( 'class="open_changed_file_icon_wrap">' '', output_text) diff --git a/tests/test_pagure_flask_ui_no_master_branch.py b/tests/test_pagure_flask_ui_no_master_branch.py index 45a49c5..38270a9 100644 --- a/tests/test_pagure_flask_ui_no_master_branch.py +++ b/tests/test_pagure_flask_ui_no_master_branch.py @@ -225,13 +225,9 @@ class PagureFlaskNoMasterBranchtests(tests.SimplePagureTest):   sources ''', output_text) - self.assertTrue( - # new version of pygments - '
foo
' in output_text - or - # old version of pygments - '
foo
' in output_text - ) + self.assertIn( + '
foo
', output_text + ) @patch('pagure.lib.notify.send_email') def test_view_raw_file(self, send_email): diff --git a/tests/test_pagure_flask_ui_repo.py b/tests/test_pagure_flask_ui_repo.py index 2a23947..80d8b5d 100644 --- a/tests/test_pagure_flask_ui_repo.py +++ b/tests/test_pagure_flask_ui_repo.py @@ -2055,9 +2055,7 @@ class PagureFlaskRepotests(tests.Modeltests): self.assertNotIn( 'id="show_hidden_commits"', output_text) - self.assertIn( - '- ' + - 'Row 0', output_text) + self.assertIn('
- Row 0
', output_text) # View inverse commits comparison output = self.app.get('/test/c/%s..%s' % (c1.oid.hex, c2.oid.hex)) self.assertEqual(output.status_code, 200) @@ -2073,9 +2071,7 @@ class PagureFlaskRepotests(tests.Modeltests): ' %s\n ..\n %s\n' % (c1.oid.hex, c2.oid.hex), output_text) - self.assertIn( - '' + - '+ Row 0', output_text) + self.assertIn('
+ Row 0
', output_text) def compare_all(c1, c3): # View commits comparison @@ -2089,13 +2085,9 @@ class PagureFlaskRepotests(tests.Modeltests): ' %s\n ..\n %s\n' % (c1.oid.hex, c3.oid.hex), output_text) - self.assertIn( - '+ Row 0', output_text) + self.assertIn('
+ Row 0
', output_text) self.assertEqual( - output_text.count( - '+ Row 0'), 2) + output_text.count('
+ Row 0
'), 2) self.assertIn( '1 more commits...', output_text) @@ -2120,11 +2112,8 @@ class PagureFlaskRepotests(tests.Modeltests): (c3.oid.hex, c1.oid.hex), output_text) self.assertIn( - '@@ -1,2 +1,1' + - ' @@', output_text) - self.assertIn( - '- ' + - 'Row 0', output_text) + '
@@ -1,2 +1,1 @@
', output_text) + self.assertIn('
- Row 0
', output_text) self.assertIn( '
1 more commits...', output_text) @@ -2218,7 +2207,7 @@ class PagureFlaskRepotests(tests.Modeltests): '', output_text) self.assertIn( - '
 bar
', output_text) + '
 bar
', output_text) # Empty files should also be displayed tests.add_content_to_git( @@ -2317,11 +2306,9 @@ class PagureFlaskRepotests(tests.Modeltests): self.assertIn( '', output_text) - self.assertTrue( - '
Row 0
' - in output_text - or - '
Row 0
' in output_text + self.assertIn( + '
Row 0
', + output_text ) # Add a fork of a fork @@ -2364,7 +2351,8 @@ class PagureFlaskRepotests(tests.Modeltests): '', output_text) self.assertIn( - '
 barRow 0
', output_text) + '
 barRow 0
', + output_text) @patch( 'pagure.lib.encoding_utils.decode', @@ -2562,7 +2550,7 @@ class PagureFlaskRepotests(tests.Modeltests): '', output_text) self.assertIn( - '
 bar
', output_text) + '
 bar
', output_text) data = regex.findall(output_text) self.assertEqual(len(data), 2) @@ -2580,7 +2568,7 @@ class PagureFlaskRepotests(tests.Modeltests): '', output_text) self.assertIn( - '
 bar
', output_text) + '
 bar
', output_text) data = regex.findall(output_text) self.assertEqual(len(data), 2) @@ -2593,7 +2581,7 @@ class PagureFlaskRepotests(tests.Modeltests): '', output_text) self.assertIn( - '
 bar
', output_text) + '
 bar
', output_text) data2 = regex.findall(output_text) self.assertEqual(len(data2), 2) self.assertNotEqual(data, data2) @@ -2639,12 +2627,9 @@ class PagureFlaskRepotests(tests.Modeltests): self.assertIn( '', output_text) - self.assertTrue( - '
Row 0
' - in output_text - or - '
Row 0
' - in output_text + self.assertIn( + '
Row 0
', + output_text ) # Add a fork of a fork @@ -2678,7 +2663,8 @@ class PagureFlaskRepotests(tests.Modeltests): '', output_text) self.assertIn( - '
 barRow 0
', output_text) + '
 barRow 0
', + output_text) def test_view_blame_file_on_tag(self): """ Test the view_blame_file endpoint. """ @@ -2710,7 +2696,7 @@ class PagureFlaskRepotests(tests.Modeltests): '', output_text) self.assertIn( - '
 bar
', output_text) + '
 bar
', output_text) data = regex.findall(output_text) self.assertEqual(len(data), 2) diff --git a/tests/test_pagure_flask_ui_repo_view_file.py b/tests/test_pagure_flask_ui_repo_view_file.py index a79b7cc..cd551b3 100644 --- a/tests/test_pagure_flask_ui_repo_view_file.py +++ b/tests/test_pagure_flask_ui_repo_view_file.py @@ -104,8 +104,9 @@ class PagureFlaskRepoViewFiletests(LocalBasetests): '' in output_text) - self.assertTrue( - '
 bar
' in output_text) + self.assertIn( + '
 bar
', + output_text) def test_view_file_empty_file(self): """ Test the view_file with an empty file. """ @@ -220,11 +221,9 @@ class PagureFlaskRepoViewFiletests(LocalBasetests): self.assertIn( '', output_text) - self.assertTrue( - '
Row 0
' - in output_text - or - '
Row 0
' in output_text + self.assertIn( + '
Row 0
', + output_text ) def test_view_file_fork_and_edit_logged_out(self): @@ -328,7 +327,8 @@ class PagureFlaskRepoViewFileForktests(LocalBasetests): 'data-line-number="1">', output_text) self.assertIn( - '
 barRow 0
', output_text) + '
 barRow 0
', + output_text) def test_view_file_fork_and_edit_on_fork_logged_out(self): """ Test the view_file on a text file on a fork when logged out. """ diff --git a/tests/test_pagure_flask_ui_slash_branch_name.py b/tests/test_pagure_flask_ui_slash_branch_name.py index e98547a..7c09903 100644 --- a/tests/test_pagure_flask_ui_slash_branch_name.py +++ b/tests/test_pagure_flask_ui_slash_branch_name.py @@ -227,12 +227,8 @@ class PagureFlaskSlashInBranchtests(tests.SimplePagureTest):
  .gitignore ''', output_text) - self.assertTrue( - # new version of pygments - '
*~
' in output_text - or - # old version of pygments - '
*~
' in output_text) + self.assertIn( + '
*~
', output_text) @patch('pagure.lib.notify.send_email') def test_view_raw_file(self, send_email):