1 # This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
 
   2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
 
   4 from ..base import WLElement
 
   7 class Footnote(WLElement):
 
  12     def signal(self, signal):
 
  13         if signal == 'INLINE':
 
  14             self.START_INLINE = False
 
  16             super().signal(signal)
 
  18     def txt_build(self, builder):
 
  21     def html_build(self, builder):
 
  22         if not builder.with_footnotes:
 
  25         builder.footnote_counter += 1
 
  26         fn_no = builder.footnote_counter
 
  27         footnote_id = 'footnote-idm{}'.format(self.attrib['_compat_ordered_id'])
 
  28         anchor_id = 'anchor-idm{}'.format(self.attrib['_compat_ordered_id'])
 
  31         builder.start_element(
 
  34                 "href": '#{}'.format(footnote_id),
 
  35                 "class": "annotation-anchor",
 
  39         builder.push_text('[{}]'.format(fn_no))
 
  42         # Add actual footnote.
 
  43         builder.enter_fragment('footnotes')
 
  44         builder.start_element('div', {'class': 'fn-{}'.format(self.tag)})
 
  45         builder.push_text('\n') # Compat
 
  46         builder.start_element('a', {'name': footnote_id})
 
  48         builder.start_element('a', {
 
  49             'href': '#{}'.format(anchor_id), 'class': 'annotation'
 
  51         builder.push_text('[{}]'.format(fn_no))
 
  54         builder.start_element('p')
 
  55         super(Footnote, self).html_build(builder)
 
  57         builder.push_text(' [{}]'.format(self.qualifier))
 
  60         builder.exit_fragment()
 
  62     def epub_build(self, builder):
 
  63         fn_no = builder.assign_footnote_number()
 
  64         part_number = getattr(
 
  70         builder.start_element(
 
  74                 'id': f'anchor-{fn_no}',
 
  75                 'href': f'annotations.xhtml#annotation-{fn_no}',
 
  78         builder.start_element('sup', {})
 
  79         builder.push_text(str(fn_no))
 
  84         builder.enter_fragment('footnotes')
 
  85         builder.start_element('div', {
 
  86             'id': f'annotation-{fn_no}',
 
  89         builder.start_element('a', {
 
  90             'href': f"part{part_number}.xhtml#anchor-{fn_no}"
 
  92         builder.push_text(str(fn_no))
 
  94         builder.push_text('. ')
 
  96         super().epub_build(builder)
 
  97         builder.push_text(' [' + self.qualifier + ']')
 
 100         builder.push_text('\n')
 
 102         builder.exit_fragment()
 
 107     """Przypis autorski."""
 
 111         return _("author's footnote")
 
 115     """Przypis tłumacza."""
 
 119         return _("translator's footnote")
 
 123     """Przypis redakcyjny."""
 
 127         return _("editor's footnote")
 
 131     """Przypis redakcji źródła."""
 
 135         return _("source editor's footnote")