1- # -*- coding: utf-8 -*-
21"""
32 sphinx-mermaid
43 ~~~~~~~~~~~~~~~
@@ -88,7 +87,7 @@ def get_mm_code(self):
8887 try :
8988 with codecs .open (filename , 'r' , 'utf-8' ) as fp :
9089 mmcode = fp .read ()
91- except ( IOError , OSError ) :
90+ except OSError :
9291 return [document .reporter .warning (
9392 'External Mermaid file %r not found or reading '
9493 'it failed' % filename , line = self .lineno )]
@@ -151,8 +150,8 @@ def render_mm(self, code, options, _fmt, prefix='mermaid'):
151150 mermaid_cmd_shell = self .builder .config .mermaid_cmd_shell in {True , 'True' , 'true' }
152151 hashkey = (code + str (options ) + str (self .builder .config .mermaid_sequence_config )).encode ('utf-8' )
153152
154- basename = '%s-%s' % ( prefix , sha1 (hashkey ).hexdigest ())
155- fname = '%s.%s' % ( basename , _fmt )
153+ basename = f' { prefix } - { sha1 (hashkey ).hexdigest ()} '
154+ fname = f' { basename } . { _fmt } '
156155 relfn = posixpath .join (self .builder .imgpath , fname )
157156 outdir = os .path .join (self .builder .outdir , self .builder .imagedir )
158157 outfn = os .path .join (outdir , fname )
@@ -222,26 +221,26 @@ def render_mm_html(self, node, code, options, prefix='mermaid',
222221
223222 fname , outfn = render_mm (self , code , options , _fmt , prefix )
224223 except MermaidError as exc :
225- logger .warning ('mermaid code %r : ' % code + str (exc ))
224+ logger .warning (f 'mermaid code { code !r } : ' + str (exc ))
226225 raise nodes .SkipNode
227226
228227 if fname is None :
229228 self .body .append (self .encode (code ))
230229 else :
231230 if alt is None :
232231 alt = node .get ('alt' , self .encode (code ).strip ())
233- imgcss = imgcls and 'class="%s"' % imgcls or ''
232+ imgcss = imgcls and f 'class="{ imgcls } "' or ''
234233 if _fmt == 'svg' :
235- svgtag = '''<object data="%s" type="image/svg+xml">
236- <p class="warning">%s</p></object>\n ''' % (fname , alt )
234+ svgtag = f'''<object data="{ fname } " type="image/svg+xml">
235+ <p class="warning">{ alt } </p></object>
236+ '''
237237 self .body .append (svgtag )
238238 else :
239239 if 'align' in node :
240240 self .body .append ('<div align="%s" class="align-%s">' %
241241 (node ['align' ], node ['align' ]))
242242
243- self .body .append ('<img src="%s" alt="%s" %s/>\n ' %
244- (fname , alt , imgcss ))
243+ self .body .append (f'<img src="{ fname } " alt="{ alt } " { imgcss } />\n ' )
245244 if 'align' in node :
246245 self .body .append ('</div>\n ' )
247246
@@ -256,7 +255,7 @@ def render_mm_latex(self, node, code, options, prefix='mermaid'):
256255 try :
257256 fname , outfn = render_mm (self , code , options , 'pdf' , prefix )
258257 except MermaidError as exc :
259- logger .warning ('mm code %r : ' % code + str (exc ))
258+ logger .warning (f 'mm code { code !r } : ' + str (exc ))
260259 raise nodes .SkipNode
261260
262261 if self .builder .config .mermaid_pdfcrop != '' :
@@ -266,7 +265,7 @@ def render_mm_latex(self, node, code, options, prefix='mermaid'):
266265 except OSError as err :
267266 if err .errno != ENOENT : # No such file or directory
268267 raise
269- logger .warning ('command %r cannot be run (needed to crop pdf), check the mermaid_cmd setting' % self . builder . config . mermaid_pdfcrop )
268+ logger .warning (f 'command { self . builder . config . mermaid_pdfcrop !r } cannot be run (needed to crop pdf), check the mermaid_cmd setting' )
270269 return None , None
271270
272271 stdout , stderr = p .communicate ()
@@ -313,7 +312,7 @@ def render_mm_texinfo(self, node, code, options, prefix='mermaid'):
313312 try :
314313 fname , outfn = render_mm (self , code , options , 'png' , prefix )
315314 except MermaidError as exc :
316- logger .warning ('mm code %r : ' % code + str (exc ))
315+ logger .warning (f 'mm code { code !r } : ' + str (exc ))
317316 raise nodes .SkipNode
318317 if fname is not None :
319318 self .body .append ('@image{%s,,,[mermaid],png}\n ' % fname [:- 4 ])
0 commit comments