diff --git a/layouts/shortcodes/lib.html b/layouts/shortcodes/lib.html new file mode 100644 index 0000000..31bfcae --- /dev/null +++ b/layouts/shortcodes/lib.html @@ -0,0 +1 @@ +{{ index .Params 0 }} diff --git a/src/markdown/headers.py b/src/markdown/headers.py index 2aeed14..029d64f 100644 --- a/src/markdown/headers.py +++ b/src/markdown/headers.py @@ -11,7 +11,8 @@ class MarkdownHeader(): '=====': 2, '====': 3, '===': 4, - '==': 5 + '==': 5, + '=': 6 } def convert(self, text): diff --git a/src/markdown/links.py b/src/markdown/links.py index 2310950..0c5493e 100644 --- a/src/markdown/links.py +++ b/src/markdown/links.py @@ -1,5 +1,6 @@ import re from os import walk +from pathlib import Path from src.markdown_converter import MarkdownConverter @@ -16,7 +17,7 @@ class MarkdownLinks(): convertedlink = "" if "http" in origlink or "www" in 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) else: convertedlink = self.convert_as_internal_link(origlink) @@ -49,14 +50,17 @@ class MarkdownLinks(): return """[%s]({{< relref "%s" >}})""" % (title, url) def convert_as_external_link(self, text): - url = self.parseUrl(text) - title = self.parseTitle(text) - - return "[" + title + "](" + url + ")" + if '|' in text: + url = self.parseUrl(text) + title = self.parseTitle(text) + return "[" + title + "](" + url + ")" + url = text.replace('[', '').replace(']', '') + return "[" + url + "](" + url + ")" def assert_interwiki_is_known(self, shortcode): 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) break if not shortcode in map(lambda x: x.replace(".html", ""), shortcodes): diff --git a/test/markdown/test_links.py b/test/markdown/test_links.py index 0e1c03d..3e6aee8 100644 --- a/test/markdown/test_links.py +++ b/test/markdown/test_links.py @@ -21,6 +21,12 @@ class TestMarkdownLinks(TestCase): with self.assertRaises(ValueError): 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): # see https://gohugo.io/extras/shortcodes/ mdLink = """{{< wp Wiki >}}""" @@ -46,12 +52,24 @@ class TestMarkdownLinks(TestCase): self.assertEqual(mdLink, self.converter.convert(dokuLink)) + def test_internal_link_with_image_tag(self): + dokuLink = "[[code|]]" + mdLink = """[]({{< relref "code" >}})""" + + self.assertEqual(mdLink, self.converter.convert(dokuLink)) + def test_internal_links_converted_properly(self): mdLink = """[text]({{< relref "bla" >}})""" dokuLink = "[[bla|text]]" 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): mdLink = "[Wouter Groeneveld](https://github.com/wgroeneveld/)" dokuLink = "[[https://github.com/wgroeneveld/|Wouter Groeneveld]]"