summaryrefslogtreecommitdiff
path: root/panfry/page.py
diff options
context:
space:
mode:
authorScott Bahling <sbahling@mudgum.net>2013-03-19 18:25:18 +0100
committerScott Bahling <sbahling@mudgum.net>2013-03-19 18:25:18 +0100
commitae99cfbd9a0372b577a23636f0677f266a559c5f (patch)
tree0ea33cec22901661a433402941286cafe7895641 /panfry/page.py
parent59e2443d531ace2005de5a9e830e063d79808427 (diff)
downloadpanfry-ae99cfbd9a0372b577a23636f0677f266a559c5f.tar.gz
panfry-ae99cfbd9a0372b577a23636f0677f266a559c5f.tar.xz
panfry-ae99cfbd9a0372b577a23636f0677f266a559c5f.zip
Implement full table of contents generation
By default panfry now generates a full table of contents navigation for split page documents. This means the TOC navitation has links to all pages and page sections. Simple, page only level table of contents can be switched on by passing the --simple-toc option.
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()