Skip to content

Commit

Permalink
Only double dialog and inline markup seem to be missing now. The latt…
Browse files Browse the repository at this point in the history
…er seems to be either very hard or impossible with gofpdf, so might not be implemented ever.
  • Loading branch information
LaPingvino committed Jan 12, 2019
1 parent 5861ed4 commit 99ebe57
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 18 deletions.
57 changes: 41 additions & 16 deletions fountain/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,28 @@ func CheckSection(row string) (bool, string, string) {
return section, "section", row
}

func CheckForce(row string) (bool, string, string) {
var force = true
var ftype string
if len(row) < 1 {
return false, "", ""
}
switch row[0] {
case '@':
ftype = "speaker"
case '~':
ftype = "lyrics"
case '!':
ftype = "action"
default:
force = false
}
if force {
row = row[1:]
}
return force, ftype, row
}

// This is a Fountain parser, trying to be as close as possible to the description
// found at https://fountain.io/syntax but it can be incomplete.
// Over time more and more parts should be configurable here, e.g. INT/EXT translatable to other languages.
Expand All @@ -94,22 +116,6 @@ func Parse(file io.Reader) (out lex.Screenplay) {
titlepage = false
action = "newpage"
}

// Backtracking for elements that need a following empty line
checkfuncs := []func(string) (bool, string, string){
CheckScene,
CheckCrow,
CheckEqual,
CheckSection,
}
for _, checkfunc := range checkfuncs {
check, element, contents := checkfunc(last(&out, 1).Contents)
if check && last(&out, 2).Contents == "" {
last(&out, 1).Type = element
last(&out, 1).Contents = contents
break
}
}
}
if last(&out, 1).Type != "action" {
last(&out, 1).Contents = strings.TrimSpace(last(&out, 1).Contents)
Expand All @@ -136,6 +142,25 @@ func Parse(file io.Reader) (out lex.Screenplay) {
dialog = true
}

checkfuncs := []func(string) (bool, string, string){
CheckScene, // should actually check for empty lines, but doing that creates more problems than it solves
CheckCrow,
CheckEqual,
CheckSection,
CheckForce,
}
for _, checkfunc := range checkfuncs {
check, element, contents := checkfunc(row)
if check {
action = element
row = contents
if action == "speaker" {
dialog = true
}
break
}
}

if titlepage {
if titletag == "" {
out = append(out, lex.Line{Type: "titlepage"})
Expand Down
10 changes: 8 additions & 2 deletions rules/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,17 @@ var Default = Set{
},
"meta": {
Left: 1.5,
Width: 3,
Width: 6,
},
"center": {
Left: 1.5,
Width: 3,
Width: 6,
Align: "C",
},
"lyrics": {
Left: 2,
Width: 5,
Style: "i",
Font: "Helvetica",
},
}

0 comments on commit 99ebe57

Please sign in to comment.