diff --git a/README.md b/README.md index cc42f8d..6bac9a7 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,26 @@ You'll have to come up with your own shortcodes for those. See wp.html in the layouts directory. You could customize interwiki links from dokuwiki: `[[custom>somelink]]` would refer to some custom wiki. Simply add custom.html and link to the website of your choice. Use Hugo's `{{ index .Params 0 }}` to get the link content. +### TODO's + +There's a dokuwiki plugin which enables things like: + + ```html + a todo list + done + also checked off + ``` + +Hugo supports this using this MD syntax: + +``` +- [ ] a todo list +- [x] done +- [x] also checked off +``` + +I like lists. So this is naturally supported. + ### I want to create my own syntax conversion! No problem, the project was made with extensibility in mind. diff --git a/src/markdown/todo.py b/src/markdown/todo.py new file mode 100644 index 0000000..e9ccdee --- /dev/null +++ b/src/markdown/todo.py @@ -0,0 +1,15 @@ +from src.markdown_converter import MarkdownConverter +from re import compile + +@MarkdownConverter.Register +class MarkdownTodo(): + pattern = compile('()(.*?)()') + todo = '- [ ] ' + done = '- [x] ' + + def convert(self, text): + result = text + 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 diff --git a/test/markdown/test_todo.py b/test/markdown/test_todo.py new file mode 100644 index 0000000..f202c51 --- /dev/null +++ b/test/markdown/test_todo.py @@ -0,0 +1,31 @@ +from unittest import TestCase + +from src.markdown.todo import MarkdownTodo + + +class TestMarkdownTodo(TestCase): + + def setUp(self): + self.converter = MarkdownTodo() + + def test_converts_todos_with_marked_as_done(self): + src = ''' + item 1 + item 2 + ''' + expected = ''' + - [ ] item 1 + - [x] item 2 + ''' + self.assertEqual(expected, self.converter.convert(src)) + + def test_converts_todos(self): + src = ''' + item 1 + item 2 + ''' + expected = ''' + - [ ] item 1 + - [ ] item 2 + ''' + self.assertEqual(expected, self.converter.convert(src))