added simple styles, moved to markdown submodule
parent
6810e0168f
commit
600098bac3
21
README.md
21
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?
|
|
@ -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
|
|
@ -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__('<br/>', '\\')
|
||||
|
||||
# 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__('~~', '<del>', '</del>')
|
|
@ -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 = []
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from unittest import TestCase
|
||||
|
||||
from src.markdown_headers import MarkdownHeader
|
||||
from src.markdown.headers import MarkdownHeader
|
||||
|
||||
|
||||
class TestMarkdownHeader(TestCase):
|
|
@ -1,6 +1,6 @@
|
|||
from unittest import TestCase
|
||||
|
||||
from src.markdown_links import MarkdownLinks
|
||||
from src.markdown.links import MarkdownLinks
|
||||
|
||||
|
||||
class TestMarkdownLinks(TestCase):
|
|
@ -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 <br/>
|
||||
is it me you're looking for?<br/>
|
||||
i can see it in your eyes...
|
||||
'''
|
||||
|
||||
self.assertEqual(expected, MarkdownLineBreak().convert(src))
|
||||
|
||||
def test_some_strikethrough_style(self):
|
||||
src = 'some <del>deleted</del> 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))
|
Loading…
Reference in New Issue