From 084eb29d426688617b6e19846f508b6d1cb3a564 Mon Sep 17 00:00:00 2001 From: Thibault Kruse Date: Sat, 10 Sep 2016 09:16:57 +0900 Subject: [PATCH] minor improvement, strip newlines from end of code snippets --- scripts/python/md-split.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/scripts/python/md-split.py b/scripts/python/md-split.py index e06fe85..9a855fc 100755 --- a/scripts/python/md-split.py +++ b/scripts/python/md-split.py @@ -117,10 +117,24 @@ def process_code(read_filehandle, text_filehandle, line, linenum, sourcefile, co text_filehandle.write('\n') if (has_actual_code and not has_question_marks): + linebuffer = clean_trailing_newlines(linebuffer) write_with_harness(codefile, sourcefile, start_linenum, linebuffer) return (line, linenum) +def clean_trailing_newlines(linebuffer): + result = [] + code_started = False + linebuffer.reverse() + for line in linebuffer: + if not code_started and line == '\n': + continue + code_started = True + result.append(line) + result.reverse() + return result + + def write_with_harness(codefile, sourcefile, start_linenum, linebuffer): '''write output with additional lines to make code likely compilable''' # add commonly used headers, so that lines can likely compile.