Skip to content

Commit ba2c81e

Browse files
committed
properly escape quotes
1 parent f6a810e commit ba2c81e

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

readme2tex/render.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import tempfile
88
import xml.etree.ElementTree as ET
99
from subprocess import check_output
10+
from xml.sax.saxutils import quoteattr
1011
import logging
1112

1213
envelope = r'''%% processed with readme2tex
@@ -25,17 +26,6 @@
2526
except NameError:
2627
pass
2728

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
38-
3929
def rendertex(engine, string, packages, temp_dir, block):
4030
if engine != 'latex': raise Exception("Not Implemented")
4131
source = envelope % ('\n'.join(r'\usepackage{%s}' % ''.join(package) for package in packages), 'a' if not block else '', string)
@@ -327,8 +317,8 @@ def render(
327317
tail.append('%x' % random.randint(0, 1e12))
328318
if needs_inversion:
329319
tail.append('invert_in_darkmode')
330-
img = '<img alt="%s" src="%s%s" %s width="%spt" height="%spt"/>' % (
331-
replace_all(equation, html_escape_dict),
320+
img = '<img alt=%s src="%s%s" %s width="%spt" height="%spt"/>' % (
321+
quoteattr(equation),
332322
url,
333323
'?%s' % ('&'.join(tail)) if tail else '',
334324
('valign=%spx'%(-off * scale) if use_valign else 'align=middle'),

0 commit comments

Comments
 (0)