PEP-8 convention check in PyCharm
This commit is contained in:
parent
fe0bcbf330
commit
9e8fa5b9aa
|
@ -8,7 +8,7 @@ from src.markdown_converter import MarkdownConverter
|
||||||
class DokuWikiToHugo:
|
class DokuWikiToHugo:
|
||||||
root_dir = ""
|
root_dir = ""
|
||||||
|
|
||||||
def __init__(self, root = None):
|
def __init__(self, root=None):
|
||||||
self.header_converter = HugoFileConfig()
|
self.header_converter = HugoFileConfig()
|
||||||
DokuWikiToHugo.root_dir = root
|
DokuWikiToHugo.root_dir = root
|
||||||
pass
|
pass
|
||||||
|
@ -19,9 +19,9 @@ class DokuWikiToHugo:
|
||||||
shutil.rmtree('output')
|
shutil.rmtree('output')
|
||||||
os.mkdir('output')
|
os.mkdir('output')
|
||||||
|
|
||||||
def doku_to_hugo(self, dir):
|
def doku_to_hugo(self, directory):
|
||||||
self.create_output_dir()
|
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] == '.']
|
files = [f for f in files if not f[0] == '.']
|
||||||
for file in files:
|
for file in files:
|
||||||
self.process_file(root, file)
|
self.process_file(root, file)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import os.path, time
|
import os.path
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
class HugoFileConfig:
|
class HugoFileConfig:
|
||||||
|
|
10
src/main.py
10
src/main.py
|
@ -3,12 +3,14 @@ import argparse
|
||||||
from src.dokuwiki_to_hugo import DokuWikiToHugo
|
from src.dokuwiki_to_hugo import DokuWikiToHugo
|
||||||
|
|
||||||
|
|
||||||
def main(dir, root):
|
def main(directory, root):
|
||||||
DokuWikiToHugo(root).doku_to_hugo(dir)
|
DokuWikiToHugo(root).doku_to_hugo(directory)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("-d", "--dir", help="the directory of your DokuWiki pages collection", required = True)
|
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("-r", "--root", help="the root directory name in your hugo content where to link to",
|
||||||
|
required=False)
|
||||||
opts = parser.parse_args()
|
opts = parser.parse_args()
|
||||||
main(opts.dir, opts.root)
|
main(opts.dir, opts.root)
|
||||||
|
|
|
@ -7,5 +7,5 @@ from os.path import dirname, basename, isfile
|
||||||
import glob
|
import glob
|
||||||
|
|
||||||
modules = glob.glob(dirname(__file__)+"/*.py")
|
modules = glob.glob(dirname(__file__)+"/*.py")
|
||||||
__all__ = [ basename(f)[:-3] for f in modules if isfile(f) and not f.endswith('__init__.py')]
|
__all__ = [basename(f)[:-3] for f in modules if isfile(f) and not f.endswith('__init__.py')]
|
||||||
print('loaded markdown converters: ' + ', '.join(__all__))
|
print('loaded markdown converters: ' + ', '.join(__all__))
|
|
@ -3,6 +3,18 @@ from re import compile
|
||||||
|
|
||||||
from src.markdown_converter import MarkdownConverter
|
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):
|
class BaseMarkdownCode(ABC):
|
||||||
markdown = "```"
|
markdown = "```"
|
||||||
|
|
||||||
|
@ -10,28 +22,21 @@ class BaseMarkdownCode(ABC):
|
||||||
self.tag = tag
|
self.tag = tag
|
||||||
self.pattern = compile('(<' + 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):
|
def convert(self, text):
|
||||||
result = text
|
result = text
|
||||||
for match in self.pattern.findall(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)
|
result = result.replace(match[0], BaseMarkdownCode.markdown + language)
|
||||||
return result.replace('</' + self.tag + '>', BaseMarkdownCode.markdown)
|
return result.replace('</' + self.tag + '>', BaseMarkdownCode.markdown)
|
||||||
|
|
||||||
@MarkdownConverter.Register
|
|
||||||
|
@MarkdownConverter.register
|
||||||
class MarkdownFile(BaseMarkdownCode):
|
class MarkdownFile(BaseMarkdownCode):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__('file')
|
super().__init__('file')
|
||||||
|
|
||||||
@MarkdownConverter.Register
|
|
||||||
|
@MarkdownConverter.register
|
||||||
class MarkdownCode(BaseMarkdownCode):
|
class MarkdownCode(BaseMarkdownCode):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__('code')
|
super().__init__('code')
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
from src.markdown_converter import MarkdownConverter
|
from src.markdown_converter import MarkdownConverter
|
||||||
|
|
||||||
|
|
||||||
@MarkdownConverter.Register
|
@MarkdownConverter.register
|
||||||
class MarkdownEmoji():
|
class MarkdownEmoji:
|
||||||
# config as you like. http://www.webpagefx.com/tools/emoji-cheat-sheet/
|
# config as you like. http://www.webpagefx.com/tools/emoji-cheat-sheet/
|
||||||
config = {
|
config = {
|
||||||
'8-)': 'sunglasses',
|
'8-)': 'sunglasses',
|
||||||
|
|
|
@ -2,8 +2,9 @@ from re import compile
|
||||||
|
|
||||||
from src.markdown_converter import MarkdownConverter
|
from src.markdown_converter import MarkdownConverter
|
||||||
|
|
||||||
@MarkdownConverter.Register
|
|
||||||
class MarkdownHeader():
|
@MarkdownConverter.register
|
||||||
|
class MarkdownHeader:
|
||||||
pattern = compile('(=+)(.*?)(=+)')
|
pattern = compile('(=+)(.*?)(=+)')
|
||||||
head = "="
|
head = "="
|
||||||
config = {
|
config = {
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
from src.markdown_converter import MarkdownConverter
|
from src.markdown_converter import MarkdownConverter
|
||||||
from re import compile
|
from re import compile
|
||||||
|
|
||||||
@MarkdownConverter.Register
|
|
||||||
|
@MarkdownConverter.register
|
||||||
class MarkdownImages:
|
class MarkdownImages:
|
||||||
pattern = compile('{{(\s?)(.*?)(\s?)}}')
|
pattern = compile('{{(\s?)(.*?)(\s?)}}')
|
||||||
|
|
||||||
|
@ -21,6 +22,7 @@ class MarkdownImages:
|
||||||
style.append("height: " + height + "px;")
|
style.append("height: " + height + "px;")
|
||||||
else:
|
else:
|
||||||
style.append("width: " + dimensions + "px;")
|
style.append("width: " + dimensions + "px;")
|
||||||
|
|
||||||
def parse_position():
|
def parse_position():
|
||||||
if len(left) > 0 and len(right) > 0:
|
if len(left) > 0 and len(right) > 0:
|
||||||
style.append("margin-left: auto; margin-right: auto;")
|
style.append("margin-left: auto; margin-right: auto;")
|
||||||
|
|
|
@ -6,13 +6,14 @@ from src.dokuwiki_to_hugo import DokuWikiToHugo
|
||||||
from src.markdown_converter import MarkdownConverter
|
from src.markdown_converter import MarkdownConverter
|
||||||
|
|
||||||
|
|
||||||
@MarkdownConverter.Register
|
@MarkdownConverter.register
|
||||||
class MarkdownLinks():
|
class MarkdownLinks:
|
||||||
# see http://pythex.org/
|
# see http://pythex.org/
|
||||||
pattern = re.compile('(\[\[)(.*?)(\]\])')
|
pattern = re.compile('(\[\[)(.*?)(\]\])')
|
||||||
|
|
||||||
def convert(self, text):
|
def convert(self, text):
|
||||||
result = text
|
result = text
|
||||||
|
|
||||||
def starts_with_space(match):
|
def starts_with_space(match):
|
||||||
return match[1][0] is ' '
|
return match[1][0] is ' '
|
||||||
|
|
||||||
|
@ -31,7 +32,7 @@ class MarkdownLinks():
|
||||||
result = result.replace(origlink, convertedlink)
|
result = result.replace(origlink, convertedlink)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def parseUrl(self, text):
|
def parse_url(self, text):
|
||||||
return text[2:text.index('|')]
|
return text[2:text.index('|')]
|
||||||
|
|
||||||
def add_md_and_replace_home_with_index(self, src_url):
|
def add_md_and_replace_home_with_index(self, src_url):
|
||||||
|
@ -39,20 +40,22 @@ class MarkdownLinks():
|
||||||
if "." not in url:
|
if "." not in url:
|
||||||
url = url + ".md"
|
url = url + ".md"
|
||||||
return url.replace('home.md', '_index.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(":", "/")
|
url = text[2:len(text) - 2].replace(":", "/")
|
||||||
return self.add_md_and_replace_home_with_index(url)
|
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)
|
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(']]')]
|
return text[text.index('|') + 1: text.index(']]')]
|
||||||
|
|
||||||
def convert_as_interwiki_link(self, text):
|
def convert_as_interwiki_link(self, text):
|
||||||
interwiki_shortcode = text[2:text.index('>')]
|
interwiki_shortcode = text[2:text.index('>')]
|
||||||
self.assert_interwiki_is_known(interwiki_shortcode)
|
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)
|
return """{{< %s "%s" >}}""" % (interwiki_shortcode, interwiki_urlpart)
|
||||||
|
|
||||||
|
@ -65,18 +68,18 @@ class MarkdownLinks():
|
||||||
url = ""
|
url = ""
|
||||||
title = ""
|
title = ""
|
||||||
if "|" not in text:
|
if "|" not in text:
|
||||||
url = self.parseInternalUrl(text)
|
url = self.parse_internal_url(text)
|
||||||
title = text[2:len(text)-2].replace(":", "/")
|
title = text[2:len(text) - 2].replace(":", "/")
|
||||||
else:
|
else:
|
||||||
url = self.parseInternalUrlWithoutTitle(text)
|
url = self.parse_internal_url_without_title(text)
|
||||||
title = self.parseTitle(text)
|
title = self.parse_title(text)
|
||||||
|
|
||||||
return """[%s]({{< relref "%s%s" >}})""" % (title, self.root_dir(url), url.replace(' ', '_'))
|
return """[%s]({{< relref "%s%s" >}})""" % (title, self.root_dir(url), url.replace(' ', '_'))
|
||||||
|
|
||||||
def convert_as_external_link(self, text):
|
def convert_as_external_link(self, text):
|
||||||
if '|' in text:
|
if '|' in text:
|
||||||
url = self.parseUrl(text)
|
url = self.parse_url(text)
|
||||||
title = self.parseTitle(text)
|
title = self.parse_title(text)
|
||||||
return "[" + title + "](" + url + ")"
|
return "[" + title + "](" + url + ")"
|
||||||
url = text.replace('[', '').replace(']', '')
|
url = text.replace('[', '').replace(']', '')
|
||||||
return "[" + url + "](" + url + ")"
|
return "[" + url + "](" + url + ")"
|
||||||
|
@ -87,5 +90,5 @@ class MarkdownLinks():
|
||||||
for (dirpath, dirnames, filenames) in walk(shortcodes_path):
|
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)):
|
||||||
raise ValueError("Unknown Interwiki code " + shortcode + " - please add a shortcode in the layouts dir!")
|
raise ValueError("Unknown Interwiki code " + shortcode + " - please add a shortcode in the layouts dir!")
|
|
@ -3,8 +3,8 @@ import re
|
||||||
from src.markdown_converter import MarkdownConverter
|
from src.markdown_converter import MarkdownConverter
|
||||||
|
|
||||||
|
|
||||||
@MarkdownConverter.Register
|
@MarkdownConverter.register
|
||||||
class MarkdownOrderedList():
|
class MarkdownOrderedList:
|
||||||
pattern = re.compile('(^(\s*)-\s)(.*)', re.MULTILINE)
|
pattern = re.compile('(^(\s*)-\s)(.*)', re.MULTILINE)
|
||||||
|
|
||||||
def convert(self, text):
|
def convert(self, text):
|
||||||
|
@ -14,27 +14,32 @@ class MarkdownOrderedList():
|
||||||
result = text
|
result = text
|
||||||
|
|
||||||
def deeper_depth(depth):
|
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):
|
def drop_in_depth_detected(depth):
|
||||||
return len(deeper_depth(depth)) > 0
|
return len(deeper_depth(depth)) > 0
|
||||||
|
|
||||||
def remove_deeper_depths(depth):
|
def remove_deeper_depths(depth):
|
||||||
for itm in deeper_depth(depth):
|
for itm in deeper_depth(depth):
|
||||||
last_used_linenrs.remove(itm)
|
last_used_linenrs.remove(itm)
|
||||||
|
|
||||||
def last_used_by_depth(depth):
|
def last_used_by_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 last_used_index(depth):
|
def last_used_index(depth):
|
||||||
return last_used_by_depth(depth)[0][2]
|
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):
|
def last_used_linenr(depth):
|
||||||
result = list(filter(lambda x: x[0] == depth, last_used_linenrs))
|
linenr_result = last_used_by_depth(depth)
|
||||||
if len(result) > 0:
|
if len(linenr_result) == 0:
|
||||||
last_used_linenrs.remove(result[0])
|
return 0
|
||||||
last_used_linenrs.append((depth, linenr, index))
|
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):
|
for match in MarkdownOrderedList.pattern.findall(text):
|
||||||
current_line = (match[0] + match[2]).replace('\n', '')
|
current_line = (match[0] + match[2]).replace('\n', '')
|
||||||
|
@ -42,7 +47,7 @@ class MarkdownOrderedList():
|
||||||
current_linenr = lines.index(current_line)
|
current_linenr = lines.index(current_line)
|
||||||
|
|
||||||
if last_used_linenr(current_depth) + 1 is current_linenr:
|
if last_used_linenr(current_depth) + 1 is current_linenr:
|
||||||
index = index + 1
|
index += 1
|
||||||
elif drop_in_depth_detected(current_depth):
|
elif drop_in_depth_detected(current_depth):
|
||||||
index = last_used_index(current_depth) + 1
|
index = last_used_index(current_depth) + 1
|
||||||
remove_deeper_depths(current_depth)
|
remove_deeper_depths(current_depth)
|
||||||
|
|
|
@ -8,6 +8,7 @@ class NopStyle(ABC):
|
||||||
def convert(self, text):
|
def convert(self, text):
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
||||||
class SimpleReplacementStyle(ABC):
|
class SimpleReplacementStyle(ABC):
|
||||||
def __init__(self, markdown_style, dokuwiki_style):
|
def __init__(self, markdown_style, dokuwiki_style):
|
||||||
self.markdown_style = markdown_style
|
self.markdown_style = markdown_style
|
||||||
|
@ -16,9 +17,9 @@ class SimpleReplacementStyle(ABC):
|
||||||
def convert(self, text):
|
def convert(self, text):
|
||||||
return text.replace(self.dokuwiki_style, self.markdown_style)
|
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:
|
if dokuwiki_style_end is None:
|
||||||
dokuwiki_style_end = dokuwiki_style_begin
|
dokuwiki_style_end = dokuwiki_style_begin
|
||||||
self.pattern = compile('(' + dokuwiki_style_begin + ')(.*?)(' + dokuwiki_style_end + ')')
|
self.pattern = compile('(' + dokuwiki_style_begin + ')(.*?)(' + dokuwiki_style_end + ')')
|
||||||
|
@ -32,33 +33,39 @@ class SimpleStyleBetweenTags(ABC):
|
||||||
result = result.replace(orig_header, new_header)
|
result = result.replace(orig_header, new_header)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@MarkdownConverter.Register
|
|
||||||
|
@MarkdownConverter.register
|
||||||
class MarkdownLineBreak(SimpleReplacementStyle):
|
class MarkdownLineBreak(SimpleReplacementStyle):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__('<br/>', '\\')
|
super().__init__('<br/>', '\\')
|
||||||
|
|
||||||
|
|
||||||
# inline html is supported with Hugo, don't need the tags.
|
# inline html is supported with Hugo, don't need the tags.
|
||||||
@MarkdownConverter.Register
|
@MarkdownConverter.register
|
||||||
class MarkdownInlineHtml():
|
class MarkdownInlineHtml:
|
||||||
def convert(self, text):
|
def convert(self, text):
|
||||||
return text.replace('<html>', '').replace('</html>', '')
|
return text.replace('<html>', '').replace('</html>', '')
|
||||||
|
|
||||||
|
|
||||||
# bold in Doku is bold in MD
|
# bold in Doku is bold in MD
|
||||||
@MarkdownConverter.Register
|
@MarkdownConverter.register
|
||||||
class MarkdownBold(NopStyle):
|
class MarkdownBold(NopStyle):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@MarkdownConverter.Register
|
|
||||||
|
@MarkdownConverter.register
|
||||||
class MarkdownItalic(SimpleStyleBetweenTags):
|
class MarkdownItalic(SimpleStyleBetweenTags):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__('*', '//')
|
super().__init__('*', '//')
|
||||||
|
|
||||||
@MarkdownConverter.Register
|
|
||||||
|
@MarkdownConverter.register
|
||||||
class MarkdownStrikeThrough(SimpleStyleBetweenTags):
|
class MarkdownStrikeThrough(SimpleStyleBetweenTags):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__('~~', '<del>', '</del>')
|
super().__init__('~~', '<del>', '</del>')
|
||||||
|
|
||||||
@MarkdownConverter.Register
|
|
||||||
|
@MarkdownConverter.register
|
||||||
class MarkdownInlineCode(SimpleStyleBetweenTags):
|
class MarkdownInlineCode(SimpleStyleBetweenTags):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__('`', "''", "''")
|
super().__init__('`', "''", "''")
|
|
@ -1,8 +1,9 @@
|
||||||
from src.markdown_converter import MarkdownConverter
|
from src.markdown_converter import MarkdownConverter
|
||||||
from re import compile
|
from re import compile
|
||||||
|
|
||||||
@MarkdownConverter.Register
|
|
||||||
class MarkdownTodo():
|
@MarkdownConverter.register
|
||||||
|
class MarkdownTodo:
|
||||||
pattern = compile('(<todo(\s#)?>)(.*?)(</todo>)')
|
pattern = compile('(<todo(\s#)?>)(.*?)(</todo>)')
|
||||||
todo = '- [ ] '
|
todo = '- [ ] '
|
||||||
done = '- [x] '
|
done = '- [x] '
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
class MarkdownConverter:
|
class MarkdownConverter:
|
||||||
converters = []
|
converters = []
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def Register(cls, converter_class):
|
def register(cls, converter_class):
|
||||||
cls.converters.append(converter_class())
|
cls.converters.append(converter_class())
|
||||||
return converter_class
|
return converter_class
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,6 @@
|
||||||
|
|
||||||
##### header 5
|
##### 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.
|
||||||
|
|
|
@ -2,8 +2,8 @@ from unittest import TestCase
|
||||||
|
|
||||||
from src.markdown.code import MarkdownCode, MarkdownFile
|
from src.markdown.code import MarkdownCode, MarkdownFile
|
||||||
|
|
||||||
class TestMarkdownCode(TestCase):
|
|
||||||
|
|
||||||
|
class TestMarkdownCode(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.code_converter = MarkdownCode()
|
self.code_converter = MarkdownCode()
|
||||||
self.file_converter = MarkdownFile()
|
self.file_converter = MarkdownFile()
|
||||||
|
|
|
@ -2,6 +2,7 @@ from unittest import TestCase
|
||||||
|
|
||||||
from src.markdown.images import MarkdownImages
|
from src.markdown.images import MarkdownImages
|
||||||
|
|
||||||
|
|
||||||
class TestMarkdownImages(TestCase):
|
class TestMarkdownImages(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.converter = MarkdownImages()
|
self.converter = MarkdownImages()
|
||||||
|
|
|
@ -22,105 +22,105 @@ class TestMarkdownLinks(TestCase):
|
||||||
self.assertEqual(no_real_doku_link, self.converter.convert(no_real_doku_link))
|
self.assertEqual(no_real_doku_link, self.converter.convert(no_real_doku_link))
|
||||||
|
|
||||||
def test_internal_link_with_space_converted_to_underscore(self):
|
def test_internal_link_with_space_converted_to_underscore(self):
|
||||||
mdLink = """[magic properties]({{< relref "magic_properties.md" >}})"""
|
md_link = """[magic properties]({{< relref "magic_properties.md" >}})"""
|
||||||
dokuLink = "[[magic properties]]"
|
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):
|
def test_internal_link_to_home_converted_to_index(self):
|
||||||
mdLink = """[subpage/home]({{< relref "subpage/_index.md" >}})"""
|
md_link = """[subpage/home]({{< relref "subpage/_index.md" >}})"""
|
||||||
dokuLink = "[[subpage/home]]"
|
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):
|
def test_internal_link_with_ref_to_root_not_prefixed_with_root_dir(self):
|
||||||
DokuWikiToHugo.root_dir = "pages"
|
DokuWikiToHugo.root_dir = "pages"
|
||||||
mdLink = """[Download SaveGame #one]({{< relref "/games/Wizardry8/Wizardry8_Saves01.rar" >}})"""
|
md_link = """[Download SaveGame #one]({{< relref "/games/Wizardry8/Wizardry8_Saves01.rar" >}})"""
|
||||||
dokuLink = """[[/games/Wizardry8/Wizardry8_Saves01.rar|Download SaveGame #one]]"""
|
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):
|
def test_internal_link_prefixed_with_configured_root_dir_if_subdir(self):
|
||||||
DokuWikiToHugo.root_dir = "pages"
|
DokuWikiToHugo.root_dir = "pages"
|
||||||
mdLink = """[bla/blie]({{< relref "pages/bla/blie.md" >}})"""
|
md_link = """[bla/blie]({{< relref "pages/bla/blie.md" >}})"""
|
||||||
dokuLink = "[[bla:blie]]"
|
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):
|
def test_internal_links_not_prefixed_with_configured_root_dir_if_currdir(self):
|
||||||
DokuWikiToHugo.root_dir = "pages"
|
DokuWikiToHugo.root_dir = "pages"
|
||||||
mdLink = """[bla]({{< relref "bla.md" >}})"""
|
md_link = """[bla]({{< relref "bla.md" >}})"""
|
||||||
dokuLink = "[[bla]]"
|
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):
|
def test_internal_links_without_text_converted_properly(self):
|
||||||
mdLink = """[bla]({{< relref "bla.md" >}})"""
|
md_link = """[bla]({{< relref "bla.md" >}})"""
|
||||||
dokuLink = "[[bla]]"
|
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):
|
def test_internal_links_with_sublink_converted_properly(self):
|
||||||
mdLink = """[text]({{< relref "bla/blie.md" >}})"""
|
md_link = """[text]({{< relref "bla/blie.md" >}})"""
|
||||||
dokuLink = "[[bla:blie|text]]"
|
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):
|
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"""
|
md_link = """[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"
|
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):
|
def test_internal_links_with_some_text_in_line_converted_properly(self):
|
||||||
mdLink = """[text]({{< relref "bla.md" >}}) wow this looks cool"""
|
md_link = """[text]({{< relref "bla.md" >}}) wow this looks cool"""
|
||||||
dokuLink = "[[bla|text]] 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):
|
def test_internal_link_with_image_tag(self):
|
||||||
dokuLink = "[[code|<img src='code.jpg'>]]"
|
doku_link = "[[code|<img src='code.jpg'>]]"
|
||||||
mdLink = """[<img src='code.jpg'>]({{< relref "code.md" >}})"""
|
md_link = """[<img src='code.jpg'>]({{< 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):
|
def test_internal_links_with_extension_not_suffixed_with_md(self):
|
||||||
mdLink = """[text]({{< relref "bla.zip" >}})"""
|
md_link = """[text]({{< relref "bla.zip" >}})"""
|
||||||
dokuLink = "[[bla.zip|text]]"
|
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):
|
def test_internal_links_converted_properly(self):
|
||||||
mdLink = """[text]({{< relref "bla.md" >}})"""
|
md_link = """[text]({{< relref "bla.md" >}})"""
|
||||||
dokuLink = "[[bla|text]]"
|
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):
|
def test_unknown_interwiki_link_throws_exception(self):
|
||||||
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):
|
def test_known_interwiki_link_with_some_spaces(self):
|
||||||
mdLink = """{{< lib "Purple Cow: Transform Your Business by Being Remarkable" >}}"""
|
md_link = """{{< lib "Purple Cow: Transform Your Business by Being Remarkable" >}}"""
|
||||||
dokuLink = "[[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):
|
def test_known_interwiki_link_converts_successfully(self):
|
||||||
# see https://gohugo.io/extras/shortcodes/
|
# see https://gohugo.io/extras/shortcodes/
|
||||||
mdLink = """{{< wp "Wiki" >}}"""
|
md_link = """{{< wp "Wiki" >}}"""
|
||||||
dokuLink = "[[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):
|
def test_external_link_without_title(self):
|
||||||
mdLink = "[https://www.google.com](https://www.google.com)"
|
md_link = "[https://www.google.com](https://www.google.com)"
|
||||||
dokuLink = "[[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):
|
def test_external_links_converted_properly(self):
|
||||||
mdLink = "[Wouter Groeneveld](https://github.com/wgroeneveld/)"
|
md_link = "[Wouter Groeneveld](https://github.com/wgroeneveld/)"
|
||||||
dokuLink = "[[https://github.com/wgroeneveld/|Wouter Groeneveld]]"
|
doku_link = "[[https://github.com/wgroeneveld/|Wouter Groeneveld]]"
|
||||||
|
|
||||||
self.assertEqual(mdLink, self.converter.convert(dokuLink))
|
self.assertEqual(md_link, self.converter.convert(doku_link))
|
||||||
|
|
|
@ -2,6 +2,7 @@ from unittest import TestCase
|
||||||
|
|
||||||
from src.markdown.lists import MarkdownOrderedList
|
from src.markdown.lists import MarkdownOrderedList
|
||||||
|
|
||||||
|
|
||||||
class TestMarkdownLists(TestCase):
|
class TestMarkdownLists(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.converter = MarkdownOrderedList()
|
self.converter = MarkdownOrderedList()
|
||||||
|
@ -43,7 +44,6 @@ five - six
|
||||||
actual = self.converter.convert(src)
|
actual = self.converter.convert(src)
|
||||||
self.assertEqual(expected, actual)
|
self.assertEqual(expected, actual)
|
||||||
|
|
||||||
|
|
||||||
def test_ordered_lists_nested(self):
|
def test_ordered_lists_nested(self):
|
||||||
src = '''
|
src = '''
|
||||||
- Werkt zoals Rummikub:
|
- Werkt zoals Rummikub:
|
||||||
|
|
|
@ -5,7 +5,6 @@ from src.markdown.simplestyle import MarkdownBold, MarkdownItalic, MarkdownStrik
|
||||||
|
|
||||||
|
|
||||||
class TestMarkdownSimpleStyles(TestCase):
|
class TestMarkdownSimpleStyles(TestCase):
|
||||||
|
|
||||||
def test_inline_html_simply_removes_tags(self):
|
def test_inline_html_simply_removes_tags(self):
|
||||||
src = "<html><strong>sup</strong></html>"
|
src = "<html><strong>sup</strong></html>"
|
||||||
expected = "<strong>sup</strong>"
|
expected = "<strong>sup</strong>"
|
||||||
|
|
|
@ -7,7 +7,6 @@ from src.dokuwiki_to_hugo import DokuWikiToHugo
|
||||||
|
|
||||||
|
|
||||||
class TestDokuWikiToHugo(TestCase):
|
class TestDokuWikiToHugo(TestCase):
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
shutil.rmtree('output')
|
shutil.rmtree('output')
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@ from src.hugo_file_config import HugoFileConfig
|
||||||
|
|
||||||
|
|
||||||
class TestHugoFileConfig(TestCase):
|
class TestHugoFileConfig(TestCase):
|
||||||
|
|
||||||
def set_file_timestamp(self):
|
def set_file_timestamp(self):
|
||||||
date = datetime(2014, 10, 10, 12)
|
date = datetime(2014, 10, 10, 12)
|
||||||
u_time = mktime(date.timetuple())
|
u_time = mktime(date.timetuple())
|
||||||
|
|
|
@ -4,8 +4,8 @@ from pathlib import Path
|
||||||
|
|
||||||
from src.markdown_converter import MarkdownConverter
|
from src.markdown_converter import MarkdownConverter
|
||||||
|
|
||||||
class TestMarkdownHeader(TestCase):
|
|
||||||
|
|
||||||
|
class TestMarkdownHeader(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.converter = MarkdownConverter("dokuwiki_example.txt")
|
self.converter = MarkdownConverter("dokuwiki_example.txt")
|
||||||
|
|
||||||
|
@ -16,4 +16,3 @@ class TestMarkdownHeader(TestCase):
|
||||||
|
|
||||||
print(actual)
|
print(actual)
|
||||||
self.assertEqual(expected, actual, "Files not matching!")
|
self.assertEqual(expected, actual, "Files not matching!")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue