11import re
2- import time
32
43
54def render_message (interpreter , message ):
@@ -13,31 +12,19 @@ def render_message(interpreter, message):
1312 # Split the message into parts by {{ and }}, including multi-line strings
1413 parts = re .split (r"({{.*?}})" , message , flags = re .DOTALL )
1514
16- for i in range (len (parts )):
17- part = parts [i ]
15+ for i , part in enumerate (parts ):
1816 # If the part is enclosed in {{ and }}
1917 if part .startswith ("{{" ) and part .endswith ("}}" ):
2018 # Run the code inside the brackets
2119 output = interpreter .computer .run (
2220 "python" , part [2 :- 2 ].strip (), display = interpreter .verbose
2321 )
2422
25- # Turn it into just a simple string
26- outputs = []
27- for line in output :
28- if interpreter .debug :
29- print (line )
30- if line .get ("format" ) == "output" :
31- if "IGNORE_ALL_ABOVE_THIS_LINE" in line ["content" ]:
32- outputs .append (
33- line ["content" ].split ("IGNORE_ALL_ABOVE_THIS_LINE" )[1 ]
34- )
35- else :
36- outputs .append (line ["content" ])
37- output = "\n " .join (outputs )
23+ # Extract the output content
24+ outputs = (line ["content" ] for line in output if line .get ("format" ) == "output" and "IGNORE_ALL_ABOVE_THIS_LINE" not in line ["content" ])
3825
3926 # Replace the part with the output
40- parts [i ] = output
27+ parts [i ] = " \n " . join ( outputs )
4128
4229 # Join the parts back into the message
4330 rendered_message = "" .join (parts ).strip ()
0 commit comments