56 lines
1.2 KiB
Python
56 lines
1.2 KiB
Python
import markdown
|
|
|
|
from markdone_python.common import section_pattern
|
|
from markdone_python.common import tag_pattern
|
|
from markdone_python.common import task_pattern
|
|
from markdone_python.rendering_extensions import MarkdoneExtension
|
|
|
|
|
|
class Note(object):
|
|
def __init__(self, text: str):
|
|
self.text = text
|
|
self.tasks = []
|
|
self.sections = []
|
|
self.tags = set()
|
|
self.parse(text)
|
|
|
|
def parse(self, text: str):
|
|
for line in text.splitlines():
|
|
if section_pattern.match(line):
|
|
self.sections.append(line)
|
|
elif task_pattern.match(line):
|
|
self.tasks.append(line)
|
|
|
|
tags = tag_pattern.findall(line)
|
|
if tags:
|
|
print('tags: ', tags)
|
|
self.tags.update(tags)
|
|
|
|
print('All tags: ', self.tags)
|
|
|
|
def render(self):
|
|
|
|
print(markdown.markdown(
|
|
self.text,
|
|
extensions=[MarkdoneExtension()]
|
|
))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
Note("""
|
|
# My header
|
|
|
|
## Subheader
|
|
Got some !tags !here
|
|
More !tags with !stuff-here,!and, !there
|
|
|
|
* [] task1 !tag
|
|
* [ ] task2
|
|
* [x] task3
|
|
* [X] task4
|
|
* [X] task4
|
|
* [ ] task5
|
|
* [ ] task6
|
|
* [ ] task7
|
|
""").render()
|