Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2@file
3@brief Defines the backend for directive ``image``.
4"""
5from ..backend import Backend
8class LightBox2(Backend):
9 """
10 Backend for sphinx directive ``image``.
11 """
12 STATIC_FILES = (
13 'lightbox2/css/lightbox.css',
14 'lightbox2/js/jquery-1.11.0.min.js',
15 'lightbox2/js/lightbox.min.js',
16 'lightbox2_customize/jquery-noconflict.js',
17 'lightbox2/js/lightbox.min.map',
18 'lightbox2/img/close.png',
19 'lightbox2/img/next.png',
20 'lightbox2/img/prev.png',
21 'lightbox2/img/loading.gif',
22 )
24 def visit_image_node_html(self, writer, node):
25 "translator method"
26 # make links local (for local images only)
27 builder = self._app.builder
28 if node['uri'] in builder.images:
29 node['uri'] = '/'.join([builder.imgpath,
30 builder.images[node['uri']]])
32 if node['show_caption'] is True:
33 writer.body.append(
34 '''<figure class="{cls}">
35 '''.format(cls=' '.join(node['classes']),))
36 if node['legacy_classes']:
37 writer.body.append(
38 '''<a class="{legcls}"'''.format(legcls=' '.join(node['legacy_classes']),))
39 else:
40 writer.body.append('''<a ''')
41 else:
42 writer.body.append('''<a class="{cls}"'''.format(
43 cls=' '.join(node['classes']),))
44 if node['target']:
45 writer.body.append(' href="{0}" '.format(node['target']))
46 writer.body.append(
47 '''
48 data-lightbox="{group}"
49 href="{href}"
50 title="{title}"
51 data-title="{title}"
52 >'''.format(group='group-%s' % node['group'] if node['group'] else node['uri'],
53 href=node['uri'],
54 title=node['title'] + node['content'],
55 ))
56 writer.body.append(
57 '''<img src="{src}"
58 class="{cls}"
59 width="{width}"
60 height="{height}"
61 alt="{alt}"/>
62 '''.format(src=node['uri'],
63 cls='align-%s' % node['align'] if node['align'] else '',
64 width=node['size'][0],
65 height=node['size'][1],
66 alt=node['alt']))
67 # , title=node['title']))
69 def depart_image_node_html(self, writer, node):
70 "translator method"
71 writer.body.append('</a>')
72 if node['show_caption'] is True:
73 writer.body.append('''<figcaption>{title}</figcaption>
74 '''.format(title=node['title'],))
75 writer.body.append('</figure>')