Skip to content

Commit 6560948

Browse files
authored
Merge pull request #7 from humitos/rst-messages
Parse messages with reStructuredText
2 parents f42a01a + 9feec49 commit 6560948

1 file changed

Lines changed: 6 additions & 13 deletions

File tree

versionwarning/banner.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3-
from docutils import nodes
3+
from docutils import nodes, core
44
from munch import Munch
55
import os
66

@@ -53,19 +53,12 @@ def _create_banner_node(self, message, newest_version, admonition_type='warning'
5353
self.ADMONITION_TYPES.get(self._default_admonition_type),
5454
)
5555

56-
paragraph = nodes.paragraph()
5756
if self._message_placeholder in message:
58-
first_msg_part, second_msg_part = message.split(self._message_placeholder)
59-
reference = nodes.reference(
60-
newest_version.slug,
61-
newest_version.slug,
62-
refuri=newest_version.url,
63-
)
64-
paragraph.append(nodes.Text(first_msg_part))
65-
paragraph.append(reference)
66-
paragraph.append(nodes.Text(second_msg_part))
67-
else:
68-
paragraph.append(nodes.Text(message))
57+
message = message.replace(self._message_placeholder, '`{text} <url>`_'.format(
58+
text=newest_version.slug,
59+
url=newest_version.url,
60+
))
61+
paragraph = core.publish_doctree(message)[0]
6962

7063
banner_node = node_class(ids=[self._banner_id_div])
7164
banner_node.append(paragraph)

0 commit comments

Comments
 (0)