diff options
Diffstat (limited to 'panfry/document.py')
| -rwxr-xr-x | panfry/document.py | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/panfry/document.py b/panfry/document.py index 969d5f4..4379f6e 100755 --- a/panfry/document.py +++ b/panfry/document.py @@ -40,26 +40,24 @@ class Document: returns: markdown source with expanded links ''' re_link1 = re.compile(r'(\[(?P<s>[^\]^]+)\])\((?P<l>#.*)\)', re.S) - re_link2 = re.compile(r'(\[(?P<s>[^\]^]+)\]): (?P<l>#[a-z0-9-]+)', - re.S) - re_link3 = re.compile(r'(\[(?P<s>[^\]^]+)\][^(])', re.S) + re_link2 = re.compile(r'(\[(?P<s>[^\]^]+)\][^(])', re.S) source = re_link1.sub(self._get_cross_link, source) source = re_link2.sub(self._get_cross_link, source) - source = re_link3.sub(self._get_cross_link, source) return source def _get_cross_link(self, m): ref_txt = m.group('s') - if 'l' in m.groupdict(): - header = m.group('l')[1:] - else: - header = ref_txt.lower().replace(' ', '-') for page in self.pages: for tocitem in page.toc: - if tocitem.section_id == header: - return '[%s](%s#%s)' % (ref_txt, page.htmlfile, header) + if tocitem.heading == ref_txt.replace('\n', ' '): + return '[%s](%s#%s)' % (ref_txt, + page.htmlfile, + tocitem.header_id, + ) + + return '[%s]' % ref_txt @property def title(self): @@ -136,7 +134,7 @@ class Document: toc = [page.toc[0]] for tocitem in toc: - link = '%s#%s' % (page.htmlfile, tocitem.section_id) + link = '%s#%s' % (page.htmlfile, tocitem.header_id) links.append(dict(link=unicode(link, "utf8"), text=unicode(tocitem.heading, "utf8"), level=tocitem.level, @@ -227,7 +225,7 @@ class Document: doc.add_argument('template=%s' % template_file.name) doc.add_argument('css=%s' % self.css_file) doc.markdown = '%s\n%s' % (self.header.source, - self.expand_int_links(page.source)) + self.expand_int_links(page.markdown)) content = doc.html write_file(os.path.join(pub_path, page.htmlfile), unicode(content, 'utf-8')) |
