summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--projects/project.schema.yaml2
-rwxr-xr-xscripts/html_task.py63
2 files changed, 46 insertions, 19 deletions
diff --git a/projects/project.schema.yaml b/projects/project.schema.yaml
index c9e096c..7b1f23a 100644
--- a/projects/project.schema.yaml
+++ b/projects/project.schema.yaml
@@ -103,4 +103,4 @@ mapping:
comments:
sequence:
- - type: str
+ - type: any
diff --git a/scripts/html_task.py b/scripts/html_task.py
index 1e6c175..e47bb99 100755
--- a/scripts/html_task.py
+++ b/scripts/html_task.py
@@ -19,9 +19,22 @@ from html_base import html
#====================================
class periject_html(html_base.myhtml):
+ re_http_url = re.compile(r'(https?://[\w/:%#\$&\?\(\)~\.=\+\-]+)')
+ re_blank_line = re.compile(r'\n\n+')
+
def __init__(self):
super().__init__()
+ def _link(self, text):
+ match = periject_html.re_http_url.search(text)
+ if not match:
+ return text
+
+ a = html("a", {"href": match.group(), "target": "_blank"})
+ return match.string[:match.start()] + \
+ a.text(match.group()) + \
+ match.string[match.end():]
+
#--------------------
# task_commit_bsp
#--------------------
@@ -148,28 +161,42 @@ class periject_html(html_base.myhtml):
self.task_commit_upstream(v)
#--------------------
- # task_comment
+ # _task_comments
+ #--------------------
+ def _task_comments(self, v):
+
+ if isinstance(v, list):
+ with html("ul"):
+ for comment in v:
+ with html("li"):
+ self._task_comments(comment)
+
+ elif isinstance(v, dict):
+ for key, value in v.items():
+ html("p").print(self._link(key))
+ with html("p"):
+ self._task_comments(value)
+
+ elif isinstance(v, str):
+ comment = self._link(v)
+
+ comment = periject_html.re_blank_line.split(comment)
+ for para in comment:
+ html("p").print(para)
+
+ else:
+ print(v)
+ raise TypeError(f"Incorrect type for comments ({type(v)})")
+
+ #--------------------
+ # task_comments
#--------------------
- def task_comment(self, v):
+ def task_comments(self, v):
comments = v.get_data("comments")
if (not comments):
return
- with html("ul"):
- for comment in comments:
- str = re.search(r'(https?://[\w/:%#\$&\?\(\)~\.=\+\-]+)', comment)
- if (str):
- a = html("a", {"href":str.group(),
- "target":"_blank"})
- comment = str.string[:str.start()] + a.text(str.group()) + str.string[str.end():]
-
- comment = re.split(r'\n\n+', comment)
- if len(comment) > 1:
- with html("li"):
- for para in comment:
- html("p").print(para)
- else:
- html("li").print(comment[0])
+ self._task_comments(comments)
#--------------------
# print
@@ -188,7 +215,7 @@ class periject_html(html_base.myhtml):
html("h2").print(v.get_data("title"))
self.task_head(v)
self.task_commit(v)
- self.task_comment(v)
+ self.task_comments(v)
#====================================
#