From ceff746690571092169729d62a3225b9a1a69f8d Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Wed, 17 Mar 2021 20:39:14 +0200 Subject: scripts: Extend support for formatting comments Now that comments can span multiple lines, add support for nested lists. The yaml syntax is comments: - The BSP commit bundles 5 different changes: - Disable SN65DSI86 GPIOs - Disable scrambling (for V3U Falcon) - Hot plug detectiong polling - EDID retrieval - 4k support for Display Port v1.2 which gets translated to The YAML schema is relaxed accordingly to support sequences of anything in comments. Note the need for ':' at the end of the first line in the list. Without that, the full comment will be treated as a single block of text by the yaml parser, and the HTML generation script will render it as a single paragraph without line breaks. This could be addressed, but if we keep going further in that during, maybe a full markdown parser and generator should be integrated instead. Signed-off-by: Laurent Pinchart Acked-by: Wolfram Sang --- scripts/html_task.py | 63 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 18 deletions(-) (limited to 'scripts/html_task.py') 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) #==================================== # -- cgit v1.2.3