diff --git a/README.md b/README.md index 39f970c..272b3d7 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,23 @@ # dokuwiki-to-hugo + A DokuWiki to Hugo file exporter to quickly migrate your existing PHP wiki to Hugo + +See https://www.dokuwiki.org/wiki:syntax + +## TODO + +* Figure out image links ala http://php.net|{{wiki:dokuwiki-128.png}} +* Tables, should complex ones be supported or can I do a manual convert? +* build file structure - wire everything together +* build header TOML with timestamps, draft false etc +* lists +* emoticons +* no formatting (nowiki) - should this just be a pre? +* code hilighting (inline and multiline and downloadable) +* embedding html - remove html tag and done? + +## Not supported and probably will never be + +* embedding php - kill it with fire? +* macro's - kill it with fire? +* what to do with footnotes? \ No newline at end of file diff --git a/src/markdown_headers.py b/src/markdown/headers.py similarity index 88% rename from src/markdown_headers.py rename to src/markdown/headers.py index 576f235..5f51a5f 100644 --- a/src/markdown_headers.py +++ b/src/markdown/headers.py @@ -15,7 +15,7 @@ class MarkdownHeader: def convert(self, text): result = text for regex_head in MarkdownHeader.pattern.findall(text): - orig_header = regex_head[0] + regex_head[1] + regex_head[2] + orig_header = ''.join(regex_head) new_header = ('#' * MarkdownHeader.config[regex_head[0]]) + regex_head[1] result = result.replace(orig_header, new_header) return result diff --git a/src/markdown_links.py b/src/markdown/links.py similarity index 100% rename from src/markdown_links.py rename to src/markdown/links.py diff --git a/src/markdown/simplestyle.py b/src/markdown/simplestyle.py new file mode 100644 index 0000000..f1472a9 --- /dev/null +++ b/src/markdown/simplestyle.py @@ -0,0 +1,46 @@ +from abc import ABC +from re import compile + +class NopStyle(ABC): + def convert(self, text): + return text + +class SimpleReplacementStyle(ABC): + def __init__(self, markdown_style, dokuwiki_style): + self.markdown_style = markdown_style + self.dokuwiki_style = dokuwiki_style + + 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): + if dokuwiki_style_end is None: + dokuwiki_style_end = dokuwiki_style_begin + self.pattern = compile('(' + dokuwiki_style_begin + ')(.*?)(' + dokuwiki_style_end + ')') + self.markdown_style = markdown_style + + def convert(self, text): + result = text + for regex_head in self.pattern.findall(text): + orig_header = ''.join(regex_head) + new_header = self.markdown_style + regex_head[1] + self.markdown_style + result = result.replace(orig_header, new_header) + return result + +class MarkdownLineBreak(SimpleReplacementStyle): + def __init__(self): + super().__init__('
', '\\') + +# bold in Doku is bold in MD +class MarkdownBold(NopStyle): + pass + +class MarkdownItalic(SimpleStyleBetweenTags): + def __init__(self): + super().__init__('*', '//') + +class MarkdownStrikeThrough(SimpleStyleBetweenTags): + def __init__(self): + super().__init__('~~', '', '') diff --git a/src/markdown_converter.py b/src/markdown_converter.py index b0dfe0b..de583cc 100644 --- a/src/markdown_converter.py +++ b/src/markdown_converter.py @@ -1,12 +1,22 @@ -from src.markdown_headers import MarkdownHeader -from src.markdown_links import MarkdownLinks from functools import reduce +from src.markdown.links import MarkdownLinks + +from src.markdown.headers import MarkdownHeader +from src.markdown.simplestyle import MarkdownItalic, MarkdownBold, MarkdownStrikeThrough + + class MarkdownConverter: def __init__(self, file): self.file = file - self.converters = (MarkdownHeader(), MarkdownLinks()) + self.converters = ( + MarkdownHeader(), + MarkdownLinks(), + MarkdownItalic(), + MarkdownBold(), + MarkdownStrikeThrough() + ) def convert(self): converted = [] diff --git a/test/markdown/__init__.py b/test/markdown/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/test_markdown_header.py b/test/markdown/test_header.py similarity index 95% rename from test/test_markdown_header.py rename to test/markdown/test_header.py index 8113553..bec10d7 100644 --- a/test/test_markdown_header.py +++ b/test/markdown/test_header.py @@ -1,6 +1,6 @@ from unittest import TestCase -from src.markdown_headers import MarkdownHeader +from src.markdown.headers import MarkdownHeader class TestMarkdownHeader(TestCase): diff --git a/test/test_markdown_links.py b/test/markdown/test_links.py similarity index 97% rename from test/test_markdown_links.py rename to test/markdown/test_links.py index c03c3f0..0e1c03d 100644 --- a/test/test_markdown_links.py +++ b/test/markdown/test_links.py @@ -1,6 +1,6 @@ from unittest import TestCase -from src.markdown_links import MarkdownLinks +from src.markdown.links import MarkdownLinks class TestMarkdownLinks(TestCase): diff --git a/test/markdown/test_simplestyle.py b/test/markdown/test_simplestyle.py new file mode 100644 index 0000000..bf63c14 --- /dev/null +++ b/test/markdown/test_simplestyle.py @@ -0,0 +1,32 @@ +from unittest import TestCase + +from src.markdown.simplestyle import MarkdownBold, MarkdownItalic, MarkdownStrikeThrough, MarkdownLineBreak + + +class TestMarkdownSimpleStyles(TestCase): + + def test_some_linebreaks(self): + src = ''' + hello \\ + is it me you're looking for?\\ + i can see it in your eyes... + ''' + expected = ''' + hello
+ is it me you're looking for?
+ i can see it in your eyes... + ''' + + self.assertEqual(expected, MarkdownLineBreak().convert(src)) + + def test_some_strikethrough_style(self): + src = 'some deleted style' + self.assertEqual('some ~~deleted~~ style', MarkdownStrikeThrough().convert(src)) + + def test_some_italic_styles(self): + src = '//italic// stuff right //there// bam!' + self.assertEqual('*italic* stuff right *there* bam!', MarkdownItalic().convert(src)) + + 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