summaryrefslogtreecommitdiff
path: root/panfry/page.py
diff options
context:
space:
mode:
authorScott Bahling <sbahling@mudgum.net>2013-07-28 12:54:44 +0200
committerScott Bahling <sbahling@mudgum.net>2013-07-28 12:54:44 +0200
commit8ba0a5fe5708569b4cc948dc3460d4eb34755b23 (patch)
treebd7674d34138a53dfcc14ef9cce004d0919cd0bb /panfry/page.py
parent921dd24342f9b940751ddf3f5ca73132131a4062 (diff)
parentab77b7fcc1416c1acb8e77572db7b30c72cc5292 (diff)
downloadpanfry-8ba0a5fe5708569b4cc948dc3460d4eb34755b23.tar.gz
panfry-8ba0a5fe5708569b4cc948dc3460d4eb34755b23.tar.xz
panfry-8ba0a5fe5708569b4cc948dc3460d4eb34755b23.zip
Merge branch 'master' of mudgum.net:panfry
Diffstat (limited to 'panfry/page.py')
-rwxr-xr-xpanfry/page.py36
1 files changed, 11 insertions, 25 deletions
diff --git a/panfry/page.py b/panfry/page.py
index 722241c..efd3561 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.
@@ -59,6 +38,9 @@ class Page(TextFile):
self.format = format
self._markdown = ''
+ def __repr__(self):
+ return self.markdown
+
@property
def markdown(self):
if self.format == 'markdown':
@@ -106,14 +88,18 @@ 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()