diff --git a/test/test_wiki_trac_rst_convert.py b/test/test_wiki_trac_rst_convert.py
index b3a09b1..a4dd95b 100644
--- a/test/test_wiki_trac_rst_convert.py
+++ b/test/test_wiki_trac_rst_convert.py
@@ -3,7 +3,7 @@
from wiki_trac_rst_convert import convert_content
-class TracRstToVanillaRst(unittest.TestCase):
+class TracToVanillaRst(unittest.TestCase):
"""
Test conversion of content from Trac-flavored reStructuredText to
vanilla reStructuredText, that is supported by GitHub
@@ -100,6 +100,31 @@ def test_several_trac_wiki_rst_links_with_content(self):
' List of free software used by Chevah Project.'
)
+ def test_tracwiki_general_link(self):
+ """
+ Process general links from TracWiki format to GitHub-compatible
+ RST links
+ """
+ self.assertConvertedContent(
+ '`Buildbot `__\n',
+ '[https://chevah.com/buildbot/ Buildbot]'
+ )
+
+ def test_tracwiki_wiki_link(self):
+ """
+ Process wiki links from TracWiki format to GitHub-compatible
+ RST simple links
+ """
+ self.assertConvertedContent(
+ '`Project management and administration `__\n'
+ '`Administrative `__ - Project management [and administration]\n'
+ '`Administrative/AllHandMeeting/Past `__',
+
+ '[wiki:Administrative Project management and administration]\n'
+ '[wiki:Administrative Administrative] - Project management [and administration]\n'
+ '[wiki:"Administrative/AllHandMeeting/Past"]'
+ )
+
if __name__ == '__main__':
unittest.main()
diff --git a/wiki_trac_rst_convert.py b/wiki_trac_rst_convert.py
index da95167..e5a17cd 100644
--- a/wiki_trac_rst_convert.py
+++ b/wiki_trac_rst_convert.py
@@ -45,6 +45,7 @@ def convert_content(text: str):
text = text.replace(seq, '')
text = text.strip() + '\n'
text = _trac_rst_wiki_to_github_links(text)
+ text = _tracwiki_to_github_links(text)
return text
@@ -73,6 +74,28 @@ def _trac_rst_wiki_to_github_links(text: str):
return text
+def _tracwiki_to_github_links(text: str):
+ """
+ Takes TracWiki content and converts the links and link text in it
+ to inline GitHub links.
+ """
+
+ url = '[a-z]+://[^ ]+'
+ link_text = '[^]]+'
+ link_re = re.compile(f'\[({url}) ({link_text})]')
+
+ matches = re.findall(link_re, text)
+ for url, link_text in matches:
+ text = re.sub(
+ link_re,
+ rf'`{link_text} <{url}>`__',
+ text,
+ 1
+ )
+
+ return text
+
+
def _wiki_url(title):
"""
GitHub Wiki collapses directory structure.