summaryrefslogtreecommitdiff
path: root/panfry/document.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/document.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/document.py')
-rwxr-xr-xpanfry/document.py34
1 files changed, 24 insertions, 10 deletions
diff --git a/panfry/document.py b/panfry/document.py
index 0b450da..aa29561 100755
--- a/panfry/document.py
+++ b/panfry/document.py
@@ -14,9 +14,20 @@ class Document:
self.src_path = path
self.meta = self.get_meta(path)
self.pages = self.get_pages(path)
+ self.full_toc = True
- css_file = 'css/style.css'
- workdir = 'stdocs-work'
+ self.css_file = 'css/style.css'
+
+ @property
+ def set_simple_toc(self):
+ self.full_toc = False
+
+ @property
+ def set_full_toc(self):
+ self.full_toc = True
+
+ def set_templater(self, templater):
+ self.templater = templater
@property
def title(self):
@@ -56,9 +67,6 @@ class Document:
return meta
- def set_templater(self, templater):
- self.templater = templater
-
def next_page(self, page):
try:
idx = self.pages.index(page)
@@ -85,11 +93,17 @@ class Document:
'''
links = []
for page in self.pages:
- title, level = page.title
- links.append(dict(link=unicode(page.htmlfile, "utf8"),
- text=unicode(title, "utf8"),
- level=level,
- ))
+ if self.full_toc:
+ toc = page.toc
+ else:
+ toc = [page.toc[0]]
+
+ for tocitem in toc:
+ link = '%s#%s' % (page.htmlfile, tocitem.section_id)
+ links.append(dict(link=unicode(link, "utf8"),
+ text=unicode(tocitem.heading, "utf8"),
+ level=tocitem.level,
+ ))
return links