-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkboxify.py
24 lines (22 loc) · 1 KB
/
checkboxify.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from markdown import Markdown
from markdown.preprocessors import Preprocessor
from markdown.extensions import Extension
# preprocessor extensions shouldn't actually be used like this
# instead some sort of inline processor would have been the correct choice
# but this way is simpler
class Checkboxifier(Preprocessor):
def run(self, lines):
new_lines = []
for line in lines:
if line.startswith("- [ ]"):
new_lines.append(f"<input type='checkbox'/> {line[6:]}<br>")
elif line.startswith("- [x]"):
new_lines.append(f"<input type='checkbox' checked/> <span class='dim'>{line[6:]}</span><br>")
elif line.startswith("- [/]"):
new_lines.append(f"<input type='checkbox' class='semi'/> {line[6:]}<br>")
else:
new_lines.append(line)
return new_lines
class CheckboxifyExtension(Extension):
def extendMarkdown(self, md):
md.preprocessors.register(Checkboxifier(md), "checkboxify", 12)