aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Vilcans <martin@librador.com>2011-08-24 00:14:03 +0200
committerMartin Vilcans <martin@librador.com>2011-08-24 00:14:03 +0200
commitbeec72fbfa4c462463d354dbc75392a47de77f74 (patch)
treee69dd45f24d178bd1c1de029d0ad8335697f2b48
parent8cd9137097f8f6116917b71731d8ee76683119b6 (diff)
downloadscreenplain-beec72fbfa4c462463d354dbc75392a47de77f74.tar.gz
Ignore leading spaces and trailing EOL characters on lines.
-rw-r--r--screenplain/parse.py9
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))