]> git.ipfire.org Git - pbs.git/commitdiff
Improve paragraph splitting of Text module
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Oct 2017 11:15:21 +0000 (12:15 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Oct 2017 11:15:21 +0000 (12:15 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/buildservice/sources.py
src/templates/modules/commit-message.html
src/templates/modules/text.html [new file with mode: 0644]
src/web/ui_modules.py

index 6a77265aec78b34ccd8b1cd04fd33f4796228122..086c58e4e8492b0772656a1d1fdbd1cd9aadc8f1 100644 (file)
@@ -281,6 +281,7 @@ dist_templates_modules_DATA = \
        src/templates/modules/repo-actions-table.html \
        src/templates/modules/repository-table.html \
        src/templates/modules/source-table.html \
+       src/templates/modules/text.html \
        src/templates/modules/updates-table.html \
        src/templates/modules/user-table.html \
        src/templates/modules/watchers-sidebar-table.html
index 39ed7202cc18d34ed2c4e58ef394a0a848ca6472..c466fdd0a3b72f4637361e376ad1915fc90c907d 100644 (file)
@@ -217,7 +217,27 @@ class Commit(base.DataObject):
                if all((l == "" for l in message)):
                        return
 
-               return "\n".join(message)
+               # We will now break the message into paragraphs
+               paragraphs = re.split("\n\n+", "\n".join(message))
+               print paragraphs
+
+               message = []
+               for paragraph in paragraphs:
+                       # Remove all line breaks that are not following a colon
+                       # and where the next line does not start with a star.
+                       paragraph = re.sub("(?<=\:)\n(?=[\*\s])", " ", paragraph)
+
+                       message.append(paragraph)
+
+               return "\n\n".join(message)
+
+       def split_paragraphs(self, s):
+               for group_seperator, line_iteration in itertools.groupby(s.splitlines(True), key=str.isspace):
+                       if group_seperator:
+                               continue
+
+                       paragraph = "".join(line_iteration)
+                       yield paragraph.replace("\n", " ")
 
        @property
        def message_full(self):
index 0f1fa386f0c0b9f6082decca6b86941162724c1e..bd57e7dfebaa96605cab4f016dcd68f97096a38b 100644 (file)
@@ -1,5 +1,3 @@
 <h4>{{ commit.subject }}</h4>
 
-{% apply linkify %}
-       {% module Text(commit.message) %}
-{% end %}
+{% module Text(commit.message) %}
\ No newline at end of file
diff --git a/src/templates/modules/text.html b/src/templates/modules/text.html
new file mode 100644 (file)
index 0000000..0d1dcb0
--- /dev/null
@@ -0,0 +1,7 @@
+{% for paragraph in paragraphs %}
+    <p>
+            {% apply linkify %}
+                {{ paragraph }}
+            {% end %}
+    </p>
+{% end %}
\ No newline at end of file
index fe22f97225467d393a9ca39cf09a7f68a64bbfb2..ee8e5c1abb8e06ff10973ca455a78bd9b7bd1543 100644 (file)
@@ -3,11 +3,9 @@
 from __future__ import division
 
 import datetime
-import itertools
 import math
 import pytz
 import re
-import string
 import tornado.web
 
 from .. import users
@@ -25,14 +23,6 @@ class TextModule(UIModule):
 
        LINK = """<a href="%s" target="_blank" rel="noopener">%s</a>"""
 
-       def split_paragraphs(self, s):
-               for group_seperator, line_iteration in itertools.groupby(s.splitlines(True), key=str.isspace):
-                       if group_seperator:
-                               continue
-
-                       paragraph = "".join(line_iteration)
-                       yield paragraph.replace("\n", " ")
-
        def render(self, text):
                # Handle empty messages
                if not text:
@@ -44,7 +34,7 @@ class TextModule(UIModule):
                # Search for CVE numbers and create hyperlinks.
                text = re.sub(self.CVE_PATTERN, self._cve_repl, text, re.I|re.U)
 
-               return text
+               return self.render_string("modules/text.html", paragraphs=text.split("\n\n"))
 
        def _bugzilla_repl(self, m):
                bug_id = m.group(1)