@@ -61,11 +61,10 @@ def directive_boolean(value):
6161 raise ValueError ("No argument provided but required" )
6262 if value .lower ().strip () in ["yes" , "1" , 1 , "true" , "ok" ]:
6363 return True
64- elif value .lower ().strip () in ['no' , '0' , 0 , 'false' , 'none' ]:
64+ if value .lower ().strip () in ['no' , '0' , 0 , 'false' , 'none' ]:
6565 return False
66- else :
67- raise ValueError ("Please use on of: yes, true, no, false. "
68- "Do not use `{}` as boolean." .format (value ))
66+ raise ValueError ("Please use on of: yes, true, no, false. "
67+ "Do not use `{}` as boolean." .format (value ))
6968
7069
7170def get_image_extension (uri ):
@@ -110,7 +109,6 @@ def align(self):
110109 'width' : directives .length_or_percentage_or_unitless ,
111110 'height' : directives .length_or_unitless ,
112111 'strech' : directives .choice ,
113-
114112 'group' : directives .unchanged ,
115113 'class' : directives .class_option , # or str?
116114 'alt' : directives .unchanged ,
@@ -126,9 +124,9 @@ def run(self):
126124 env = self .state .document .settings .env
127125 conf = env .app .config .images_config
128126
129- # TODO get defaults from config
130- group = self . options . get ( 'group' ,
131- conf ['default_group' ] if conf ['default_group' ] else uuid .uuid4 ())
127+ group = self . options . get (
128+ 'group' ,
129+ conf ['default_group' ] if conf ['default_group' ] else uuid .uuid4 ())
132130 classes = self .options .get ('class' , '' )
133131 width = self .options .get ('width' , conf ['default_image_width' ])
134132 height = self .options .get ('height' , conf ['default_image_height' ])
@@ -139,12 +137,9 @@ def run(self):
139137 align = self .options .get ('align' , '' )
140138 show_caption = self .options .get ('show_caption' , False )
141139 legacy_classes = self .options .get ('legacy_class' , '' )
142-
143- # TODO get default from config
144140 download = self .options .get ('download' , conf ['download' ])
145141
146142 # parse nested content
147- # TODO: something is broken here, not parsed as expected
148143 description = nodes .paragraph ()
149144 content = nodes .paragraph ()
150145 content += [nodes .Text (f"{ x } " ) for x in self .content ]
@@ -181,6 +176,7 @@ def run(self):
181176
182177 img ['content' ] = description .astext ()
183178 img ['target' ] = target
179+ img ['source' ] = "unknown-source"
184180
185181 if title is None :
186182 img ['title' ] = ''
@@ -196,10 +192,10 @@ def run(self):
196192 img ['size' ] = (width , height )
197193 img ['width' ] = width
198194 img ['height' ] = height
199- img ['classes' ] += classes
200195 img ['alt' ] = alt
201196 img ['align' ] = align
202197 img ['download' ] = download
198+ img ['classes' ] += classes
203199 return [img ]
204200
205201 def is_remote (self , uri ):
@@ -222,9 +218,8 @@ def is_remote(self, uri):
222218 return False
223219 if '://' in uri :
224220 return True
225- raise ValueError ('Image URI `{}` has to be local relative or '
226- 'absolute path to image, or remote address.'
227- .format (uri ))
221+ raise ValueError (f'Image URI { uri !r} has to be local relative or '
222+ f'absolute path to image, or remote address.' )
228223
229224
230225def install_backend_static_files (app , env ):
@@ -282,7 +277,6 @@ def download_images(app, env):
282277 dirn = os .path .dirname (dst )
283278 ensuredir (dirn )
284279 if not os .path .isfile (dst ):
285-
286280 logger .info ('%r -> %r (downloading)' , src , dst )
287281 with open (dst , 'wb' ) as f :
288282 # TODO: apply reuqests_kwargs
@@ -333,13 +327,17 @@ def inner_wrapper(writer, node):
333327 return f (writer , node )
334328 return inner_wrapper
335329 signature = f'_{ node .__name__ } _{ output_type } '
336- return (backend_method (getattr (backend , 'visit' + signature , getattr (backend , 'visit_' + node .__name__ + '_fallback' ))),
337- backend_method (getattr (backend , 'depart' + signature , getattr (backend , 'depart_' + node .__name__ + '_fallback' ))))
330+ return (backend_method (getattr (backend , 'visit' + signature ,
331+ getattr (backend , 'visit_' + node .__name__ + '_fallback' ))),
332+ backend_method (getattr (backend , 'depart' + signature ,
333+ getattr (backend , 'depart_' + node .__name__ + '_fallback' ))))
338334
339335 # add new node to the stack
340336 # connect backend processing methods to this node
341- app .add_node (image_node , ** {output_type : backend_methods (image_node , output_type )
342- for output_type in ('html' , 'latex' , 'man' , 'texinfo' , 'text' , 'epub' )})
337+ app .add_node (
338+ image_node ,
339+ ** {output_type : backend_methods (image_node , output_type )
340+ for output_type in ('html' , 'latex' , 'man' , 'texinfo' , 'text' , 'epub' )})
343341
344342 app .add_directive ('thumbnail' , ImageDirective )
345343 if config ['override_image_directive' ]:
0 commit comments