diff options
Diffstat (limited to 'panfry/page.py')
| -rwxr-xr-x | panfry/page.py | 36 |
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() |
