Skip to content

Commit f6a810e

Browse files
committed
adds alt attribute for accessibility
1 parent daf02d4 commit f6a810e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

readme2tex/render.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@
2525
except NameError:
2626
pass
2727

28+
html_escape_dict = {
29+
'"': '"',
30+
'\n': '
',
31+
'<': '&lt;',
32+
}
33+
34+
def replace_all(text, dic):
35+
for i, j in dic.iteritems():
36+
text = text.replace(i, j)
37+
return text
2838

2939
def rendertex(engine, string, packages, temp_dir, block):
3040
if engine != 'latex': raise Exception("Not Implemented")
@@ -317,7 +327,8 @@ def render(
317327
tail.append('%x' % random.randint(0, 1e12))
318328
if needs_inversion:
319329
tail.append('invert_in_darkmode')
320-
img = '<img src="%s%s" %s width=%spt height=%spt/>' % (
330+
img = '<img alt="%s" src="%s%s" %s width="%spt" height="%spt"/>' % (
331+
replace_all(equation, html_escape_dict),
321332
url,
322333
'?%s' % ('&'.join(tail)) if tail else '',
323334
('valign=%spx'%(-off * scale) if use_valign else 'align=middle'),

0 commit comments

Comments
 (0)