summaryrefslogtreecommitdiff
path: root/panfry/page.py
diff options
context:
space:
mode:
Diffstat (limited to 'panfry/page.py')
-rwxr-xr-xpanfry/page.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/panfry/page.py b/panfry/page.py
index 2c82e04..76620bc 100755
--- a/panfry/page.py
+++ b/panfry/page.py
@@ -24,6 +24,19 @@ class TextFile:
return self.lines[0]
+class TOCItem:
+ '''
+ Table of Contents Line Item
+ '''
+ def __init__(self, heading, level):
+ self.heading = heading
+ self.level = level
+
+ @property
+ def section_id(self):
+ return self.heading.lower().replace(' ', '-')
+
+
class Page(TextFile):
'''
Represents single page source file.
@@ -70,14 +83,14 @@ class Page(TextFile):
heading = ''
for line in self.lines:
if heading and re.match('[=]{2}', line):
- toc.append((heading, 1))
+ toc.append(TOCItem(heading, 1))
continue
if heading and re.match('[-]{2}', line):
- toc.append((heading, 2))
+ toc.append(TOCItem(heading, 2))
continue
if re.match('#+.+[A-z|0-9]', line):
level = len(re.match('#+', line).group())
- toc.append((line.split(' ', 1)[1].strip(), level))
+ toc.append(TOCItem(line.split(' ', 1)[1].strip(), level))
continue
heading = line.strip()