From ae99cfbd9a0372b577a23636f0677f266a559c5f Mon Sep 17 00:00:00 2001 From: Scott Bahling Date: Tue, 19 Mar 2013 18:25:18 +0100 Subject: 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. --- panfry/page.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'panfry/page.py') 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() -- cgit v1.2.3