summaryrefslogtreecommitdiff
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
parentf22108809004ea08f962cc0ad19ef1fa8051bd0c (diff)
Add fountain writer and toml configuration
-rw-r--r--fountain/parse.go3
-rw-r--r--fountain/write.go65
-rw-r--r--main.go12
-rw-r--r--rules/toml.go7
4 files changed, 80 insertions, 7 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)
+ }
+ }
+}
diff --git a/main.go b/main.go
index fa94657..6c561bc 100644
--- a/main.go
+++ b/main.go
@@ -24,8 +24,8 @@ func main() {
elements := flag.String("e", "default", "Element settings from settings file to use.")
input := flag.String("i", "-", "Input from provided filename. - means standard input.")
output := flag.String("o", "-", "Output to provided filename. - means standard output.")
- from := flag.String("from", "fountain", "Input file type. Choose from fountain, lex [, fdx]. Formats between angle brackets are planned to be supported, but are not supported by this binary.")
- to := flag.String("to", "lex", "Output file type. Choose from pdf (built-in, doesn't support inline markup), lex (helpful for troubleshooting and correcting fountain parsing), [html, epub*, mobi*, docx*, odt*, fountain, fdx]. Formats marked with a little star need an additional external tool to work. Formats between angle brackets are planned to be supported, but are not supported by this binary.")
+ from := flag.String("from", "", "Input file type. Choose from fountain, lex [, fdx]. Formats between angle brackets are planned to be supported, but are not supported by this binary.")
+ to := flag.String("to", "", "Output file type. Choose from pdf (built-in, doesn't support inline markup), lex (helpful for troubleshooting and correcting fountain parsing), fountain, [html, epub*, mobi*, docx*, odt*, fdx]. Formats marked with a little star need an additional external tool to work. Formats between angle brackets are planned to be supported, but are not supported by this binary.")
help := flag.Bool("help", false, "Show this help message")
flag.Parse()
@@ -47,6 +47,8 @@ func main() {
var outfile io.Writer
var i lex.Screenplay
+ conf := rules.GetConf(*config)
+
if *input == "-" {
infile = os.Stdin
log.Println("Reading from Stdin")
@@ -76,7 +78,7 @@ func main() {
case "lex":
i = lex.Parse(infile)
case "fountain":
- i = fountain.Parse(infile)
+ i = fountain.Parse(conf.Scenes[*scenein], infile)
default:
log.Printf("%s is not a valid input type", *from)
}
@@ -89,9 +91,11 @@ func main() {
return
}
log.Println("While the PDF output of this tool is acceptable for most purposes, I would recommend against it for sending in your screenplay. For command line usage, the Afterwriting commandline tools and e.g. the latex export of emacs fountain-mode look really good.")
- pdf.Create(*output, rules.Default, i)
+ pdf.Create(*output, conf.Elements[*elements], i)
case "lex":
lex.Write(i, outfile)
+ case "fountain":
+ fountain.Write(outfile, conf.Scenes[*sceneout], i)
default:
log.Printf("%s is not a valid output type", *to)
}
diff --git a/rules/toml.go b/rules/toml.go
index 4bb5946..ccc6479 100644
--- a/rules/toml.go
+++ b/rules/toml.go
@@ -3,6 +3,7 @@ package rules
import (
"github.com/BurntSushi/toml"
"os"
+ "log"
)
type TOMLConf struct{
@@ -18,11 +19,13 @@ func ReadFile(file string) (TOMLConf, error) {
return r, err
}
-func MustReadFile(file string) TOMLConf {
+func GetConf(file string) TOMLConf {
c, err := ReadFile(file)
if err != nil {
- panic(err)
+ log.Println("Error loading file, loading default configuration: ", err)
+ c = DefaultConf()
}
+ log.Println("Configuration set")
return c
}