From: Michael Tremer Date: Fri, 27 Oct 2017 11:15:21 +0000 (+0100) Subject: Improve paragraph splitting of Text module X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f78cbba4180876800e69c40bb7ef157ab9901f1e;p=pbs.git Improve paragraph splitting of Text module Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 6a77265a..086c58e4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/src/buildservice/sources.py b/src/buildservice/sources.py index 39ed7202..c466fdd0 100644 --- a/src/buildservice/sources.py +++ b/src/buildservice/sources.py @@ -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): diff --git a/src/templates/modules/commit-message.html b/src/templates/modules/commit-message.html index 0f1fa386..bd57e7df 100644 --- a/src/templates/modules/commit-message.html +++ b/src/templates/modules/commit-message.html @@ -1,5 +1,3 @@

{{ commit.subject }}

-{% 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 index 00000000..0d1dcb07 --- /dev/null +++ b/src/templates/modules/text.html @@ -0,0 +1,7 @@ +{% for paragraph in paragraphs %} +

+ {% apply linkify %} + {{ paragraph }} + {% end %} +

+{% end %} \ No newline at end of file diff --git a/src/web/ui_modules.py b/src/web/ui_modules.py index fe22f972..ee8e5c1a 100644 --- a/src/web/ui_modules.py +++ b/src/web/ui_modules.py @@ -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 = """%s""" - 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)