diff options
author | Martin Vilcans <martin@librador.com> | 2011-08-24 00:14:03 +0200 |
---|---|---|
committer | Martin Vilcans <martin@librador.com> | 2011-08-24 00:14:03 +0200 |
commit | beec72fbfa4c462463d354dbc75392a47de77f74 (patch) | |
tree | e69dd45f24d178bd1c1de029d0ad8335697f2b48 | |
parent | 8cd9137097f8f6116917b71731d8ee76683119b6 (diff) | |
download | screenplain-beec72fbfa4c462463d354dbc75392a47de77f74.tar.gz |
Ignore leading spaces and trailing EOL characters on lines.
-rw-r--r-- | screenplain/parse.py | 9 |
1 files changed, 9 insertions, 0 deletions
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)) |