diff options
Diffstat (limited to 'panfry/document.py')
| -rwxr-xr-x | panfry/document.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/panfry/document.py b/panfry/document.py index 7bc65c2..edf1cf8 100755 --- a/panfry/document.py +++ b/panfry/document.py @@ -42,18 +42,23 @@ class Document: ''' re_link1 = re.compile(r'(\[(?P<s>[^\]^]+)\])\((?P<l>#.*)\)', re.S) re_link2 = re.compile(r'(\[(?P<s>[^\]^]+)\][^(])', re.S) + re_link3 = re.compile(r'(\[(?P<s>[^\]^]+)\])\[(?P<h>[^\]].*)\]', 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 'h' in m.groupdict(): + heading = m.group('h') + else: + heading = m.group('s') for page in self.pages: for tocitem in page.toc: - if tocitem.heading == ref_txt.replace('\n', ' '): - return '[%s](%s#%s)' % (ref_txt, + if tocitem.heading == heading.replace('\n', ' '): + return '[%s](%s#%s)' % (heading, page.htmlfile, tocitem.header_id, ) |
