summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoop Kiefte <ikojba@gmail.com>2019-01-12 04:36:51 +0100
committerJoop Kiefte <ikojba@gmail.com>2019-01-12 04:36:51 +0100
commit99ebe57d73abe7448da656b9122e98f3f5b151b3 (patch)
tree091f23490eee1a527782cadd1689db1f5a57a2e2
parent5861ed4f19c32d01d80921b3a8254b20789ebb5f (diff)
Only double dialog and inline markup seem to be missing now. The latter seems to be either very hard or impossible with gofpdf, so might not be implemented ever.
-rw-r--r--fountain/parse.go57
-rw-r--r--rules/rules.go10
2 files changed, 49 insertions, 18 deletions
diff --git a/fountain/parse.go b/fountain/parse.go
index ae3ed7a..2d0b0b7 100644
--- a/fountain/parse.go
+++ b/fountain/parse.go
@@ -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.
@@ -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)
@@ -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"})
diff --git a/rules/rules.go b/rules/rules.go
index 2493e3f..acd9282 100644
--- a/rules/rules.go
+++ b/rules/rules.go
@@ -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",
+ },
}