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,
|
||||
'====': 3,
|
||||
'===': 4,
|
||||
'==': 5
|
||||
'==': 5,
|
||||
'=': 6
|
||||
}
|
||||
|
||||
def convert(self, text):
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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|<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):
|
||||
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]]"
|
||||
|
|
Loading…
Reference in New Issue