dokuwiki-to-hugo/src/markdown_headers.py

24 lines
544 B
Python
Raw Normal View History

2017-01-12 18:02:09 +01:00
from collections import OrderedDict
2017-01-12 16:48:09 +01:00
class MarkdownHeader:
2017-01-12 18:02:09 +01:00
head = "="
config = {
'======': 1,
'=====': 2,
'====': 3,
'===': 4,
'==': 5
}
2017-01-12 16:48:09 +01:00
def convert(self, text):
2017-01-12 18:02:09 +01:00
config = OrderedDict(sorted(MarkdownHeader.config.items(), key = lambda t : t[1]))
for key, val in config.items():
if text.startswith(key):
return ('#' * val) + self.strip(text)
return text
2017-01-12 16:48:09 +01:00
def strip(self, text):
2017-01-12 18:02:09 +01:00
return text.replace(MarkdownHeader.head, "")