#4509 Add styling for markdown tables
Merged 2 years ago by pingou. Opened 2 years ago by jlanda.
jlanda/pagure fix-markdown-tables  into  master

file modified
+8
@@ -25,6 +25,7 @@ 

  

  import markdown.inlinepatterns

  import markdown.preprocessors

+ import markdown.postprocessors

  import markdown.util

  import pygit2

  import re
@@ -369,6 +370,11 @@ 

          return output

  

  

+ class EncapsulateMarkdownPostprocessor(markdown.postprocessors.Postprocessor):

+     def run(self, text):

+         return '<div class="markdown">' + text + "</div>"

+ 

+ 

  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 @@ 

  

          md.inlinePatterns["striked"] = StrikeThroughPattern(STRIKE_THROUGH_RE)

  

+         md.postprocessors["encapsulate"] = EncapsulateMarkdownPostprocessor()

+ 

          md.registerExtension(self)

  

  

file modified
+18
@@ -507,3 +507,21 @@ 

  .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;

+ }

+ 

@@ -351,7 +351,7 @@ 

                      "date": date,

                      "date_created": "1477558752",

                      "type": "pull-request",

-                     "description_mk": '<p>pingou created PR <a href="/test/pull-request/1" title="[Closed] test pull-request">test#1</a></p>',

+                     "description_mk": '<div class="markdown"><p>pingou created PR <a href="/test/pull-request/1" title="[Closed] test pull-request">test#1</a></p></div>',

                      "id": 1,

                      "ref_id": "1",

                      "type": "created",
@@ -361,7 +361,7 @@ 

                      "date": date,

                      "date_created": "1477558752",

                      "type": "pull-request",

-                     "description_mk": '<p>pingou commented on PR <a href="/test/pull-request/1" title="[Closed] test pull-request">test#1</a></p>',

+                     "description_mk": '<div class="markdown"><p>pingou commented on PR <a href="/test/pull-request/1" title="[Closed] test pull-request">test#1</a></p></div>',

                      "id": 2,

                      "ref_id": "1",

                      "type": "commented",
@@ -371,7 +371,7 @@ 

                      "date": date,

                      "date_created": "1477558752",

                      "type": "pull-request",

-                     "description_mk": '<p>pingou closed PR <a href="/test/pull-request/1" title="[Closed] test pull-request">test#1</a></p>',

+                     "description_mk": '<div class="markdown"><p>pingou closed PR <a href="/test/pull-request/1" title="[Closed] test pull-request">test#1</a></p></div>',

                      "id": 3,

                      "ref_id": "1",

                      "type": "closed",
@@ -381,7 +381,7 @@ 

                      "date": date,

                      "date_created": "1477558752",

                      "type": "pull-request",

-                     "description_mk": '<p>pingou commented on PR <a href="/test/pull-request/1" title="[Closed] test pull-request">test#1</a></p>',

+                     "description_mk": '<div class="markdown"><p>pingou commented on PR <a href="/test/pull-request/1" title="[Closed] test pull-request">test#1</a></p></div>',

                      "id": 4,

                      "ref_id": "1",

                      "type": "commented",
@@ -427,7 +427,7 @@ 

          data = json.loads(output.get_data(as_text=True))

          exp = {

              "activities": [

-                 {"description_mk": "<p>pingou committed on test#githash</p>"}

+                 {"description_mk": '<div class="markdown"><p>pingou committed on test#githash</p></div>'}

              ],

              "date": date,

          }
@@ -532,7 +532,7 @@ 

          data = json.loads(output.get_data(as_text=True))

          exp = {

              "activities": [

-                 {"description_mk": "<p>pingou committed on test#githash</p>"}

+                 {"description_mk": '<div class="markdown"><p>pingou committed on test#githash</p></div>'}

              ],

              "date": utcdate,

          }
@@ -641,7 +641,7 @@ 

          data = json.loads(output.get_data(as_text=True))

          exp = {

              "activities": [

-                 {"description_mk": "<p>pingou committed on test#githash</p>"}

+                 {"description_mk": '<div class="markdown"><p>pingou committed on test#githash</p></div>'}

              ],

              "date": utcdate,

          }

@@ -910,8 +910,8 @@ 

              )

              self.assertIn(

                  """<section class="readme">

-               <h1>project-1</h1>

- <p>Prõjéctö #1</p>

+               <div class="markdown"><h1>project-1</h1>

+ <p>Prõjéctö #1</p></div>

              </section>""",

                  output_text,

              )
@@ -931,8 +931,8 @@ 

              )

              self.assertIn(

                  """<section class="readme">

-               <h1>project-2</h1>

- <p>Мой первый суперский репозиторий</p>

+               <div class="markdown"><h1>project-2</h1>

+ <p>Мой первый суперский репозиторий</p></div>

              </section>""",

                  output_text,

              )
@@ -1345,11 +1345,11 @@ 

          data["csrf_token"] = csrf_token

          output = self.app.post("/markdown/", data=data)

          self.assertEqual(output.status_code, 200)

-         exp = """<h2>test</h2>

+         exp = """<div class="markdown"><h2>test</h2>

  <ul>

  <li>1</li>

  <li>item 2</li>

- </ul>"""

+ </ul></div>"""

          self.assertEqual(output.get_data(as_text=True), exp)

  

          tests.create_projects(self.session)
@@ -1362,22 +1362,22 @@ 

          ]

          expected = [

              # 'pingou committed on test#9364354a4555ba17aa60f0dc844d70b74eb1aecd',

-             '<p>pingou committed on <a href="/test/c/9364354a4555ba17aa60f0dc844d70b74eb1aecd" '

+             '<div class="markdown"><p>pingou committed on <a href="/test/c/9364354a4555ba17aa60f0dc844d70b74eb1aecd" '

              'title="Commit 9364354a4555ba17aa60f0dc844d70b74eb1aecd"'

-             ">test#9364354a4555ba17aa60f0dc844d70b74eb1aecd</a></p>",

+             ">test#9364354a4555ba17aa60f0dc844d70b74eb1aecd</a></p></div>",

              # 'Cf commit 936435',

-             "<p>Cf commit 936435</p>",

+             '<div class="markdown"><p>Cf commit 936435</p></div>',

              # 'Cf commit 9364354',

              #'<p>Cf commit 9364354</p>',

-             '<p>Cf commit <a href="/test/c/9364354" '

-             'title="Commit 9364354">9364354</a></p>',

+             '<div class="markdown"><p>Cf commit <a href="/test/c/9364354" '

+             'title="Commit 9364354">9364354</a></p></div>',

              # 'Cf commit 9364354a',

-             '<p>Cf commit <a href="/test/c/9364354a" '

-             'title="Commit 9364354a">9364354</a></p>',

+             '<div class="markdown"><p>Cf commit <a href="/test/c/9364354a" '

+             'title="Commit 9364354a">9364354</a></p></div>',

              # 'Cf commit 9364354a4555ba17aa60f0dc844d70b74eb1aecd',

-             '<p>Cf commit <a href="/test/c/9364354a4555ba17aa60f0dc844d70b74eb1aecd" '

+             '<div class="markdown"><p>Cf commit <a href="/test/c/9364354a4555ba17aa60f0dc844d70b74eb1aecd" '

              'title="Commit 9364354a4555ba17aa60f0dc844d70b74eb1aecd"'

-             ">9364354</a></p>",

+             ">9364354</a></p></div>",

          ]

  

          with self.app.application.app_context():
@@ -1406,7 +1406,7 @@ 

          tests.create_projects(self.session)

          tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)

          text = "Cf commit 9364354a4555ba17aa60f0d"

-         exp = "<p>Cf commit 9364354a4555ba17aa60f0d</p>"

+         exp = '<div class="markdown"><p>Cf commit 9364354a4555ba17aa60f0d</p></div>'

  

          with self.app.application.app_context():

              data = {"content": text, "csrf_token": csrf_token}
@@ -1439,8 +1439,8 @@ 

  

          text = "Cf commit %s" % first_commit.oid.hex

          exp = (

-             '<p>Cf commit <a href="/test/c/{0}" title="Commit {0}">{1}'

-             "</a></p>".format(first_commit.oid.hex, first_commit.oid.hex[:7])

+             '<div class="markdown"><p>Cf commit <a href="/test/c/{0}" title="Commit {0}">{1}'

+             "</a></p></div>".format(first_commit.oid.hex, first_commit.oid.hex[:7])

          )

  

          with self.app.application.app_context():

@@ -2119,11 +2119,11 @@ 

              # FIXME: There is likely something going wrong in the html

              # below

              self.assertIn(

-                 '<span class="font-size-09 autogenerated-comment pl-4">'

+                 '<span class="font-size-09 autogenerated-comment pl-4"><div class="markdown">'

                  '<p><strong>Metadata Update from <a href="http://localhost.localdomain/user/pingou">'

                  '</a><a href="http://localhost.localdomain/user/pingou">@pingou</a></strong>:'

                  "<br>\n- Issue close_status updated to: Fixed<br>\n- Issue status updated to:"

-                 " Closed (was: Open)</p></span>\n",

+                 " Closed (was: Open)</p></div></span>\n",

                  output_text,

              )

  
@@ -4550,8 +4550,8 @@ 

          self.assertEqual(output.status_code, 200)

          self.assertIn(

              '<span class="comment_text comment_body">'

-             '<p>foo bar <a href="/ns/test3/issue/1" '

-             'title="[Open] test issue">#1</a> see?</p></span>',

+             '<div class="markdown"><p>foo bar <a href="/ns/test3/issue/1" '

+             'title="[Open] test issue">#1</a> see?</p></div></span>',

              output.get_data(as_text=True),

          )

  
@@ -4680,8 +4680,8 @@ 

          self.assertEqual(output.status_code, 200)

          self.assertIn(

              '<span class="comment_text comment_body">'

-             '<p>foo bar <a href="/fork/pingou/ns/test3/issue/1" '

-             'title="[Open] test issue">#1</a> see?</p></span>',

+             '<div class="markdown"><p>foo bar <a href="/fork/pingou/ns/test3/issue/1" '

+             'title="[Open] test issue">#1</a> see?</p></div></span>',

              output.get_data(as_text=True),

          )

  

file modified
+52 -52
@@ -4244,93 +4244,93 @@ 

          ]

          expected = [

              # 'foo bar test#1 see?',

-             '<p>foo bar <a href="http://localhost.localdomain/test/pull-request/1"'

-             ' title="[Open] test pull-request">test#1</a> see?</p>',

+             '<div class="markdown"><p>foo bar <a href="http://localhost.localdomain/test/pull-request/1"'

+             ' title="[Open] test pull-request">test#1</a> see?</p></div>',

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

-             "<p>foo bar pingou/test#2 I mean, really</p>",

+             '<div class="markdown"><p>foo bar pingou/test#2 I mean, really</p></div>',

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

-             '<p>foo bar <a href="http://localhost.localdomain/fork/'

+             '<div class="markdown"><p>foo bar <a href="http://localhost.localdomain/fork/'

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

-             "pingou/test#2</a> bouza!</p>",

+             "pingou/test#2</a> bouza!</p></div>",

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

-             '<p>foo bar <a href="http://localhost.localdomain/fork/'

+             '<div class="markdown"><p>foo bar <a href="http://localhost.localdomain/fork/'

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

-             "pingou/test#2</a> bouza!</p>",

+             "pingou/test#2</a> bouza!</p></div>",

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

-             '<p>foo bar <a href="http://localhost.localdomain/ns/test3/issue/4"'

-             ' title="[Open] test issue">ns/test3#4</a> bouza!</p>',

+             '<div class="markdown"><p>foo bar <a href="http://localhost.localdomain/ns/test3/issue/4"'

+             ' title="[Open] test issue">ns/test3#4</a> bouza!</p></div>',

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

-             "<p>foo bar user/ns/test#5 bouza!</p>",

+             '<div class="markdown"><p>foo bar user/ns/test#5 bouza!</p></div>',

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

-             '<p>foo bar <a href="http://localhost.localdomain/'

+             '<div class="markdown"><p>foo bar <a href="http://localhost.localdomain/'

              'fork/pingou/ns/test/issue/7" title="[Open] test issue #7">'

-             "pingou/ns/test#7</a> bouza!</p>",

+             "pingou/ns/test#7</a> bouza!</p></div>",

              # 'test#1 bazinga!',

-             '<p><a href="http://localhost.localdomain/test/pull-request/1" '

-             'title="[Open] test pull-request">test#1</a> bazinga!</p>',

+             '<div class="markdown"><p><a href="http://localhost.localdomain/test/pull-request/1" '

+             'title="[Open] test pull-request">test#1</a> bazinga!</p></div>',

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

-             '<p>pingou opened the PR <a href="http://localhost.localdomain/'

+             '<div class="markdown"><p>pingou opened the PR <a href="http://localhost.localdomain/'

              'fork/pingou/test/pull-request/2" '

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

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

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

-             '<p><a href="http://localhost.localdomain/fork/pingou/ns/test/issue/8" '

-             'title="Private issue">pingou/ns/test#8</a> is private</p>',

+             '<div class="markdown"><p><a href="http://localhost.localdomain/fork/pingou/ns/test/issue/8" '

+             'title="Private issue">pingou/ns/test#8</a> is private</p></div>',

              # 'implicit link to #1',

-             '<p>implicit link to <a href="http://localhost.localdomain/test/pull-request/1" title="[Open] test pull-request">#1</a></p>',

+             '<div class="markdown"><p>implicit link to <a href="http://localhost.localdomain/test/pull-request/1" title="[Open] test pull-request">#1</a></p></div>',

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

-             '<p>implicit link .<a href="http://localhost.localdomain/test/pull-request/1" title="[Open] test pull-request">#1</a>. with non-whitespace, non-word characters</p>',

+             '<div class="markdown"><p>implicit link .<a href="http://localhost.localdomain/test/pull-request/1" title="[Open] test pull-request">#1</a>. with non-whitespace, non-word characters</p></div>',

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

-             '<p><a href="http://localhost.localdomain/test/issue/2" title="[Open] test issue">#2</a> - implicit link at start of line</p>',

+             '<div class="markdown"><p><a href="http://localhost.localdomain/test/issue/2" title="[Open] test issue">#2</a> - implicit link at start of line</p></div>',

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

-             '<p><a href="http://localhost.localdomain/test/issue/2" title="[Open] test issue">#2</a>. implicit link at start of line with no whitespace after</p>',

+             '<div class="markdown"><p><a href="http://localhost.localdomain/test/issue/2" title="[Open] test issue">#2</a>. implicit link at start of line with no whitespace after</p></div>',

              # '#regular header',

-             "<h1>regular header</h1>",

+             '<div class="markdown"><h1>regular header</h1></div>',

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

-             "<h1>34 looks like an implicit link, but no issue 34</h1>",

+             '<div class="markdown"><h1>34 looks like an implicit link, but no issue 34</h1></div>',

              # 'pingou committed on test#9364354a4555ba17aa60f0dc844d70b74eb1aecd',

-             '<p>pingou committed on <a href="http://localhost.localdomain/'

+             '<div class="markdown"><p>pingou committed on <a href="http://localhost.localdomain/'

              'test/c/9364354a4555ba17aa60f0dc844d70b74eb1aecd" '

              'title="Commit 9364354a4555ba17aa60f0dc844d70b74eb1aecd"'

-             ">test#9364354a4555ba17aa60f0dc844d70b74eb1aecd</a></p>",

+             ">test#9364354a4555ba17aa60f0dc844d70b74eb1aecd</a></p></div>",

              # 'irc://pagure.io'

-             '<p><a href="irc://pagure.io">irc://pagure.io</a></p>',

+             '<div class="markdown"><p><a href="irc://pagure.io">irc://pagure.io</a></p></div>',

              # '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

              # '<p><a href="ircs://pagure.io">ircs://pagure.io</a></p>',

-             '<p><a href="ircs://pagure.io">ircs://pagure.io</a></p>'

+             '<div class="markdown"><p><a href="ircs://pagure.io">ircs://pagure.io</a></p></div>'

              if tuple(bleach_v) >= (1, 5, 0)

-             else "<p><a>ircs://pagure.io</a></p>",

+             else '<div class="markdown"><p><a>ircs://pagure.io</a></p></div>',

              # 'http://pagure.io'

-             '<p><a href="http://pagure.io">http://pagure.io</a></p>',

+             '<div class="markdown"><p><a href="http://pagure.io">http://pagure.io</a></p></div>',

              # 'https://pagure.io'

-             '<p><a href="https://pagure.io">https://pagure.io</a></p>',

+             '<div class="markdown"><p><a href="https://pagure.io">https://pagure.io</a></p></div>',

              # '<https://pagure.io/pagure>'

-             '<p><a href="https://pagure.io/pagure">https://pagure.io/pagure'

-             "</a></p>",

+             '<div class="markdown"><p><a href="https://pagure.io/pagure">https://pagure.io/pagure'

+             "</a></p></div>",

              # '~~foo~~'

-             "<p><del>foo</del></p>",

+             '<div class="markdown"><p><del>foo</del></p></div>',

              # '~~foo bar~~'

-             "<p><del>foo bar</del></p>",

+             '<div class="markdown"><p><del>foo bar</del></p></div>',

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

-             '<p><del><a href="https://bugzilla.redhat.com/1435310">'

-             "BZ#1435310</a></del></p>",

+             '<div class="markdown"><p><del><a href="https://bugzilla.redhat.com/1435310">'

+             "BZ#1435310</a></del></p></div>",

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

              # denial during F26AH boot 'error_name=org.freedesktop.systemd1

              # .NoSuchDynamicUser~~'

-             '<p><del><a href="https://bugzilla.redhat.com/1435310">'

+             '<div class="markdown"><p><del><a href="https://bugzilla.redhat.com/1435310">'

              "BZ#1435310</a> avc denial during F26AH boot 'error_name="

-             "org.freedesktop.systemd1.NoSuchDynamicUser'</del></p>",

+             "org.freedesktop.systemd1.NoSuchDynamicUser'</del></p></div>",

              # '``~~foo bar~~``'

-             "<p><code>~~foo bar~~</code></p>",

+             '<div class="markdown"><p><code>~~foo bar~~</code></p></div>',

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

-             "<p><del>foo bar</del> and <del>another </del></p>",

+             '<div class="markdown"><p><del>foo bar</del> and <del>another </del></p></div>',

              # 'lets mention @pingou',

-             '<p>lets mention <a href="http://localhost.localdomain/user/pingou">@pingou</a></p>',

+             '<div class="markdown"><p>lets mention <a href="http://localhost.localdomain/user/pingou">@pingou</a></p></div>',

              # '@pingou at start of line',

-             '<p><a href="http://localhost.localdomain/user/pingou">@pingou</a> at start of line</p>',

+             '<div class="markdown"><p><a href="http://localhost.localdomain/user/pingou">@pingou</a> at start of line</p></div>',

              # 'but not someone@pingou.com',

-             "<p>but not someone@pingou.com</p>",

+             '<div class="markdown"><p>but not someone@pingou.com</p></div>',

          ]

  

          if old_markdown:
@@ -4338,26 +4338,26 @@ 

                  # '[![Fedora_infinity_small.png]'

                  # '(/test/issue/raw/Fedora_infinity_small.png)]'

                  # '(/test/issue/raw/Fedora_infinity_small.png)',

-                 '<p><a href="/test/issue/raw/Fedora_infinity_small.png"><span>'

+                 '<div class="markdown"><p><a href="/test/issue/raw/Fedora_infinity_small.png"><span>'

                  '<img alt="Fedora_infinity_small.png" class="lazyload" '

                  'data-src="/test/issue/raw/Fedora_infinity_small.png" src="">'

                  "<noscript>"

                  '<img alt="Fedora_infinity_small.png" '

                  'src="/test/issue/raw/Fedora_infinity_small.png" />'

-                 "</noscript></span></a></p>"

+                 "</noscript></span></a></p></div>"

              )

          else:

              expected.append(

                  # '[![Fedora_infinity_small.png]'

                  # '(/test/issue/raw/Fedora_infinity_small.png)]'

                  # '(/test/issue/raw/Fedora_infinity_small.png)',

-                 '<p><a href="/test/issue/raw/Fedora_infinity_small.png"><span>'

+                 '<div class="markdown"><p><a href="/test/issue/raw/Fedora_infinity_small.png"><span>'

                  '<img alt="Fedora_infinity_small.png" class="lazyload" '

                  'data-src="/test/issue/raw/Fedora_infinity_small.png" src="">'

                  "<noscript>"

                  '<img alt="Fedora_infinity_small.png" '

                  'src="/test/issue/raw/Fedora_infinity_small.png">'

-                 "</noscript></span></a></p>"

+                 "</noscript></span></a></p></div>"

              )

  

          with self.app.application.app_context():
@@ -5139,7 +5139,7 @@ 

  foo bar

          """

  

-         expected = """<table>

+         expected = """<div class="markdown"><table>

  <thead>

  <tr>

  <th align="left">Left-aligned</th>
@@ -5160,7 +5160,7 @@ 

  </tr>

  </tbody>

  </table>

- <p>foo bar</p>"""

+ <p>foo bar</p></div>"""

  

          with self.app.application.app_context():

              html = pagure.lib.query.text2markdown(text)
@@ -5182,7 +5182,7 @@ 

  foo bar

          """

  

-         expected = """<table>

+         expected = """<div class="markdown"><table>

  <thead>

  <tr>

  <th align="left">Left-aligned</th>
@@ -5203,7 +5203,7 @@ 

  </tr>

  </tbody>

  </table>

- <p>foo bar</p>"""

+ <p>foo bar</p></div>"""

  

          with self.app.application.app_context():

              html = pagure.lib.query.text2markdown(text)

rebased onto 8902360

2 years ago

1 new commit added

  • Fix tests where markdown is involved
2 years ago

pretty please pagure-ci rebuild

2 years ago

This approach is probably altering too much outputs 😥

3 new commits added

  • Fix tests where markdown is involved
  • Add styling for markdown tables
  • pagure markdown extension: encapsulate our markdowns on a div tag
2 years ago

3 new commits added

  • Fix tests where markdown is involved
  • Add styling for markdown tables
  • pagure markdown extension: encapsulate our markdowns on a div tag
2 years ago

3 new commits added

  • Fix tests where markdown is involved
  • Add styling for markdown tables
  • pagure markdown extension: encapsulate our markdowns on a div tag
2 years ago

Pull-Request has been merged by pingou

2 years ago