summaryrefslogtreecommitdiff
path: root/fountain/write.go
diff options
context:
space:
mode:
Diffstat (limited to 'fountain/write.go')
-rw-r--r--fountain/write.go65
1 files changed, 65 insertions, 0 deletions
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)
+ }
+ }
+}