summaryrefslogtreecommitdiff
path: root/fountain
diff options
context:
space:
mode:
authorJoop Kiefte <ikojba@gmail.com>2019-01-12 22:24:45 +0100
committerJoop Kiefte <ikojba@gmail.com>2019-01-12 22:24:45 +0100
commit7813670abf4ec55f819e0c26c2300a274672bf08 (patch)
tree92665b255dd4d4c74c5d32368652448aea1fb25b /fountain
parentf22108809004ea08f962cc0ad19ef1fa8051bd0c (diff)
Add fountain writer and toml configuration
Diffstat (limited to 'fountain')
-rw-r--r--fountain/parse.go3
-rw-r--r--fountain/write.go65
2 files changed, 67 insertions, 1 deletions
diff --git a/fountain/parse.go b/fountain/parse.go
index d2dfeea..a01b97f 100644
--- a/fountain/parse.go
+++ b/fountain/parse.go
@@ -96,7 +96,8 @@ func CheckForce(row string) (bool, string, string) {
// 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.
-func Parse(file io.Reader) (out lex.Screenplay) {
+func Parse(scenes []string, file io.Reader) (out lex.Screenplay) {
+ Scene = scenes
var err error
var titlepage, dialog bool = true, false
var s, titletag string
diff --git a/fountain/write.go b/fountain/write.go
new file mode 100644
index 0000000..25eb41b
--- /dev/null
+++ b/fountain/write.go
@@ -0,0 +1,65 @@
+package fountain
+
+import (
+ "github.com/lapingvino/lexington/lex"
+ "io"
+ "fmt"
+ "strings"
+)
+
+func Write(f io.Writer, scene []string, screenplay lex.Screenplay) {
+ var titlepage = "start"
+ for _, line := range screenplay {
+ element := line.Type
+ if titlepage == "start" && line.Type != "titlepage" {
+ titlepage = ""
+ }
+ if titlepage != "" {
+ element = titlepage
+ }
+ switch element {
+ case "start":
+ titlepage = "titlepage"
+ case "titlepage":
+ if line.Type == "metasection" {
+ continue
+ }
+ if line.Type == "newpage" {
+ fmt.Fprintln(f, "")
+ titlepage = ""
+ continue
+ }
+ fmt.Fprintf(f, "%s: %s\n", line.Type, line.Contents)
+ case "newpage":
+ fmt.Fprintln(f, "===")
+ case "empty":
+ fmt.Fprintln(f, "")
+ case "speaker":
+ if line.Contents != strings.ToUpper(line.Contents) {
+ fmt.Fprint(f, "@")
+ }
+ fmt.Fprintln(f, line.Contents)
+ case "scene":
+ var supported bool
+ for _, prefix := range scene {
+ if strings.HasPrefix(line.Contents, prefix+" ") ||
+ strings.HasPrefix(line.Contents, prefix+".") {
+ supported = true
+ }
+ }
+ if !supported {
+ fmt.Fprint(f, ".")
+ }
+ fmt.Fprintln(f, line.Contents)
+ case "lyrics":
+ fmt.Fprintf(f, "~%s\n", line.Contents)
+ case "action":
+ if line.Contents == strings.ToUpper(line.Contents) {
+ fmt.Fprint(f, "!")
+ }
+ fmt.Fprintln(f, line.Contents)
+ default:
+ fmt.Fprintln(f, line.Contents)
+ }
+ }
+}