bugfixes after e2e testing
This commit is contained in:
parent
50fdb86c3e
commit
10250429ae
|
@ -0,0 +1 @@
|
||||||
|
<a href="https://www.goodreads.com/search?utf8=%E2%9C%93&query={{ index .Params 0 }}" target="_blank">{{ index .Params 0 }}</a>
|
|
@ -11,7 +11,8 @@ class MarkdownHeader():
|
||||||
'=====': 2,
|
'=====': 2,
|
||||||
'====': 3,
|
'====': 3,
|
||||||
'===': 4,
|
'===': 4,
|
||||||
'==': 5
|
'==': 5,
|
||||||
|
'=': 6
|
||||||
}
|
}
|
||||||
|
|
||||||
def convert(self, text):
|
def convert(self, text):
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import re
|
import re
|
||||||
from os import walk
|
from os import walk
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from src.markdown_converter import MarkdownConverter
|
from src.markdown_converter import MarkdownConverter
|
||||||
|
|
||||||
|
@ -16,7 +17,7 @@ class MarkdownLinks():
|
||||||
convertedlink = ""
|
convertedlink = ""
|
||||||
if "http" in origlink or "www" in origlink:
|
if "http" in origlink or "www" in origlink:
|
||||||
convertedlink = self.convert_as_external_link(origlink)
|
convertedlink = self.convert_as_external_link(origlink)
|
||||||
elif ">" in origlink:
|
elif ">" in origlink and not "<" in origlink:
|
||||||
convertedlink = self.convert_as_interwiki_link(origlink)
|
convertedlink = self.convert_as_interwiki_link(origlink)
|
||||||
else:
|
else:
|
||||||
convertedlink = self.convert_as_internal_link(origlink)
|
convertedlink = self.convert_as_internal_link(origlink)
|
||||||
|
@ -49,14 +50,17 @@ class MarkdownLinks():
|
||||||
return """[%s]({{< relref "%s" >}})""" % (title, url)
|
return """[%s]({{< relref "%s" >}})""" % (title, url)
|
||||||
|
|
||||||
def convert_as_external_link(self, text):
|
def convert_as_external_link(self, text):
|
||||||
url = self.parseUrl(text)
|
if '|' in text:
|
||||||
title = self.parseTitle(text)
|
url = self.parseUrl(text)
|
||||||
|
title = self.parseTitle(text)
|
||||||
return "[" + title + "](" + url + ")"
|
return "[" + title + "](" + url + ")"
|
||||||
|
url = text.replace('[', '').replace(']', '')
|
||||||
|
return "[" + url + "](" + url + ")"
|
||||||
|
|
||||||
def assert_interwiki_is_known(self, shortcode):
|
def assert_interwiki_is_known(self, shortcode):
|
||||||
shortcodes = []
|
shortcodes = []
|
||||||
for (dirpath, dirnames, filenames) in walk("../layouts/shortcodes"):
|
shortcodes_path = Path(__file__).parents[2].joinpath('layouts/shortcodes')
|
||||||
|
for (dirpath, dirnames, filenames) in walk(shortcodes_path):
|
||||||
shortcodes.extend(filenames)
|
shortcodes.extend(filenames)
|
||||||
break
|
break
|
||||||
if not shortcode in map(lambda x: x.replace(".html", ""), shortcodes):
|
if not shortcode in map(lambda x: x.replace(".html", ""), shortcodes):
|
||||||
|
|
|
@ -21,6 +21,12 @@ class TestMarkdownLinks(TestCase):
|
||||||
with self.assertRaises(ValueError):
|
with self.assertRaises(ValueError):
|
||||||
self.converter.convert("[[whaddapdawg>Wiki]]")
|
self.converter.convert("[[whaddapdawg>Wiki]]")
|
||||||
|
|
||||||
|
def test_known_interwiki_link_with_some_spaces(self):
|
||||||
|
mdLink = """{{< lib Purple Cow: Transform Your Business by Being Remarkable >}}"""
|
||||||
|
dokuLink = "[[lib>Purple Cow: Transform Your Business by Being Remarkable]]"
|
||||||
|
|
||||||
|
self.assertEqual(mdLink, self.converter.convert(dokuLink))
|
||||||
|
|
||||||
def test_known_interwiki_link_converts_successfully(self):
|
def test_known_interwiki_link_converts_successfully(self):
|
||||||
# see https://gohugo.io/extras/shortcodes/
|
# see https://gohugo.io/extras/shortcodes/
|
||||||
mdLink = """{{< wp Wiki >}}"""
|
mdLink = """{{< wp Wiki >}}"""
|
||||||
|
@ -46,12 +52,24 @@ class TestMarkdownLinks(TestCase):
|
||||||
|
|
||||||
self.assertEqual(mdLink, self.converter.convert(dokuLink))
|
self.assertEqual(mdLink, self.converter.convert(dokuLink))
|
||||||
|
|
||||||
|
def test_internal_link_with_image_tag(self):
|
||||||
|
dokuLink = "[[code|<img src='code.jpg'>]]"
|
||||||
|
mdLink = """[<img src='code.jpg'>]({{< relref "code" >}})"""
|
||||||
|
|
||||||
|
self.assertEqual(mdLink, self.converter.convert(dokuLink))
|
||||||
|
|
||||||
def test_internal_links_converted_properly(self):
|
def test_internal_links_converted_properly(self):
|
||||||
mdLink = """[text]({{< relref "bla" >}})"""
|
mdLink = """[text]({{< relref "bla" >}})"""
|
||||||
dokuLink = "[[bla|text]]"
|
dokuLink = "[[bla|text]]"
|
||||||
|
|
||||||
self.assertEqual(mdLink, self.converter.convert(dokuLink))
|
self.assertEqual(mdLink, self.converter.convert(dokuLink))
|
||||||
|
|
||||||
|
def test_external_link_without_title(self):
|
||||||
|
mdLink = "[https://www.google.com](https://www.google.com)"
|
||||||
|
dokuLink = "[[https://www.google.com]]"
|
||||||
|
|
||||||
|
self.assertEqual(mdLink, self.converter.convert(dokuLink))
|
||||||
|
|
||||||
def test_external_links_converted_properly(self):
|
def test_external_links_converted_properly(self):
|
||||||
mdLink = "[Wouter Groeneveld](https://github.com/wgroeneveld/)"
|
mdLink = "[Wouter Groeneveld](https://github.com/wgroeneveld/)"
|
||||||
dokuLink = "[[https://github.com/wgroeneveld/|Wouter Groeneveld]]"
|
dokuLink = "[[https://github.com/wgroeneveld/|Wouter Groeneveld]]"
|
||||||
|
|
Loading…
Reference in New Issue