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
|
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
|
||||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||||
|
|
||||||
|
.idea/*
|
||||||
|
|
||||||
# User-specific stuff:
|
# User-specific stuff:
|
||||||
.idea/workspace.xml
|
.idea/workspace.xml
|
||||||
.idea/tasks.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:
|
class MarkdownLinks:
|
||||||
known_shortcodes = ('wp')
|
known_shortcodes = ('wp')
|
||||||
pattern = re.compile('\[\[.+\]\]')
|
pattern = re.compile('\[\[(.*?)\]\]')
|
||||||
|
|
||||||
def convert(self, text):
|
def convert(self, text):
|
||||||
result = text
|
result = text
|
||||||
for link in MarkdownLinks.pattern.findall(text):
|
for regex_link in MarkdownLinks.pattern.findall(text):
|
||||||
|
origlink = "[[" + regex_link + "]]"
|
||||||
convertedlink = ""
|
convertedlink = ""
|
||||||
if "http" in text or "www" in text:
|
if "http" in regex_link or "www" in regex_link:
|
||||||
convertedlink = self.convert_as_external_link(text)
|
convertedlink = self.convert_as_external_link(origlink)
|
||||||
elif ">" in text:
|
elif ">" in regex_link:
|
||||||
convertedlink = self.convert_as_interwiki_link(text)
|
convertedlink = self.convert_as_interwiki_link(origlink)
|
||||||
else:
|
else:
|
||||||
convertedlink = self.convert_as_internal_link(text)
|
convertedlink = self.convert_as_internal_link(origlink)
|
||||||
result = result.replace(link, convertedlink)
|
result = result.replace(origlink, convertedlink)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def parseUrl(self, text):
|
def parseUrl(self, text):
|
||||||
|
|
|
@ -34,6 +34,12 @@ class TestMarkdownLinks(TestCase):
|
||||||
|
|
||||||
self.assertEqual(mdLink, self.converter.convert(dokuLink))
|
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):
|
def test_internal_links_with_some_text_in_line_converted_properly(self):
|
||||||
mdLink = """[text]({{< relref "bla" >}}) wow this looks cool"""
|
mdLink = """[text]({{< relref "bla" >}}) wow this looks cool"""
|
||||||
dokuLink = "[[bla|text]] wow this looks cool"
|
dokuLink = "[[bla|text]] wow this looks cool"
|
||||||
|
|
Loading…
Reference in New Issue