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):
 
   9     DISABLE_NUMBERING = True
 
  14     def signal(self, signal):
 
  15         if signal == 'INLINE':
 
  16             self.START_INLINE = False
 
  18             super().signal(signal)
 
  20     def txt_build(self, builder):
 
  23     def html_build(self, builder):
 
  24         if not builder.with_footnotes:
 
  27         fn_no = self.attrib.get('_visible_numbering')
 
  28         footnote_id = 'footnote-id{}'.format(fn_no)
 
  29         anchor_id = 'anchor-id{}'.format(fn_no)
 
  32         builder.start_element(
 
  35                 "href": '#{}'.format(footnote_id),
 
  36                 "class": "annotation-anchor",
 
  40         builder.push_text('[{}]'.format(fn_no))
 
  43         # Add actual footnote.
 
  44         builder.enter_fragment('footnotes')
 
  45         builder.start_element('div', {'class': 'fn-{}'.format(self.tag)})
 
  46         builder.push_text('\n') # Compat
 
  47         builder.start_element('a', {'name': footnote_id})
 
  49         builder.start_element('a', {
 
  50             'href': '#{}'.format(anchor_id), 'class': 'annotation'
 
  52         builder.push_text('[{}]'.format(fn_no))
 
  55         builder.start_element('p')
 
  56         super(Footnote, self).html_build(builder)
 
  58         builder.push_text(' [{}]'.format(self.qualifier))
 
  61         builder.exit_fragment()
 
  63     def epub_build(self, builder):
 
  64         fn_no = builder.assign_footnote_number()
 
  65         part_number = getattr(
 
  71         builder.start_element(
 
  75                 'id': f'anchor-{fn_no}',
 
  76                 'href': f'annotations.xhtml#annotation-{fn_no}',
 
  79         builder.start_element('sup', {})
 
  80         builder.push_text(str(fn_no))
 
  85         builder.enter_fragment('footnotes')
 
  86         builder.start_element('div', {
 
  87             'id': f'annotation-{fn_no}',
 
  90         builder.start_element('a', {
 
  91             'href': f"part{part_number}.xhtml#anchor-{fn_no}"
 
  93         builder.push_text(str(fn_no))
 
  95         builder.push_text('. ')
 
  97         super().epub_build(builder)
 
  98         builder.push_text(' [' + self.qualifier + ']')
 
 101         builder.push_text('\n')
 
 103         builder.exit_fragment()
 
 108     """Przypis autorski."""
 
 112         return _("author's footnote")
 
 116     """Przypis tłumacza."""
 
 120         return _("translator's footnote")
 
 124     """Przypis redakcyjny."""
 
 128         return _("editor's footnote")
 
 132     """Przypis redakcji źródła."""
 
 136         return _("source editor's footnote")