File tree Expand file tree Collapse file tree 1 file changed +19
-12
lines changed
Expand file tree Collapse file tree 1 file changed +19
-12
lines changed Original file line number Diff line number Diff line change 22import re
33
44def filter_text (content ):
5+ content = content .replace (r'\implies' , r'\Longrightarrow' )
6+
57 pattern = re .compile (
6- r'(```[\s\S]*?```|`[^`\n]*?`)'
8+ r'(```[\s\S]*?```)'
9+ r'|(`[^`\n]*?`)'
710 r'|(\$\$[\s\S]*?\$\$)'
811 r'|((?<!\$)\$(?!\$)[^\n$]+?(?<!\$)\$(?!\$))'
912 r'|(\\\|)' ,
1013 re .MULTILINE
1114 )
1215
1316 def replacer (match ):
14- g_code = match .group (1 )
15- g_block_math = match .group (2 )
16- g_inline_math = match .group (3 )
17- g_escaped_pipe = match .group (4 )
17+ g_block_code = match .group (1 )
18+ g_inline_code = match .group (2 )
19+ g_block_math = match .group (3 )
20+ g_inline_math = match .group (4 )
21+ g_escaped_pipe = match .group (5 )
1822
19- if g_code :
20- return g_code
21-
22- elif g_block_math :
23+ if g_block_code :
24+ return g_block_code
25+
26+ if g_inline_code :
27+ return g_inline_code .replace (r'\|' , '|' )
28+
29+ if g_block_math :
2330 inner = g_block_math [2 :- 2 ]
2431 return f"\\ f[{ inner } \\ f]"
2532
26- elif g_inline_math :
33+ if g_inline_math :
2734 inner = g_inline_math [1 :- 1 ]
2835 return f"\\ f${ inner } \\ f$"
2936
30- elif g_escaped_pipe :
37+ if g_escaped_pipe :
3138 return "|"
3239
3340 return match .group (0 )
@@ -40,7 +47,7 @@ def replacer(match):
4047
4148 filename = sys .argv [1 ]
4249 try :
43- with open (filename , 'r' , encoding = 'utf-8' ) as f :
50+ with open (filename , 'r' , encoding = 'utf-8' , errors = 'ignore' ) as f :
4451 print (filter_text (f .read ()))
4552 except Exception as e :
4653 sys .stderr .write (str (e ))
You can’t perform that action at this time.
0 commit comments