todo's as dokuwiki's plugin

This commit is contained in:
wgroeneveld 2017-01-15 20:40:23 +01:00
parent 0e3f7aaa40
commit 17625d6f1d
3 changed files with 66 additions and 0 deletions

View File

@ -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
<todo>a todo list</todo>
<todo #>done</todo>
<todo #>also checked off</todo>
```
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.

15
src/markdown/todo.py Normal file
View File

@ -0,0 +1,15 @@
from src.markdown_converter import MarkdownConverter
from re import compile
@MarkdownConverter.Register
class MarkdownTodo():
pattern = compile('(<todo(\s#)?>)(.*?)(</todo>)')
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

View File

@ -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 = '''
<todo>item 1</todo>
<todo #>item 2</todo>
'''
expected = '''
- [ ] item 1
- [x] item 2
'''
self.assertEqual(expected, self.converter.convert(src))
def test_converts_todos(self):
src = '''
<todo>item 1</todo>
<todo>item 2</todo>
'''
expected = '''
- [ ] item 1
- [ ] item 2
'''
self.assertEqual(expected, self.converter.convert(src))