fix regex
This commit is contained in:
parent
9236cb0d7e
commit
3a7a38c215
|
@ -5,6 +5,8 @@
|
|||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
.idea/*
|
||||
|
||||
# User-specific stuff:
|
||||
.idea/workspace.xml
|
||||
.idea/tasks.xml
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
|
@ -4,19 +4,20 @@ import re
|
|||
|
||||
class MarkdownLinks:
|
||||
known_shortcodes = ('wp')
|
||||
pattern = re.compile('\[\[.+\]\]')
|
||||
pattern = re.compile('\[\[(.*?)\]\]')
|
||||
|
||||
def convert(self, text):
|
||||
result = text
|
||||
for link in MarkdownLinks.pattern.findall(text):
|
||||
for regex_link in MarkdownLinks.pattern.findall(text):
|
||||
origlink = "[[" + regex_link + "]]"
|
||||
convertedlink = ""
|
||||
if "http" in text or "www" in text:
|
||||
convertedlink = self.convert_as_external_link(text)
|
||||
elif ">" in text:
|
||||
convertedlink = self.convert_as_interwiki_link(text)
|
||||
if "http" in regex_link or "www" in regex_link:
|
||||
convertedlink = self.convert_as_external_link(origlink)
|
||||
elif ">" in regex_link:
|
||||
convertedlink = self.convert_as_interwiki_link(origlink)
|
||||
else:
|
||||
convertedlink = self.convert_as_internal_link(text)
|
||||
result = result.replace(link, convertedlink)
|
||||
convertedlink = self.convert_as_internal_link(origlink)
|
||||
result = result.replace(origlink, convertedlink)
|
||||
return result
|
||||
|
||||
def parseUrl(self, text):
|
||||
|
|
|
@ -34,6 +34,12 @@ class TestMarkdownLinks(TestCase):
|
|||
|
||||
self.assertEqual(mdLink, self.converter.convert(dokuLink))
|
||||
|
||||
def test_multiple_links_in_text_converted_properly(self):
|
||||
mdLink = """{{< relref "bla" >}} wow this looks cool and so does {{< relref "this" >}} and such"""
|
||||
dokuLink = "[[bla]] wow this looks cool and so does [[this]] and such"
|
||||
|
||||
self.assertEqual(mdLink, self.converter.convert(dokuLink))
|
||||
|
||||
def test_internal_links_with_some_text_in_line_converted_properly(self):
|
||||
mdLink = """[text]({{< relref "bla" >}}) wow this looks cool"""
|
||||
dokuLink = "[[bla|text]] wow this looks cool"
|
||||
|
|
Loading…
Reference in New Issue