Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aefc816

Browse files
committed
Remove leading/trailing blank newlines on save.
1 parent 73f91ba commit aefc816

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

run.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,12 @@ def save_code(code, leaf, language, mode, newline=True):
881881
code_path = os.path.join(code_folder, filename.replace("-", "_"))
882882
else:
883883
raise Exception("mode: 'execution' | 'documentation' | 'exception'")
884+
code_lines = code.splitlines()
885+
while not code_lines[0]:
886+
code_lines.pop(0)
887+
while not code_lines[-1]:
888+
code_lines.pop()
889+
code = '\n'.join(code_lines)
884890
if not os.path.exists(code_folder):
885891
os.makedirs(code_folder)
886892
with open(code_path, 'w') as f:

0 commit comments

Comments
 (0)