3737TIKZ_PGF_RE = re .compile (r"\\begin\{(?:tikzpicture|pgfpicture)\}" )
3838DEFAULT_IMG_HTML_CLASS = "img-responsive"
3939
40+ # {{{ mypy
41+
42+ if False :
43+ from typing import Text , Any , Optional # noqa
44+
45+ # }}}
46+
4047
4148def tex_to_img_tag (tex_source , * args , ** kwargs ):
49+ # type: (Text, *Any, **Any) -> Optional[Text]
4250 '''Convert LaTex to IMG tag'''
4351
4452 compiler = kwargs .get ("compiler" , None )
@@ -49,8 +57,6 @@ def tex_to_img_tag(tex_source, *args, **kwargs):
4957 if not image_format :
5058 raise ValueError (_ ("'image_format' must be specified." ))
5159
52- output_dir = kwargs .get ("output_dir" )
53-
5460 tex_filename = kwargs .get ("tex_filename" , None )
5561 tex_preamble = kwargs .get ("tex_preamble" , "" )
5662 tex_preamble_extra = kwargs .get ("tex_preamble_extra" , "" )
@@ -71,12 +77,13 @@ def tex_to_img_tag(tex_source, *args, **kwargs):
7177
7278 if html_class_extra :
7379 if isinstance (html_class_extra , list ):
74- html_class_extra = " " .join (html_class_extra )
80+ html_class_extra = " " .join (html_class_extra )
7581 elif not isinstance (html_class_extra , six .string_types ):
7682 raise ValueError (
7783 _ ('"html_class_extra" must be a string or a list' ))
78- html_class = "%s %s" % (DEFAULT_IMG_HTML_CLASS , html_class_extra )
79- else : html_class = DEFAULT_IMG_HTML_CLASS
84+ html_class = "%s %s" % (DEFAULT_IMG_HTML_CLASS , html_class_extra )
85+ else :
86+ html_class = DEFAULT_IMG_HTML_CLASS
8087
8188 texdoc = TexDoc (
8289 tex_source , preamble = tex_preamble ,
@@ -88,22 +95,23 @@ def tex_to_img_tag(tex_source, *args, **kwargs):
8895
8996 if (compiler == "latex"
9097 and image_format == "png"
91- and re .search (TIKZ_PGF_RE , tex_source )):
98+ and
99+ re .search (TIKZ_PGF_RE , tex_source )):
92100 image_format = "svg"
93101
94- tex2img_class = get_tex2img_class (compiler , image_format )
102+ assert isinstance (compiler , six .text_type )
103+
104+ tex2img_class = get_tex2img_class (compiler , image_format ) # type: ignore
95105
96106 if not alt :
97107 alt = texdoc .document
98108
99109 if alt :
100- from django .utils .html import escape
101- alt = "alt='%s'" % alt .strip ().replace ("\n " ,"" )
110+ alt = "alt='%s'" % alt .strip ().replace ("\n " , "" )
102111
103112 latex2img = tex2img_class (
104113 tex_source = texdoc .as_latex (),
105114 tex_filename = tex_filename ,
106- output_dir = output_dir
107115 )
108116
109117 return (
0 commit comments