diff --git a/src/dokuwiki_to_hugo.py b/src/dokuwiki_to_hugo.py index 4b36598..c6ccd5a 100644 --- a/src/dokuwiki_to_hugo.py +++ b/src/dokuwiki_to_hugo.py @@ -8,7 +8,7 @@ from src.markdown_converter import MarkdownConverter class DokuWikiToHugo: root_dir = "" - def __init__(self, root = None): + def __init__(self, root=None): self.header_converter = HugoFileConfig() DokuWikiToHugo.root_dir = root pass @@ -19,9 +19,9 @@ class DokuWikiToHugo: shutil.rmtree('output') os.mkdir('output') - def doku_to_hugo(self, dir): + def doku_to_hugo(self, directory): self.create_output_dir() - for root, subFolders, files in os.walk(dir): + for root, subFolders, files in os.walk(directory): files = [f for f in files if not f[0] == '.'] for file in files: self.process_file(root, file) diff --git a/src/hugo_file_config.py b/src/hugo_file_config.py index f0db3de..35697e3 100644 --- a/src/hugo_file_config.py +++ b/src/hugo_file_config.py @@ -1,4 +1,5 @@ -import os.path, time +import os.path +import time class HugoFileConfig: @@ -23,4 +24,4 @@ tags = [ %s ] date = "%s" -+++""" % (title, ',\n'.join(map(lambda tag: ' "' + tag + '"', tags)), date) \ No newline at end of file ++++""" % (title, ',\n'.join(map(lambda tag: ' "' + tag + '"', tags)), date) diff --git a/src/main.py b/src/main.py index cff14ac..0c6c6ba 100644 --- a/src/main.py +++ b/src/main.py @@ -3,12 +3,14 @@ import argparse from src.dokuwiki_to_hugo import DokuWikiToHugo -def main(dir, root): - DokuWikiToHugo(root).doku_to_hugo(dir) +def main(directory, root): + DokuWikiToHugo(root).doku_to_hugo(directory) + if __name__ == "__main__": parser = argparse.ArgumentParser() - parser.add_argument("-d", "--dir", help="the directory of your DokuWiki pages collection", required = True) - parser.add_argument("-r", "--root", help="the root directory name in your hugo content where to link to", required = False) + parser.add_argument("-d", "--dir", help="the directory of your DokuWiki pages collection", required=True) + parser.add_argument("-r", "--root", help="the root directory name in your hugo content where to link to", + required=False) opts = parser.parse_args() main(opts.dir, opts.root) diff --git a/src/markdown/__init__.py b/src/markdown/__init__.py index e187b3d..ed70aa2 100644 --- a/src/markdown/__init__.py +++ b/src/markdown/__init__.py @@ -7,5 +7,5 @@ from os.path import dirname, basename, isfile import glob modules = glob.glob(dirname(__file__)+"/*.py") -__all__ = [ basename(f)[:-3] for f in modules if isfile(f) and not f.endswith('__init__.py')] -print('loaded markdown converters: ' + ', '.join(__all__)) \ No newline at end of file +__all__ = [basename(f)[:-3] for f in modules if isfile(f) and not f.endswith('__init__.py')] +print('loaded markdown converters: ' + ', '.join(__all__)) diff --git a/src/markdown/code.py b/src/markdown/code.py index 38bd66c..6e8a3c5 100644 --- a/src/markdown/code.py +++ b/src/markdown/code.py @@ -3,6 +3,18 @@ from re import compile from src.markdown_converter import MarkdownConverter + +# PEP8 fault, could be static or function instead of method (not in class context) +def strip_lang(language): + if language is '': + return language + + lang = language[1:len(language)] + if ' ' in lang: + lang = lang[0:lang.index(' ')] + return lang + + class BaseMarkdownCode(ABC): markdown = "```" @@ -10,28 +22,21 @@ class BaseMarkdownCode(ABC): self.tag = tag self.pattern = compile('(<' + tag + '(.*?)>)') - def strip_lang(self, language): - if(language is ''): - return language - - lang = language[1:len(language)] - if(' ' in lang): - lang = lang[0:lang.index(' ')] - return lang - def convert(self, text): result = text for match in self.pattern.findall(text): - language = self.strip_lang(match[1]) + language = strip_lang(match[1]) result = result.replace(match[0], BaseMarkdownCode.markdown + language) return result.replace('', BaseMarkdownCode.markdown) -@MarkdownConverter.Register + +@MarkdownConverter.register class MarkdownFile(BaseMarkdownCode): def __init__(self): super().__init__('file') -@MarkdownConverter.Register + +@MarkdownConverter.register class MarkdownCode(BaseMarkdownCode): def __init__(self): super().__init__('code') diff --git a/src/markdown/emoji.py b/src/markdown/emoji.py index 56b01fd..31dfd6f 100644 --- a/src/markdown/emoji.py +++ b/src/markdown/emoji.py @@ -1,8 +1,8 @@ from src.markdown_converter import MarkdownConverter -@MarkdownConverter.Register -class MarkdownEmoji(): +@MarkdownConverter.register +class MarkdownEmoji: # config as you like. http://www.webpagefx.com/tools/emoji-cheat-sheet/ config = { '8-)': 'sunglasses', @@ -29,4 +29,4 @@ class MarkdownEmoji(): result = text for key, value in MarkdownEmoji.config.items(): result = result.replace(key, ':' + value + ':') - return result \ No newline at end of file + return result diff --git a/src/markdown/headers.py b/src/markdown/headers.py index fadab3f..09679a2 100644 --- a/src/markdown/headers.py +++ b/src/markdown/headers.py @@ -2,8 +2,9 @@ from re import compile from src.markdown_converter import MarkdownConverter -@MarkdownConverter.Register -class MarkdownHeader(): + +@MarkdownConverter.register +class MarkdownHeader: pattern = compile('(=+)(.*?)(=+)') head = "=" config = { diff --git a/src/markdown/images.py b/src/markdown/images.py index 94b52c4..7454b90 100644 --- a/src/markdown/images.py +++ b/src/markdown/images.py @@ -1,7 +1,8 @@ from src.markdown_converter import MarkdownConverter from re import compile -@MarkdownConverter.Register + +@MarkdownConverter.register class MarkdownImages: pattern = compile('{{(\s?)(.*?)(\s?)}}') @@ -21,6 +22,7 @@ class MarkdownImages: style.append("height: " + height + "px;") else: style.append("width: " + dimensions + "px;") + def parse_position(): if len(left) > 0 and len(right) > 0: style.append("margin-left: auto; margin-right: auto;") @@ -42,4 +44,4 @@ class MarkdownImages: for match in MarkdownImages.pattern.findall(text): replaced = "" % (self.parse_style(match), self.parse_source(match[1])) result = result.replace('{{' + ''.join(match) + '}}', replaced) - return result \ No newline at end of file + return result diff --git a/src/markdown/links.py b/src/markdown/links.py index 59b4758..10ee1cd 100644 --- a/src/markdown/links.py +++ b/src/markdown/links.py @@ -6,13 +6,14 @@ from src.dokuwiki_to_hugo import DokuWikiToHugo from src.markdown_converter import MarkdownConverter -@MarkdownConverter.Register -class MarkdownLinks(): +@MarkdownConverter.register +class MarkdownLinks: # see http://pythex.org/ pattern = re.compile('(\[\[)(.*?)(\]\])') def convert(self, text): result = text + def starts_with_space(match): return match[1][0] is ' ' @@ -31,7 +32,7 @@ class MarkdownLinks(): result = result.replace(origlink, convertedlink) return result - def parseUrl(self, text): + def parse_url(self, text): return text[2:text.index('|')] def add_md_and_replace_home_with_index(self, src_url): @@ -39,20 +40,22 @@ class MarkdownLinks(): if "." not in url: url = url + ".md" return url.replace('home.md', '_index.md') - def parseInternalUrl(self, text): + + def parse_internal_url(self, text): url = text[2:len(text) - 2].replace(":", "/") return self.add_md_and_replace_home_with_index(url) - def parseInternalUrlWithoutTitle(self, text): - url = self.parseUrl(text).replace(":", "/") + + def parse_internal_url_without_title(self, text): + url = self.parse_url(text).replace(":", "/") return self.add_md_and_replace_home_with_index(url) - def parseTitle(self, text): + def parse_title(self, text): return text[text.index('|') + 1: text.index(']]')] def convert_as_interwiki_link(self, text): interwiki_shortcode = text[2:text.index('>')] self.assert_interwiki_is_known(interwiki_shortcode) - interwiki_urlpart = text[text.index('>') + 1 : len(text) - 2] + interwiki_urlpart = text[text.index('>') + 1: len(text) - 2] return """{{< %s "%s" >}}""" % (interwiki_shortcode, interwiki_urlpart) @@ -65,18 +68,18 @@ class MarkdownLinks(): url = "" title = "" if "|" not in text: - url = self.parseInternalUrl(text) - title = text[2:len(text)-2].replace(":", "/") + url = self.parse_internal_url(text) + title = text[2:len(text) - 2].replace(":", "/") else: - url = self.parseInternalUrlWithoutTitle(text) - title = self.parseTitle(text) + url = self.parse_internal_url_without_title(text) + title = self.parse_title(text) return """[%s]({{< relref "%s%s" >}})""" % (title, self.root_dir(url), url.replace(' ', '_')) def convert_as_external_link(self, text): if '|' in text: - url = self.parseUrl(text) - title = self.parseTitle(text) + url = self.parse_url(text) + title = self.parse_title(text) return "[" + title + "](" + url + ")" url = text.replace('[', '').replace(']', '') return "[" + url + "](" + url + ")" @@ -87,5 +90,5 @@ class MarkdownLinks(): for (dirpath, dirnames, filenames) in walk(shortcodes_path): shortcodes.extend(filenames) break - if not shortcode in map(lambda x: x.replace(".html", ""), shortcodes): - raise ValueError("Unknown Interwiki code " + shortcode + " - please add a shortcode in the layouts dir!") \ No newline at end of file + if not (shortcode in map(lambda x: x.replace(".html", ""), shortcodes)): + raise ValueError("Unknown Interwiki code " + shortcode + " - please add a shortcode in the layouts dir!") diff --git a/src/markdown/lists.py b/src/markdown/lists.py index 1d1ecd2..a4556e7 100644 --- a/src/markdown/lists.py +++ b/src/markdown/lists.py @@ -3,8 +3,8 @@ import re from src.markdown_converter import MarkdownConverter -@MarkdownConverter.Register -class MarkdownOrderedList(): +@MarkdownConverter.register +class MarkdownOrderedList: pattern = re.compile('(^(\s*)-\s)(.*)', re.MULTILINE) def convert(self, text): @@ -14,27 +14,32 @@ class MarkdownOrderedList(): result = text def deeper_depth(depth): - return list(filter(lambda x : x[0] > depth, last_used_linenrs)) + return list(filter(lambda x: x[0] > depth, last_used_linenrs)) + def drop_in_depth_detected(depth): return len(deeper_depth(depth)) > 0 + def remove_deeper_depths(depth): for itm in deeper_depth(depth): last_used_linenrs.remove(itm) + def last_used_by_depth(depth): return list(filter(lambda x: x[0] == depth, last_used_linenrs)) + def last_used_index(depth): return last_used_by_depth(depth)[0][2] - def last_used_linenr(depth): - result = last_used_by_depth(depth) - if len(result) == 0: - return 0 - return result[0][1] - def set_last_used_linenr(depth, linenr, index): - result = list(filter(lambda x: x[0] == depth, last_used_linenrs)) - if len(result) > 0: - last_used_linenrs.remove(result[0]) - last_used_linenrs.append((depth, linenr, index)) + def last_used_linenr(depth): + linenr_result = last_used_by_depth(depth) + if len(linenr_result) == 0: + return 0 + return linenr_result[0][1] + + def set_last_used_linenr(depth, linenr, the_index): + last_used_result = list(filter(lambda x: x[0] == depth, last_used_linenrs)) + if len(last_used_result) > 0: + last_used_linenrs.remove(last_used_result[0]) + last_used_linenrs.append((depth, linenr, the_index)) for match in MarkdownOrderedList.pattern.findall(text): current_line = (match[0] + match[2]).replace('\n', '') @@ -42,7 +47,7 @@ class MarkdownOrderedList(): current_linenr = lines.index(current_line) if last_used_linenr(current_depth) + 1 is current_linenr: - index = index + 1 + index += 1 elif drop_in_depth_detected(current_depth): index = last_used_index(current_depth) + 1 remove_deeper_depths(current_depth) @@ -52,4 +57,4 @@ class MarkdownOrderedList(): result = result.replace(current_line, match[1].replace('\n', '') + str(index) + '. ' + match[2]) - return result \ No newline at end of file + return result diff --git a/src/markdown/simplestyle.py b/src/markdown/simplestyle.py index 17215c6..5b58539 100644 --- a/src/markdown/simplestyle.py +++ b/src/markdown/simplestyle.py @@ -8,6 +8,7 @@ class NopStyle(ABC): def convert(self, text): return text + class SimpleReplacementStyle(ABC): def __init__(self, markdown_style, dokuwiki_style): self.markdown_style = markdown_style @@ -16,9 +17,9 @@ class SimpleReplacementStyle(ABC): def convert(self, text): return text.replace(self.dokuwiki_style, self.markdown_style) -class SimpleStyleBetweenTags(ABC): - def __init__(self, markdown_style, dokuwiki_style_begin, dokuwiki_style_end = None): +class SimpleStyleBetweenTags(ABC): + def __init__(self, markdown_style, dokuwiki_style_begin, dokuwiki_style_end=None): if dokuwiki_style_end is None: dokuwiki_style_end = dokuwiki_style_begin self.pattern = compile('(' + dokuwiki_style_begin + ')(.*?)(' + dokuwiki_style_end + ')') @@ -32,33 +33,39 @@ class SimpleStyleBetweenTags(ABC): result = result.replace(orig_header, new_header) return result -@MarkdownConverter.Register + +@MarkdownConverter.register class MarkdownLineBreak(SimpleReplacementStyle): def __init__(self): super().__init__('
', '\\') + # inline html is supported with Hugo, don't need the tags. -@MarkdownConverter.Register -class MarkdownInlineHtml(): +@MarkdownConverter.register +class MarkdownInlineHtml: def convert(self, text): return text.replace('', '').replace('', '') + # bold in Doku is bold in MD -@MarkdownConverter.Register +@MarkdownConverter.register class MarkdownBold(NopStyle): pass -@MarkdownConverter.Register + +@MarkdownConverter.register class MarkdownItalic(SimpleStyleBetweenTags): def __init__(self): super().__init__('*', '//') -@MarkdownConverter.Register + +@MarkdownConverter.register class MarkdownStrikeThrough(SimpleStyleBetweenTags): def __init__(self): super().__init__('~~', '', '') -@MarkdownConverter.Register + +@MarkdownConverter.register class MarkdownInlineCode(SimpleStyleBetweenTags): def __init__(self): - super().__init__('`', "''", "''") \ No newline at end of file + super().__init__('`', "''", "''") diff --git a/src/markdown/todo.py b/src/markdown/todo.py index e9ccdee..804a43a 100644 --- a/src/markdown/todo.py +++ b/src/markdown/todo.py @@ -1,8 +1,9 @@ from src.markdown_converter import MarkdownConverter from re import compile -@MarkdownConverter.Register -class MarkdownTodo(): + +@MarkdownConverter.register +class MarkdownTodo: pattern = compile('()(.*?)()') todo = '- [ ] ' done = '- [x] ' @@ -12,4 +13,4 @@ class MarkdownTodo(): for match in MarkdownTodo.pattern.findall(text): prefix = MarkdownTodo.todo if match[1] is '' else MarkdownTodo.done result = result.replace(match[0] + match[2] + match[3], prefix + match[2]) - return result \ No newline at end of file + return result diff --git a/src/markdown_converter.py b/src/markdown_converter.py index 7eae7dd..b37b1f8 100644 --- a/src/markdown_converter.py +++ b/src/markdown_converter.py @@ -1,10 +1,11 @@ from pathlib import Path + class MarkdownConverter: converters = [] @classmethod - def Register(cls, converter_class): + def register(cls, converter_class): cls.converters.append(converter_class()) return converter_class @@ -15,4 +16,4 @@ class MarkdownConverter: text = Path(self.file).read_text() for converter in MarkdownConverter.converters: text = converter.convert(text) - return text \ No newline at end of file + return text diff --git a/test/expected_markdown_output.txt b/test/expected_markdown_output.txt index d2dcb86..d1b3c4b 100644 --- a/test/expected_markdown_output.txt +++ b/test/expected_markdown_output.txt @@ -1,7 +1,7 @@ -# header 1 +# header 1 ##### header 5 -[hi]({{< relref "hello world" >}}) this is a test! +[hi]({{< relref "hello_world.md" >}}) this is a test! -{{< wp Dogs >}} are cool, look it up. [sublink]({{< relref "link/sub" >}}) example. +{{< wp "Dogs" >}} are cool, look it up. [sublink]({{< relref "link/sub.md" >}}) example. diff --git a/test/markdown/test_code.py b/test/markdown/test_code.py index f58a733..e1f58ff 100644 --- a/test/markdown/test_code.py +++ b/test/markdown/test_code.py @@ -2,8 +2,8 @@ from unittest import TestCase from src.markdown.code import MarkdownCode, MarkdownFile -class TestMarkdownCode(TestCase): +class TestMarkdownCode(TestCase): def setUp(self): self.code_converter = MarkdownCode() self.file_converter = MarkdownFile() @@ -90,4 +90,4 @@ class TestMarkdownCode(TestCase): blehbleh """ - self.assertEqual(expected, self.code_converter.convert(src)) \ No newline at end of file + self.assertEqual(expected, self.code_converter.convert(src)) diff --git a/test/markdown/test_images.py b/test/markdown/test_images.py index f700de4..ee53c50 100644 --- a/test/markdown/test_images.py +++ b/test/markdown/test_images.py @@ -2,6 +2,7 @@ from unittest import TestCase from src.markdown.images import MarkdownImages + class TestMarkdownImages(TestCase): def setUp(self): self.converter = MarkdownImages() diff --git a/test/markdown/test_links.py b/test/markdown/test_links.py index 5c514e4..c04f796 100644 --- a/test/markdown/test_links.py +++ b/test/markdown/test_links.py @@ -22,105 +22,105 @@ class TestMarkdownLinks(TestCase): self.assertEqual(no_real_doku_link, self.converter.convert(no_real_doku_link)) def test_internal_link_with_space_converted_to_underscore(self): - mdLink = """[magic properties]({{< relref "magic_properties.md" >}})""" - dokuLink = "[[magic properties]]" + md_link = """[magic properties]({{< relref "magic_properties.md" >}})""" + doku_link = "[[magic properties]]" - self.assertEqual(mdLink, self.converter.convert(dokuLink)) + self.assertEqual(md_link, self.converter.convert(doku_link)) def test_internal_link_to_home_converted_to_index(self): - mdLink = """[subpage/home]({{< relref "subpage/_index.md" >}})""" - dokuLink = "[[subpage/home]]" + md_link = """[subpage/home]({{< relref "subpage/_index.md" >}})""" + doku_link = "[[subpage/home]]" - self.assertEqual(mdLink, self.converter.convert(dokuLink)) + self.assertEqual(md_link, self.converter.convert(doku_link)) def test_internal_link_with_ref_to_root_not_prefixed_with_root_dir(self): DokuWikiToHugo.root_dir = "pages" - mdLink = """[Download SaveGame #one]({{< relref "/games/Wizardry8/Wizardry8_Saves01.rar" >}})""" - dokuLink = """[[/games/Wizardry8/Wizardry8_Saves01.rar|Download SaveGame #one]]""" + md_link = """[Download SaveGame #one]({{< relref "/games/Wizardry8/Wizardry8_Saves01.rar" >}})""" + doku_link = """[[/games/Wizardry8/Wizardry8_Saves01.rar|Download SaveGame #one]]""" - self.assertEqual(mdLink, self.converter.convert(dokuLink)) + self.assertEqual(md_link, self.converter.convert(doku_link)) def test_internal_link_prefixed_with_configured_root_dir_if_subdir(self): DokuWikiToHugo.root_dir = "pages" - mdLink = """[bla/blie]({{< relref "pages/bla/blie.md" >}})""" - dokuLink = "[[bla:blie]]" + md_link = """[bla/blie]({{< relref "pages/bla/blie.md" >}})""" + doku_link = "[[bla:blie]]" - self.assertEqual(mdLink, self.converter.convert(dokuLink)) + self.assertEqual(md_link, self.converter.convert(doku_link)) def test_internal_links_not_prefixed_with_configured_root_dir_if_currdir(self): DokuWikiToHugo.root_dir = "pages" - mdLink = """[bla]({{< relref "bla.md" >}})""" - dokuLink = "[[bla]]" + md_link = """[bla]({{< relref "bla.md" >}})""" + doku_link = "[[bla]]" - self.assertEqual(mdLink, self.converter.convert(dokuLink)) + self.assertEqual(md_link, self.converter.convert(doku_link)) def test_internal_links_without_text_converted_properly(self): - mdLink = """[bla]({{< relref "bla.md" >}})""" - dokuLink = "[[bla]]" + md_link = """[bla]({{< relref "bla.md" >}})""" + doku_link = "[[bla]]" - self.assertEqual(mdLink, self.converter.convert(dokuLink)) + self.assertEqual(md_link, self.converter.convert(doku_link)) def test_internal_links_with_sublink_converted_properly(self): - mdLink = """[text]({{< relref "bla/blie.md" >}})""" - dokuLink = "[[bla:blie|text]]" + md_link = """[text]({{< relref "bla/blie.md" >}})""" + doku_link = "[[bla:blie|text]]" - self.assertEqual(mdLink, self.converter.convert(dokuLink)) + self.assertEqual(md_link, self.converter.convert(doku_link)) def test_multiple_links_in_text_converted_properly(self): - mdLink = """[bla]({{< relref "bla.md" >}}) wow this looks cool and so does [this]({{< relref "this.md" >}}) and such""" - dokuLink = "[[bla]] wow this looks cool and so does [[this]] and such" + md_link = """[bla]({{< relref "bla.md" >}}) wow this looks cool and so does [this]({{< relref "this.md" >}}) and such""" + doku_link = "[[bla]] wow this looks cool and so does [[this]] and such" - self.assertEqual(mdLink, self.converter.convert(dokuLink)) + self.assertEqual(md_link, self.converter.convert(doku_link)) def test_internal_links_with_some_text_in_line_converted_properly(self): - mdLink = """[text]({{< relref "bla.md" >}}) wow this looks cool""" - dokuLink = "[[bla|text]] wow this looks cool" + md_link = """[text]({{< relref "bla.md" >}}) wow this looks cool""" + doku_link = "[[bla|text]] wow this looks cool" - self.assertEqual(mdLink, self.converter.convert(dokuLink)) + self.assertEqual(md_link, self.converter.convert(doku_link)) def test_internal_link_with_image_tag(self): - dokuLink = "[[code|]]" - mdLink = """[]({{< relref "code.md" >}})""" + doku_link = "[[code|]]" + md_link = """[]({{< relref "code.md" >}})""" - self.assertEqual(mdLink, self.converter.convert(dokuLink)) + self.assertEqual(md_link, self.converter.convert(doku_link)) def test_internal_links_with_extension_not_suffixed_with_md(self): - mdLink = """[text]({{< relref "bla.zip" >}})""" - dokuLink = "[[bla.zip|text]]" + md_link = """[text]({{< relref "bla.zip" >}})""" + doku_link = "[[bla.zip|text]]" - self.assertEqual(mdLink, self.converter.convert(dokuLink)) + self.assertEqual(md_link, self.converter.convert(doku_link)) def test_internal_links_converted_properly(self): - mdLink = """[text]({{< relref "bla.md" >}})""" - dokuLink = "[[bla|text]]" + md_link = """[text]({{< relref "bla.md" >}})""" + doku_link = "[[bla|text]]" - self.assertEqual(mdLink, self.converter.convert(dokuLink)) + self.assertEqual(md_link, self.converter.convert(doku_link)) def test_unknown_interwiki_link_throws_exception(self): 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]]" + md_link = """{{< lib "Purple Cow: Transform Your Business by Being Remarkable" >}}""" + doku_link = "[[lib>Purple Cow: Transform Your Business by Being Remarkable]]" - self.assertEqual(mdLink, self.converter.convert(dokuLink)) + self.assertEqual(md_link, self.converter.convert(doku_link)) def test_known_interwiki_link_converts_successfully(self): # see https://gohugo.io/extras/shortcodes/ - mdLink = """{{< wp "Wiki" >}}""" - dokuLink = "[[wp>Wiki]]" + md_link = """{{< wp "Wiki" >}}""" + doku_link = "[[wp>Wiki]]" - self.assertEqual(mdLink, self.converter.convert(dokuLink)) + self.assertEqual(md_link, self.converter.convert(doku_link)) def test_external_link_without_title(self): - mdLink = "[https://www.google.com](https://www.google.com)" - dokuLink = "[[https://www.google.com]]" + md_link = "[https://www.google.com](https://www.google.com)" + doku_link = "[[https://www.google.com]]" - self.assertEqual(mdLink, self.converter.convert(dokuLink)) + self.assertEqual(md_link, self.converter.convert(doku_link)) def test_external_links_converted_properly(self): - mdLink = "[Wouter Groeneveld](https://github.com/wgroeneveld/)" - dokuLink = "[[https://github.com/wgroeneveld/|Wouter Groeneveld]]" + md_link = "[Wouter Groeneveld](https://github.com/wgroeneveld/)" + doku_link = "[[https://github.com/wgroeneveld/|Wouter Groeneveld]]" - self.assertEqual(mdLink, self.converter.convert(dokuLink)) + self.assertEqual(md_link, self.converter.convert(doku_link)) diff --git a/test/markdown/test_lists.py b/test/markdown/test_lists.py index 1773353..ea03793 100644 --- a/test/markdown/test_lists.py +++ b/test/markdown/test_lists.py @@ -2,6 +2,7 @@ from unittest import TestCase from src.markdown.lists import MarkdownOrderedList + class TestMarkdownLists(TestCase): def setUp(self): self.converter = MarkdownOrderedList() @@ -43,7 +44,6 @@ five - six actual = self.converter.convert(src) self.assertEqual(expected, actual) - def test_ordered_lists_nested(self): src = ''' - Werkt zoals Rummikub: @@ -103,4 +103,4 @@ three three ''' - self.assertEqual(expected, self.converter.convert(src)) \ No newline at end of file + self.assertEqual(expected, self.converter.convert(src)) diff --git a/test/markdown/test_simplestyle.py b/test/markdown/test_simplestyle.py index da921e9..9bac624 100644 --- a/test/markdown/test_simplestyle.py +++ b/test/markdown/test_simplestyle.py @@ -5,7 +5,6 @@ from src.markdown.simplestyle import MarkdownBold, MarkdownItalic, MarkdownStrik class TestMarkdownSimpleStyles(TestCase): - def test_inline_html_simply_removes_tags(self): src = "sup" expected = "sup" @@ -41,4 +40,4 @@ class TestMarkdownSimpleStyles(TestCase): def test_some_bold_styles(self): src = '** this is bold** and so is **this**' - self.assertEqual(src, MarkdownBold().convert(src)) \ No newline at end of file + self.assertEqual(src, MarkdownBold().convert(src)) diff --git a/test/test_dokuwiki_to_hugo.py b/test/test_dokuwiki_to_hugo.py index e65cf1b..a911ee0 100644 --- a/test/test_dokuwiki_to_hugo.py +++ b/test/test_dokuwiki_to_hugo.py @@ -7,7 +7,6 @@ from src.dokuwiki_to_hugo import DokuWikiToHugo class TestDokuWikiToHugo(TestCase): - def tearDown(self): shutil.rmtree('output') @@ -21,5 +20,5 @@ class TestDokuWikiToHugo(TestCase): DokuWikiToHugo().doku_to_hugo('subdir') expected = Path("output/subdir/moar/dokuwiki_header_in_subdir.md").read_text() - self.assertIn('+++', expected) # header is there, check - self.assertIn('##### some header', expected) # some conversion done, check \ No newline at end of file + self.assertIn('+++', expected) # header is there, check + self.assertIn('##### some header', expected) # some conversion done, check diff --git a/test/test_hugo_file_config.py b/test/test_hugo_file_config.py index cd1c75e..1edd3c7 100644 --- a/test/test_hugo_file_config.py +++ b/test/test_hugo_file_config.py @@ -7,7 +7,6 @@ from src.hugo_file_config import HugoFileConfig class TestHugoFileConfig(TestCase): - def set_file_timestamp(self): date = datetime(2014, 10, 10, 12) u_time = mktime(date.timetuple()) @@ -44,4 +43,4 @@ date = "2014-10-10" +++""" actual_header = self.header.create('dokuwiki_header_example.txt') - self.assertEqual(expected_header, actual_header) \ No newline at end of file + self.assertEqual(expected_header, actual_header) diff --git a/test/test_markdown_converter.py b/test/test_markdown_converter.py index 067e3ce..a8f5bb0 100644 --- a/test/test_markdown_converter.py +++ b/test/test_markdown_converter.py @@ -4,8 +4,8 @@ from pathlib import Path from src.markdown_converter import MarkdownConverter -class TestMarkdownHeader(TestCase): +class TestMarkdownHeader(TestCase): def setUp(self): self.converter = MarkdownConverter("dokuwiki_example.txt") @@ -16,4 +16,3 @@ class TestMarkdownHeader(TestCase): print(actual) self.assertEqual(expected, actual, "Files not matching!") -