X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/d04e61819290fc8d6d71b1932c55a774014c1f05..db91f942ce46e3af1420f3469a83257ef5aca4c2:/src/librarian/elements/footnotes/__init__.py diff --git a/src/librarian/elements/footnotes/__init__.py b/src/librarian/elements/footnotes/__init__.py index 82f6497..433e881 100644 --- a/src/librarian/elements/footnotes/__init__.py +++ b/src/librarian/elements/footnotes/__init__.py @@ -1,3 +1,6 @@ +# -*- coding: utf-8 +from __future__ import unicode_literals + from ..base import WLElement @@ -6,15 +9,27 @@ class Footnote(WLElement): pass def html_build(self, builder): + if not builder.with_footnotes: + return + builder.footnote_counter += 1 fn_no = builder.footnote_counter footnote_id = 'footnote-idm{}'.format(self.attrib['_compat_ordered_id']) anchor_id = 'anchor-idm{}'.format(self.attrib['_compat_ordered_id']) - builder.start_element('a', {"href": '#{}'.format(footnote_id), "class": "annotation"}) + # Add anchor. + builder.start_element( + 'a', + { + "href": '#{}'.format(footnote_id), + "class": "annotation-anchor", + "id": anchor_id, + } + ) builder.push_text('[{}]'.format(fn_no)) builder.end_element() + # Add actual footnote. builder.enter_fragment('footnotes') builder.start_element('div', {'class': 'fn-{}'.format(self.tag)}) builder.push_text('\n') # Compat @@ -34,6 +49,49 @@ class Footnote(WLElement): builder.end_element() builder.exit_fragment() + def epub_build(self, builder): + fn_no = builder.assign_footnote_number() + part_number = getattr( + builder, + 'chunk_counter', + 1 + ) + + builder.start_element( + 'a', + { + 'class': 'anchor', + 'id': f'anchor-{fn_no}', + 'href': f'annotations.xhtml#annotation-{fn_no}', + } + ) + builder.start_element('sup', {}) + builder.push_text(str(fn_no)) + builder.end_element() + builder.end_element() + + + builder.enter_fragment('footnotes') + builder.start_element('p', { + 'id': f'annotation-{fn_no}', + 'class': "annotation" + }) + builder.start_element('a', { + 'href': f"part{part_number}.xhtml#anchor-{fn_no}" + }) + builder.push_text(str(fn_no)) + builder.end_element() + builder.push_text('. ') + + super().epub_build(builder) + builder.push_text(' [' + self.qualifier + ']') + builder.end_element() + + builder.push_text('\n') + + builder.exit_fragment() + + class PA(Footnote): """Przypis autorski."""