From beec72fbfa4c462463d354dbc75392a47de77f74 Mon Sep 17 00:00:00 2001 From: Martin Vilcans Date: Wed, 24 Aug 2011 00:14:03 +0200 Subject: Ignore leading spaces and trailing EOL characters on lines. --- screenplain/parse.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/screenplain/parse.py b/screenplain/parse.py index df58f68..11856c6 100644 --- a/screenplain/parse.py +++ b/screenplain/parse.py @@ -148,9 +148,18 @@ def create_paragraph(blanks_before, line_list): else: return Action(line_list) +def clean_line(line): + """Strips leading whitespace and trailing end of line characters in a string. + + Leading whitespace is insignificant in SPMD, and trailing EOL + appear when reading from a file or HTML form. + """ + return line.lstrip().rstrip('\r\n') + def parse(source): """Reads raw text input and generates paragraph objects.""" blank_count = 0 + source = (clean_line(line) for line in source) for blank, lines in itertools.groupby(source, is_blank): if blank: blank_count = len(list(lines)) -- cgit v1.2.3