diff --git a/screenplain/parsers/fountain.py b/screenplain/parsers/fountain.py index 587eadc..d004d48 100644 --- a/screenplain/parsers/fountain.py +++ b/screenplain/parsers/fountain.py @@ -27,8 +27,10 @@ title_page_key_re = re.compile(r'([^:]+):\s*(.*)') title_page_value_re = re.compile(r'(?:\s{3,}|\t)(.+)') +character_re = re.compile( + r"^[^a-z]*[A-Z][^a-z]*([ \t]*\(.*\))?$" +) centered_re = re.compile(r'\s*>\s*(.*?)\s*<\s*$') -dual_dialog_re = re.compile(r'^(.+?)(\s*\^)$') slug_re = re.compile(r'(?:(\.)(?=[^.])\s*)?(\S.*?)\s*$') scene_number_re = re.compile(r'(.*?)\s*(?:#([\w\-.]+)#)\s*$') section_re = re.compile(r'^(#{1,6})\s*([^#].*)$') @@ -134,14 +136,15 @@ def append_dialog(self, paragraphs): return False if character.startswith('@') and len(character) >= 2: character = character[1:] - elif not character.isupper(): + elif not character_re.match(character): return False if paragraphs and isinstance(paragraphs[-1], Dialog): - dual_match = dual_dialog_re.match(character) + dual_match = character.rstrip().endswith('^') if dual_match: + character = character.rstrip()[:-1] # remove the caret previous = paragraphs.pop() - dialog = self._create_dialog(dual_match.group(1)) + dialog = self._create_dialog(character) paragraphs.append(DualDialog(previous, dialog)) return True diff --git a/tests/files/dialogue-parentheticals.fountain b/tests/files/dialogue-parentheticals.fountain new file mode 100644 index 0000000..54fa5c3 --- /dev/null +++ b/tests/files/dialogue-parentheticals.fountain @@ -0,0 +1,5 @@ +GIRL +Let me tell you something. + + GUY (On the phone) + I don't wanna. diff --git a/tests/files/dialogue-parentheticals.fountain.html b/tests/files/dialogue-parentheticals.fountain.html new file mode 100644 index 0000000..1d50f65 --- /dev/null +++ b/tests/files/dialogue-parentheticals.fountain.html @@ -0,0 +1,2 @@ +
GIRL
Let me tell you something.
GUY (On the phone)
I don't wanna.