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
This commit is contained in:
Markus Zoeller 2015-05-07 15:16:32 +02:00
parent e8707aa3b5
commit dcc2cc40a6
1 changed files with 28 additions and 1 deletions

View File

@ -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)