Skip to content

Commit

Permalink
Fixed writing of forced scene headings, removed FADE IN: from Transit…
Browse files Browse the repository at this point in the history
…ion regex (should be an Action)
  • Loading branch information
nyousefi committed Feb 26, 2012
1 parent 88af0bb commit 5225e79
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Fountain/FountainRegexes.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
NSString * const CHARACTER_CUE_PATTERN = @"(?<=\\n)([ \\t]*[^<>a-z\\s\\/\\n][^<>a-z:!\\?\\n]*[^<>a-z\\(!\\?:,\\n\\.][ \\t]?)\\n{1}";
NSString * const DIALOGUE_PATTERN = @"(<(Character|Parenthetical)>[^<>\\n]+<\\/(Character|Parenthetical)>)([^<>]*?)(?=\\n{2}|\\n{1}<Parenthetical>)";
NSString * const PARENTHETICAL_PATTERN = @"(\\([^<>]*?\\)[\\s]?)\n";
NSString * const TRANSITION_PATTERN = @"\\n([\\*_]*([^<>\\na-z]*TO:|FADE IN:|FADE TO BLACK\\.|FADE OUT\\.|CUT TO BLACK\\.)[\\*_]*)\\n";
NSString * const TRANSITION_PATTERN = @"\\n([\\*_]*([^<>\\na-z]*TO:|FADE TO BLACK\\.|FADE OUT\\.|CUT TO BLACK\\.)[\\*_]*)\\n";
NSString * const FORCED_TRANSITION_PATTERN = @"\\n((&gt;|>)\\s*[^<>\\n]+)\\n"; // need to look for &gt; pattern because we run this regex against marked up content
NSString * const PAGE_BREAK_PATTERN = @"(?<=\\n)(\\s*[\\=\\-\\_]{3,8}\\s*)\\n{1}";
NSString * const CLEANUP_PATTERN = @"<Action>\\s*<\\/Action>";
Expand Down
21 changes: 17 additions & 4 deletions Fountain/FountainWriter.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,24 @@ + (NSString *)bodyFromScript:(FNScript *)script
textToWrite = [NSString stringWithFormat:@"=%@", element.elementText];
}
else if ([element.elementType isEqualToString:@"Scene Heading"]) {
if (!script.suppressSceneNumbers && element.sceneNumber) {
textToWrite = [NSString stringWithFormat:@"%@ #%@#", element.elementText, element.sceneNumber];
textToWrite = element.elementText;

/*
We need to determine if the scene heading was a forced scene
heading, and if it was, we'll add a dot to the front of the text.
This is most easily done by checking to see if the text still
matches the SCENE_HEADER_PATTERN. Because we removed the preceeding
dot when in the parser, forced scene headings won't match the
original regular expression, while non-forced (unaltered) scene
headings will.
*/
if (![[NSString stringWithFormat:@"\n%@\n", element.elementText] isMatchedByRegex:SCENE_HEADER_PATTERN]) {
textToWrite = [NSString stringWithFormat:@".%@", textToWrite];
}
else {
textToWrite = element.elementText;

// Append a scene number if needed
if (!script.suppressSceneNumbers && element.sceneNumber) {
textToWrite = [NSString stringWithFormat:@"%@ #%@#", textToWrite, element.sceneNumber];
}
}
else if ([element.elementType isEqualToString:@"Page Break"]) {
Expand Down
2 changes: 1 addition & 1 deletion FountainTests/BigFishTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ - (void)testParentheticals

- (void)testTransitions
{
NSInteger indexes[] = {2};
NSInteger indexes[] = {209};
NSInteger maxIndexes = sizeof(indexes)/sizeof(NSInteger);
for (int i=0; i < maxIndexes; i++) {
FNElement *element = [self.script.elements objectAtIndex:indexes[i]];
Expand Down
4 changes: 3 additions & 1 deletion FountainTests/Simple.fountain
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ This is in section one.

## Section 1-1

This should be at a higher depth than the previous section.
This should be at a higher depth than the previous section.

.FORCED SCENE HEADING
12 changes: 11 additions & 1 deletion FountainTests/SyntaxTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,22 @@ - (void)testSceneHeadings

- (void)testTransitions
{
NSInteger indexes[] = {0, 9};
NSInteger indexes[] = {9};
NSInteger maxIndexes = sizeof(indexes)/sizeof(NSInteger);
for (int i=0; i < maxIndexes; i++) {
FNElement *element = [self.script.elements objectAtIndex:indexes[i]];
STAssertEqualObjects(element.elementType, @"Transition", @"Index %d: [%@] %@", indexes[i], element.elementType, element.elementText);
}
}

- (void)testForcedSceneHeadings
{
NSInteger indexes[] = {18};
NSInteger maxIndexes = sizeof(indexes)/sizeof(NSInteger);
for (int i=0; i < maxIndexes; i++) {
FNElement *element = [self.script.elements objectAtIndex:indexes[i]];
STAssertEqualObjects(element.elementType, @"Scene Heading", @"Index %d: [%@] %@", indexes[i], element.elementType, element.elementText);
}
}

@end

0 comments on commit 5225e79

Please sign in to comment.