From 8902360bb8baa549746d5ed51aef06fd15ae9a28 Mon Sep 17 00:00:00 2001 From: Julen Landa Alustiza Date: Jun 24 2019 06:23:22 +0000 Subject: [PATCH 1/3] pagure markdown extension: encapsulate our markdowns on a div tag --- diff --git a/pagure/pfmarkdown.py b/pagure/pfmarkdown.py index 1666758..b46f48f 100644 --- a/pagure/pfmarkdown.py +++ b/pagure/pfmarkdown.py @@ -25,6 +25,7 @@ import flask import markdown.inlinepatterns import markdown.preprocessors +import markdown.postprocessors import markdown.util import pygit2 import re @@ -369,6 +370,11 @@ class ImagePatternLazyLoad(ImagePattern): return output +class EncapsulateMarkdownPostprocessor(markdown.postprocessors.Postprocessor): + def run(self, text): + return '
' + text + "
" + + class PagureExtension(markdown.extensions.Extension): def extendMarkdown(self, md, md_globals): # First, make it so that bare links get automatically linkified. @@ -410,6 +416,8 @@ class PagureExtension(markdown.extensions.Extension): md.inlinePatterns["striked"] = StrikeThroughPattern(STRIKE_THROUGH_RE) + md.postprocessors["encapsulate"] = EncapsulateMarkdownPostprocessor() + md.registerExtension(self) From bac1b3160c2743feda049350ac373c88b7a167d3 Mon Sep 17 00:00:00 2001 From: Julen Landa Alustiza Date: Jun 24 2019 06:23:48 +0000 Subject: [PATCH 2/3] Add styling for markdown tables --- diff --git a/pagure/static/pagure.css b/pagure/static/pagure.css index 37f9d2e..31206a7 100644 --- a/pagure/static/pagure.css +++ b/pagure/static/pagure.css @@ -507,3 +507,21 @@ th[data-sort] { .flex-1{ flex:1; } + +.markdown table { + display: block; + overflow: auto; + width: 100%; + margin-bottom: 5px; + background-color: #fff; +} + +.markdown table tr { + border-top: 1px solid #c6cbd1; +} + +.markdown table td, .markdown table th { + border: 1px solid #dfe2e5; + padding: 6px 13px; +} + From 40c5e440829372de0a87016f865186a191fe2fde Mon Sep 17 00:00:00 2001 From: Julen Landa Alustiza Date: Jun 24 2019 08:53:08 +0000 Subject: [PATCH 3/3] Fix tests where markdown is involved --- diff --git a/tests/test_pagure_flask_api_user.py b/tests/test_pagure_flask_api_user.py index 37a5091..e93d5b5 100644 --- a/tests/test_pagure_flask_api_user.py +++ b/tests/test_pagure_flask_api_user.py @@ -351,7 +351,7 @@ class PagureFlaskApiUSertests(tests.Modeltests): "date": date, "date_created": "1477558752", "type": "pull-request", - "description_mk": '

pingou created PR test#1

', + "description_mk": '

pingou created PR test#1

', "id": 1, "ref_id": "1", "type": "created", @@ -361,7 +361,7 @@ class PagureFlaskApiUSertests(tests.Modeltests): "date": date, "date_created": "1477558752", "type": "pull-request", - "description_mk": '

pingou commented on PR test#1

', + "description_mk": '

pingou commented on PR test#1

', "id": 2, "ref_id": "1", "type": "commented", @@ -371,7 +371,7 @@ class PagureFlaskApiUSertests(tests.Modeltests): "date": date, "date_created": "1477558752", "type": "pull-request", - "description_mk": '

pingou closed PR test#1

', + "description_mk": '

pingou closed PR test#1

', "id": 3, "ref_id": "1", "type": "closed", @@ -381,7 +381,7 @@ class PagureFlaskApiUSertests(tests.Modeltests): "date": date, "date_created": "1477558752", "type": "pull-request", - "description_mk": '

pingou commented on PR test#1

', + "description_mk": '

pingou commented on PR test#1

', "id": 4, "ref_id": "1", "type": "commented", @@ -427,7 +427,7 @@ class PagureFlaskApiUSertests(tests.Modeltests): data = json.loads(output.get_data(as_text=True)) exp = { "activities": [ - {"description_mk": "

pingou committed on test#githash

"} + {"description_mk": '

pingou committed on test#githash

'} ], "date": date, } @@ -532,7 +532,7 @@ class PagureFlaskApiUSertests(tests.Modeltests): data = json.loads(output.get_data(as_text=True)) exp = { "activities": [ - {"description_mk": "

pingou committed on test#githash

"} + {"description_mk": '

pingou committed on test#githash

'} ], "date": utcdate, } @@ -641,7 +641,7 @@ class PagureFlaskApiUSertests(tests.Modeltests): data = json.loads(output.get_data(as_text=True)) exp = { "activities": [ - {"description_mk": "

pingou committed on test#githash

"} + {"description_mk": '

pingou committed on test#githash

'} ], "date": utcdate, } diff --git a/tests/test_pagure_flask_ui_app.py b/tests/test_pagure_flask_ui_app.py index 793245d..37f16d5 100644 --- a/tests/test_pagure_flask_ui_app.py +++ b/tests/test_pagure_flask_ui_app.py @@ -910,8 +910,8 @@ class PagureFlaskApptests(tests.Modeltests): ) self.assertIn( """
-

project-1

-

Prõjéctö #1

+

project-1

+

Prõjéctö #1

""", output_text, ) @@ -931,8 +931,8 @@ class PagureFlaskApptests(tests.Modeltests): ) self.assertIn( """
-

project-2

-

Мой первый суперский репозиторий

+

project-2

+

Мой первый суперский репозиторий

""", output_text, ) @@ -1345,11 +1345,11 @@ class PagureFlaskApptests(tests.Modeltests): data["csrf_token"] = csrf_token output = self.app.post("/markdown/", data=data) self.assertEqual(output.status_code, 200) - exp = """

test

+ exp = """

test

  • 1
  • item 2
  • -
""" +
""" self.assertEqual(output.get_data(as_text=True), exp) tests.create_projects(self.session) @@ -1362,22 +1362,22 @@ class PagureFlaskApptests(tests.Modeltests): ] expected = [ # 'pingou committed on test#9364354a4555ba17aa60f0dc844d70b74eb1aecd', - '

pingou committed on

pingou committed on test#9364354a4555ba17aa60f0dc844d70b74eb1aecd

", + ">test#9364354a4555ba17aa60f0dc844d70b74eb1aecd

", # 'Cf commit 936435', - "

Cf commit 936435

", + '

Cf commit 936435

', # 'Cf commit 9364354', #'

Cf commit 9364354

', - '

Cf commit 9364354

', + '

Cf commit 9364354

', # 'Cf commit 9364354a', - '

Cf commit 9364354

', + '

Cf commit 9364354

', # 'Cf commit 9364354a4555ba17aa60f0dc844d70b74eb1aecd', - '

Cf commit

Cf commit 9364354

", + ">9364354

", ] with self.app.application.app_context(): @@ -1406,7 +1406,7 @@ class PagureFlaskApptests(tests.Modeltests): tests.create_projects(self.session) tests.create_projects_git(os.path.join(self.path, "repos"), bare=True) text = "Cf commit 9364354a4555ba17aa60f0d" - exp = "

Cf commit 9364354a4555ba17aa60f0d

" + exp = '

Cf commit 9364354a4555ba17aa60f0d

' with self.app.application.app_context(): data = {"content": text, "csrf_token": csrf_token} @@ -1439,8 +1439,8 @@ class PagureFlaskApptests(tests.Modeltests): text = "Cf commit %s" % first_commit.oid.hex exp = ( - '

Cf commit {1}' - "

".format(first_commit.oid.hex, first_commit.oid.hex[:7]) + '

Cf commit {1}' + "

".format(first_commit.oid.hex, first_commit.oid.hex[:7]) ) with self.app.application.app_context(): diff --git a/tests/test_pagure_flask_ui_issues.py b/tests/test_pagure_flask_ui_issues.py index f63b964..0220f4d 100644 --- a/tests/test_pagure_flask_ui_issues.py +++ b/tests/test_pagure_flask_ui_issues.py @@ -2119,11 +2119,11 @@ class PagureFlaskIssuestests(tests.Modeltests): # FIXME: There is likely something going wrong in the html # below self.assertIn( - '' + '
' '

Metadata Update from ' '@pingou:' "
\n- Issue close_status updated to: Fixed
\n- Issue status updated to:" - " Closed (was: Open)

\n", + " Closed (was: Open)

\n", output_text, ) @@ -4550,8 +4550,8 @@ class PagureFlaskIssuestests(tests.Modeltests): self.assertEqual(output.status_code, 200) self.assertIn( '' - '

foo bar #1 see?

', + '

foo bar #1 see?

', output.get_data(as_text=True), ) @@ -4680,8 +4680,8 @@ class PagureFlaskIssuestests(tests.Modeltests): self.assertEqual(output.status_code, 200) self.assertIn( '' - '

foo bar #1 see?

', + '

foo bar #1 see?

', output.get_data(as_text=True), ) diff --git a/tests/test_pagure_lib.py b/tests/test_pagure_lib.py index d999089..790d234 100644 --- a/tests/test_pagure_lib.py +++ b/tests/test_pagure_lib.py @@ -4244,93 +4244,93 @@ class PagureLibtests(tests.Modeltests): ] expected = [ # 'foo bar test#1 see?', - '

foo bar test#1 see?

', + '

foo bar test#1 see?

', # 'foo bar pingou/test#2 I mean, really', -- unknown namespace - "

foo bar pingou/test#2 I mean, really

", + '

foo bar pingou/test#2 I mean, really

', # 'foo bar fork/pingou/test#2 bouza!', - '

foo bar

foo bar ' - "pingou/test#2 bouza!

", + "pingou/test#2 bouza!

", # 'foo bar forks/pingou/test#2 bouza!', -- the 's' doesn't matter - '

foo bar

foo bar ' - "pingou/test#2 bouza!

", + "pingou/test#2 bouza!

", # 'foo bar ns/test3#4 bouza!', - '

foo bar ns/test3#4 bouza!

', + '

foo bar ns/test3#4 bouza!

', # 'foo bar fork/user/ns/test#5 bouza!', -- unknown fork - "

foo bar user/ns/test#5 bouza!

", + '

foo bar user/ns/test#5 bouza!

', # 'foo bar fork/pingou/ns/test#7 bouza!', - '

foo bar

foo bar ' - "pingou/ns/test#7 bouza!

", + "pingou/ns/test#7 bouza!

", # 'test#1 bazinga!', - '

test#1 bazinga!

', + '

test#1 bazinga!

', # 'pingou opened the PR forks/pingou/test#2' - '

pingou opened the PR

pingou opened the PR pingou/test#2

', + 'title="[Open] test pull-request in fork">pingou/test#2

', # 'fork/pingou/ns/test#8 is private', - '

pingou/ns/test#8 is private

', + '

pingou/ns/test#8 is private

', # 'implicit link to #1', - '

implicit link to #1

', + '

implicit link to #1

', # 'implicit link .#1. with non-whitespace, non-word characters', - '

implicit link .#1. with non-whitespace, non-word characters

', + '

implicit link .#1. with non-whitespace, non-word characters

', # '#2 - implicit link at start of line', - '

#2 - implicit link at start of line

', + '

#2 - implicit link at start of line

', # '#2. implicit link at start of line with no whitespace after', - '

#2. implicit link at start of line with no whitespace after

', + '

#2. implicit link at start of line with no whitespace after

', # '#regular header', - "

regular header

", + '

regular header

', # '#34 looks like an implicit link, but no issue 34', - "

34 looks like an implicit link, but no issue 34

", + '

34 looks like an implicit link, but no issue 34

', # 'pingou committed on test#9364354a4555ba17aa60f0dc844d70b74eb1aecd', - '

pingou committed on

pingou committed on test#9364354a4555ba17aa60f0dc844d70b74eb1aecd

", + ">test#9364354a4555ba17aa60f0dc844d70b74eb1aecd

", # 'irc://pagure.io' - '

irc://pagure.io

', + '', # 'ircs://pagure.io' - This is getting cleaned by python-bleach # and the version 1.4.3 that we have won't let us adjust the # list of supported protocols # '

ircs://pagure.io

', - '

ircs://pagure.io

' + '' if tuple(bleach_v) >= (1, 5, 0) - else "

ircs://pagure.io

", + else '', # 'http://pagure.io' - '

http://pagure.io

', + '', # 'https://pagure.io' - '

https://pagure.io

', + '', # '' - '

https://pagure.io/pagure' - "

", + '", # '~~foo~~' - "

foo

", + '

foo

', # '~~foo bar~~' - "

foo bar

", + '

foo bar

', # '~~[BZ#1435310](https://bugzilla.redhat.com/1435310)~~' - '

' - "BZ#1435310

", + '", # '~~[BZ#1435310](https://bugzilla.redhat.com/1435310) avc # denial during F26AH boot 'error_name=org.freedesktop.systemd1 # .NoSuchDynamicUser~~' - '

' + '

' "BZ#1435310 avc denial during F26AH boot 'error_name=" - "org.freedesktop.systemd1.NoSuchDynamicUser'

", + "org.freedesktop.systemd1.NoSuchDynamicUser'

", # '``~~foo bar~~``' - "

~~foo bar~~

", + '

~~foo bar~~

', # '~~foo bar~~ and ~~another ~~', - "

foo bar and another

", + '

foo bar and another

', # 'lets mention @pingou', - '

lets mention @pingou

', + '

lets mention @pingou

', # '@pingou at start of line', - '

@pingou at start of line

', + '

@pingou at start of line

', # 'but not someone@pingou.com', - "

but not someone@pingou.com

", + '

but not someone@pingou.com

', ] if old_markdown: @@ -4338,26 +4338,26 @@ class PagureLibtests(tests.Modeltests): # '[![Fedora_infinity_small.png]' # '(/test/issue/raw/Fedora_infinity_small.png)]' # '(/test/issue/raw/Fedora_infinity_small.png)', - '

' + '

" ) else: expected.append( # '[![Fedora_infinity_small.png]' # '(/test/issue/raw/Fedora_infinity_small.png)]' # '(/test/issue/raw/Fedora_infinity_small.png)', - '

' + '

" ) with self.app.application.app_context(): @@ -5139,7 +5139,7 @@ class PagureLibtests(tests.Modeltests): foo bar """ - expected = """ + expected = """
@@ -5160,7 +5160,7 @@ foo bar
Left-aligned
-

foo bar

""" +

foo bar

""" with self.app.application.app_context(): html = pagure.lib.query.text2markdown(text) @@ -5182,7 +5182,7 @@ foo bar foo bar """ - expected = """ + expected = """
@@ -5203,7 +5203,7 @@ foo bar
Left-aligned
-

foo bar

""" +

foo bar

""" with self.app.application.app_context(): html = pagure.lib.query.text2markdown(text)