aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--screenplain/parsers/fountain.py20
-rw-r--r--tests/fountain_test.py17
2 files changed, 28 insertions, 9 deletions
diff --git a/screenplain/parsers/fountain.py b/screenplain/parsers/fountain.py
index 698ede1..986d092 100644
--- a/screenplain/parsers/fountain.py
+++ b/screenplain/parsers/fountain.py
@@ -55,7 +55,7 @@ class InputParagraph(object):
"""
previous_paragraphs.append(
self.as_synopsis(previous_paragraphs) or
- self.as_section() or
+ self.as_section(previous_paragraphs) or
self.as_slug() or
self.as_centered_action() or
self.as_dialog(previous_paragraphs) or
@@ -83,16 +83,18 @@ class InputParagraph(object):
else:
return Slug(_to_rich(text))
- def as_section(self):
- if len(self.lines) != 1:
- return None
+ def as_section(self, previous_paragraphs):
+ sections = []
- match = section_re.match(self.lines[0])
- if not match:
- return None
+ for line in self.lines:
+ match = section_re.match(line)
+ if not match:
+ return None
+ hashes, text = match.groups()
+ sections.append(Section(_to_rich(text), len(hashes)))
- hashes, text = match.groups()
- return Section(_to_rich(text), len(hashes))
+ previous_paragraphs += sections[:-1]
+ return sections[-1]
def as_centered_action(self):
if not all(centered_re.match(line) for line in self.lines):
diff --git a/tests/fountain_test.py b/tests/fountain_test.py
index 5b1d386..69426db 100644
--- a/tests/fountain_test.py
+++ b/tests/fountain_test.py
@@ -96,6 +96,23 @@ class SectionTests(unittest2.TestCase):
self.assertEquals(2, paras[1].level)
self.assertEquals(plain('second level'), paras[1].text)
+ def test_multiple_sections_in_one_paragraph(self):
+ paras = parse([
+ '# first level',
+ '## second level',
+ '# first level again'
+ ])
+ self.assertEquals(
+ [Section, Section, Section],
+ [type(p) for p in paras]
+ )
+ self.assertEquals(1, paras[0].level)
+ self.assertEquals(plain('first level'), paras[0].text)
+ self.assertEquals(2, paras[1].level)
+ self.assertEquals(plain('second level'), paras[1].text)
+ self.assertEquals(1, paras[2].level)
+ self.assertEquals(plain('first level again'), paras[2].text)
+
class DialogTests(unittest2.TestCase):
# A Character element is any line entirely in caps, with one empty