summaryrefslogtreecommitdiff
path: root/panfry/page.py
diff options
context:
space:
mode:
authorScott Bahling <sbahling@suse.de>2013-04-12 11:48:07 +0200
committerScott Bahling <sbahling@suse.de>2013-04-12 11:48:07 +0200
commit094530f92d678f9c2f2ad498a2c21653de399a99 (patch)
tree6e6d2d9b20b1bf1f3407d1d042a0d12ef92d49c9 /panfry/page.py
parent7eba8bd7180f538c1bfdd338abf6c858ba9dfb67 (diff)
downloadpanfry-094530f92d678f9c2f2ad498a2c21653de399a99.tar.gz
panfry-094530f92d678f9c2f2ad498a2c21653de399a99.tar.xz
panfry-094530f92d678f9c2f2ad498a2c21653de399a99.zip
Implement json TOC
Diffstat (limited to 'panfry/page.py')
-rwxr-xr-xpanfry/page.py29
1 files changed, 4 insertions, 25 deletions
diff --git a/panfry/page.py b/panfry/page.py
index 722241c..21b6323 100755
--- a/panfry/page.py
+++ b/panfry/page.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
import re
import pandoc
+from panfry.toc import TOCItem
class TextFile:
@@ -25,28 +26,6 @@ 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 header_id(self):
- # - Remove all formatting, links, etc.
- # - Remove all punctuation, except underscores, hyphens, and periods.
- # - Replace all spaces and newlines with hyphens.
- # - Convert all alphabetic characters to lowercase.
- # - Remove everything up to the first letter (identifiers may not begin
- # with a number or punctuation mark).
-
- remove = re.compile('^[^a-zA-Z]|[+~!@#$%^&*\(\){}\[\];:"\',<>?/\`]')
- header_id = self.heading.lower().replace('\n', ' ').replace(' ', '-')
- return remove.sub('', header_id)
-
-
class Page(TextFile):
'''
Represents single page source file.
@@ -106,14 +85,14 @@ class Page(TextFile):
for line in self.markdown.split('\n'):
line = line.strip()
if heading and re.match('[=]{2}', line):
- toc.append(TOCItem(heading, 1))
+ toc.append(TOCItem(heading, 1, self.htmlfile))
continue
if heading and re.match('[-]{2}', line):
- toc.append(TOCItem(heading, 2))
+ toc.append(TOCItem(heading, 2, self.htmlfile))
continue
if re.match('#+.+[A-z|0-9]', line):
level = len(re.match('#+', line).group())
- toc.append(TOCItem(line.split(' ', 1)[1].strip(), level))
+ toc.append(TOCItem(line.split(' ', 1)[1].strip(), level, self.htmlfile))
continue
heading = line.strip()