diff --git a/README.md b/README.md index 1d973f6..bc4430c 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ See https://www.dokuwiki.org/wiki:syntax * bold, italic, sub/sup, strikethrough * headings with equal sign * linebreaks (double backslash) are at this moment replaced with HTML BRs. +* unordered lists (already native MD), ordered lists using dash to markdown ### embedding HTML @@ -36,14 +37,17 @@ Simply add custom.html and link to the website of your choice. Use Hugo's `{{ in ## TODO +### styling + * 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? +* emoticons +* no formatting (nowiki, %%) - should this just be a pre? + +### structure + * build file structure - wire everything together * build header TOML with timestamps, draft false etc -* ordered lists using dash to markdown? -* emoticons -* no formatting (nowiki) - should this just be a pre? -* preventing of wiki markup %% - what to do with it? ## Not supported and probably will never be diff --git a/src/markdown/lists.py b/src/markdown/lists.py new file mode 100644 index 0000000..d0fc87f --- /dev/null +++ b/src/markdown/lists.py @@ -0,0 +1,24 @@ +import re + +class MarkdownOrderedList: + pattern = re.compile('(^-\s)(.*)', re.MULTILINE) + + def convert(self, text): + lines = text.split('\n') + last_used_linenr = 0 + index = 0 + result = text + + for match in MarkdownOrderedList.pattern.findall(text): + line = ''.join(match) + linenr = lines.index(line) + + if last_used_linenr + 1 is linenr: + index = index + 1 + else: + index = 1 + last_used_linenr = linenr + + result = result.replace(line, str(index) + '. ' + match[1]) + + return result \ No newline at end of file diff --git a/test/markdown/test_lists.py b/test/markdown/test_lists.py new file mode 100644 index 0000000..28bc42e --- /dev/null +++ b/test/markdown/test_lists.py @@ -0,0 +1,65 @@ +from unittest import TestCase + +from src.markdown.lists import MarkdownOrderedList + + +class TestMarkdownLists(TestCase): + def setUp(self): + self.converter = MarkdownOrderedList() + + def test_dont_convert_if_no_list_found(self): + self.assertEqual('hello there', self.converter.convert('hello there')) + + def test_only_convert_dashes_if_beginning_sentence(self): + src = ''' +- one-two-three +- four + +five - six + ''' + expected = ''' +1. one-two-three +2. four + +five - six + ''' + + self.assertEqual(expected, self.converter.convert(src)) + + def test_multiple_ordered_lists_in_text(self): + src = ''' +- one +- two + +three +- four +- five +six + ''' + expected = ''' +1. one +2. two + +three +1. four +2. five +six + ''' + + self.assertEqual(expected, self.converter.convert(src)) + + def test_single_ordered_list(self): + src = ''' +- one +- two + +three + ''' + expected = ''' +1. one +2. two + +three + ''' + + self.assertEqual(expected, self.converter.convert(src)) \ No newline at end of file