@@ -61,21 +61,21 @@ def HasBalancedTags(s):
61
61
62
62
def ReplaceMath (cache , data ):
63
63
old = data
64
+ data = re .sub ('[\\ \\ ]\\ [([0-9]|-)' , '\\ \\ DOUBLESLASH\\ [\\ 1' , data ) # Messed up by Bikeshed
64
65
data = data .replace ('\\ \\ ' , '\\ DOUBLESLASH' )
65
66
data = data .replace ('\\ (' , '' )
66
67
data = data .replace ('\\ )' , '' )
67
68
data = data .replace ('\\ [' , '' )
68
69
data = data .replace ('\\ ]' , '' )
69
70
data = data .replace ('\\ DOUBLESLASH' , '\\ \\ ' )
70
- data = data .replace ('’' , '\\ text{’}' )
71
- data = data .replace ('‘' , '\\ text{‘}' )
72
- data = data .replace ('\\ hfill' , '' )
71
+ data = data .replace ('\u2019 ' , '\' ' ) # "Right Single Quotation Mark" messed up by Bikeshed
72
+ data = data .replace ('\\ hfill' , ' ' )
73
73
data = data .replace ('\\ mbox' , '\\ text' )
74
74
data = data .replace ('\\ begin{split}' , '\\ begin{aligned}' )
75
75
data = data .replace ('\\ end{split}' , '\\ end{aligned}' )
76
- data = data .replace ('&' , '&' )
77
- data = data .replace ('<' , '<' )
78
- data = data .replace ('>' , '>' )
76
+ data = data .replace ('&' , '&' ) # Messed up by Bikeshed
77
+ data = data .replace ('<' , '<' ) # Messed up by Bikeshed
78
+ data = data .replace ('>' , '>' ) # Messed up by Bikeshed
79
79
data = data .replace ('{array}[t]' , '{array}' )
80
80
data = data .replace ('{array}[b]' , '{array}' )
81
81
data = data .replace ('@{~}' , '' )
@@ -108,12 +108,17 @@ def ReplaceMath(cache, data):
108
108
data = data [:start ] + v .replace ('#1' , data [start + len (k ):end ]) + data [end :]
109
109
p = subprocess .Popen (
110
110
['node' , os .path .join (SCRIPT_DIR , 'katex/cli.js' ), '--display-mode' , '--trust' ],
111
- stdin = subprocess .PIPE , stdout = subprocess .PIPE , text = True )
112
- ret = p .communicate (input = data )[0 ]
113
- if p .returncode != 0 :
111
+ stdin = subprocess .PIPE , stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True )
112
+ ret , err = p .communicate (input = data )
113
+ if p .returncode != 0 or err != "" :
114
+ if err != "" :
115
+ sys .stderr .write ('\n \n ' + err + '\n ' )
114
116
sys .stderr .write ('BEFORE:\n ' + old + '\n ' )
115
117
sys .stderr .write ('AFTER:\n ' + data + '\n ' )
116
- raise Exception ()
118
+ if p .returncode != 0 :
119
+ raise Exception ()
120
+ else :
121
+ sys .stderr .write ('RESULT:\n ' + ret + '\n ' )
117
122
ret = ret .strip ()
118
123
ret = ret [ret .find ('<span class="katex-html"' ):]
119
124
ret = '<span class="katex-display"><span class="katex">' + ret
@@ -207,7 +212,7 @@ def ExtractMath(match):
207
212
# Pull out math fragments.
208
213
data = re .sub (
209
214
'class="([^"]*)math([^"]*)"[^>]*>'
210
- '((?:[ ]*<span[^>]*>[^<]*</span>)*)([^<]*)<' ,
215
+ '((?:[ \n ]*<span[^>]*>[^<]*</span>)*)([^<]*)<' ,
211
216
ExtractMath , data )
212
217
213
218
sys .stderr .write ('Processing %d fragments.\n ' % len (fixups ))
@@ -223,7 +228,8 @@ def Worker():
223
228
fixed = ('class="' + cls_before + ' ' + cls_after + '">' +
224
229
spans + ReplaceMath (cache , mth ) + '<' )
225
230
done_fixups .append ((start , end , fixed ))
226
- except Exception :
231
+ except Exception as inst :
232
+ sys .stderr .write ('\n Exception: ' + inst .__str__ () + '\n ' )
227
233
success = False
228
234
229
235
q .task_done ()
0 commit comments