From dcc2cc40a68f7ff43516cb6db797027e16d523cd Mon Sep 17 00:00:00 2001 From: Markus Zoeller Date: Thu, 7 May 2015 15:16:32 +0200 Subject: [PATCH] Hypervisor Support Matrix renders links in notes The sphinx-extension which renders the support_matrix.ini file into HTML did not recognize URLs in the notes which have to be written as an HTML anchor element. This commit changes that. The links are clickable now. Closes-Bug: 1451468 Change-Id: Ia05610afb32c7a86536b7f462d3cfc44f9a2ca7d --- doc/ext/support_matrix.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/doc/ext/support_matrix.py b/doc/ext/support_matrix.py index 6e423fdc02..19f487784b 100644 --- a/doc/ext/support_matrix.py +++ b/doc/ext/support_matrix.py @@ -412,12 +412,39 @@ class SupportMatrixDirective(rst.Directive): ids=[id]), ] if impl.notes is not None: - subitem.append(nodes.paragraph(text=impl.notes)) + subitem.append(self._create_notes_paragraph(impl.notes)) impls.append(subitem) item.append(impls) details.append(item) + def _create_notes_paragraph(self, notes): + """ Constructs a paragraph which represents the implementation notes + + The paragraph consists of text and clickable URL nodes if links were + given in the notes. + """ + para = nodes.paragraph() + # links could start with http:// or https:// + link_idxs = [m.start() for m in re.finditer('https?://', notes)] + start_idx = 0 + for link_idx in link_idxs: + # assume the notes start with text (could be empty) + para.append(nodes.inline(text=notes[start_idx:link_idx])) + # create a URL node until the next text or the end of the notes + link_end_idx = notes.find(" ", link_idx) + if link_end_idx == -1: + # In case the notes end with a link without a blank + link_end_idx = len(notes) + uri = notes[link_idx:link_end_idx + 1] + para.append(nodes.reference("", uri, refuri=uri)) + start_idx = link_end_idx + 1 + + # get all text after the last link (could be empty) or all of the + # text if no link was given + para.append(nodes.inline(text=notes[start_idx:])) + return para + def setup(app): app.add_directive('support_matrix', SupportMatrixDirective)