# HG changeset patch
# User William Stein <wstein@gmail.com>
# Date 1210492170 25200
# Node ID 64bab8c54fd187e3860c10ba5629f6b3235cba98
# Parent 19807feec3063d1c6193d858d64ad877611d033b
trac #2860  easytofix bug in html.py
Nobody has a test case to reproduce the claimed problem. So I read
the code, vastly improved its documentation, and did make a change that
logically must fix exactly the reported bug.
diff r 19807feec306 r 64bab8c54fd1 sage/misc/html.py
a

b

from sage.misc.sage_eval import sage_eva 
13  13  
14  14  def math_parse(s): 
15  15  r""" 
 16  Turn the HTMLish string s that can have $$ and $'s in it into 
 17  pure HTML. See below for a precise definition of what this means. 
 18  
 19  INPUT: 
 20  s  a string 
 21  OUTPUT: 
 22  a string. 
 23  
16  24  Do the following: 
17  25  \begin{verbatim} 
18  26  * Replace all $ text $'s by 
… 
… 
def math_parse(s): 
23  31  the above two cases nothing is done if the $ 
24  32  is preceeded by a backslash. 
25  33  \end{verbatim} 
 34  
 35  EXAMPLES: 
 36  sage: sage.misc.html.math_parse('This is $2+2$.') 
 37  'This is <span class="math">2+2</span>.' 
 38  sage: sage.misc.html.math_parse('This is $$2+2$$.') 
 39  'This is <div class="math">2+2</div>.' 
 40  
 41  TESTS: 
 42  sage: sage.misc.html.math_parse(r'This \$\$is $2+2$.') 
 43  'This $$is <span class="math">2+2</span>.' 
26  44  """ 
 45  # Below t always has the "parsed so far" version of s, and s is 
 46  # just the part of the original input s that hasn't been parsed. 
27  47  t = '' 
28  48  while True: 
29  49  i = s.find('$') 
30  50  if i == 1: 
 51  # No dollar signs  definitely done. 
31  52  return t + s 
32  53  elif i > 0 and s[i1] == '\\': 
 54  # A dollar sign with a backslash right before it, so 
 55  # we ignore it by sticking it in the parsed string t 
 56  # and skip to the next iteration. 
33  57  t += s[:i1] + '$' 
34  58  s = s[i+1:] 
 59  continue 
35  60  elif i+1 < len(s) and s[i+1] == '$': 
 61  # Found a math environment. Double dollar sign so div mode. 
36  62  typ = 'div' 
37  63  else: 
 64  # Found math environment. Single dollar sign so span mode. 
38  65  typ = 'span' 
 66  
 67  # Now find the matching $ sign and form the span or div. 
39  68  j = s[i+2:].find('$') 
40  69  if j == 1: 
41  70  j = len(s) 