diff options
author | Joop Kiefte <ikojba@gmail.com> | 2019-01-12 05:03:06 +0100 |
---|---|---|
committer | Joop Kiefte <ikojba@gmail.com> | 2019-01-12 05:03:06 +0100 |
commit | a6318ee25fac188de4ffb2d568c0a73d242207df (patch) | |
tree | dc420521db16cd7b1b3a64c1f48989ea380d8755 | |
parent | 99ebe57d73abe7448da656b9122e98f3f5b151b3 (diff) |
Gofmt and improving front page support
-rw-r--r-- | fountain/parse.go | 41 | ||||
-rw-r--r-- | main.go | 2 | ||||
-rw-r--r-- | pdf/create.go | 11 | ||||
-rw-r--r-- | rules/rules.go | 22 |
4 files changed, 42 insertions, 34 deletions
diff --git a/fountain/parse.go b/fountain/parse.go index 2d0b0b7..abc3164 100644 --- a/fountain/parse.go +++ b/fountain/parse.go @@ -142,24 +142,24 @@ 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 + 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 == "" { @@ -167,21 +167,20 @@ func Parse(file io.Reader) (out lex.Screenplay) { } split := strings.SplitN(row, ":", 2) if len(split) == 2 { - action = strings.ToLower(split[0]) - switch action { + action = split[0] + switch strings.ToLower(action) { case "title", "credit", "author", "authors": - action = "title" + titletag = "title" default: if titletag == "title" { out = append(out, lex.Line{Type: "metasection"}) } - action = "meta" + titletag = action } row = strings.TrimSpace(split[1]) if row == "" { continue } - titletag = action } else { action = titletag row = strings.TrimSpace(row) @@ -1,7 +1,7 @@ // Lexington is a command line tool to convert between several formats used for screenwriting. // When you write a screenplay in Fountain, you can use this tool to convert it into other formats. // The tool uses an internal format called lex which can be used to tweak the output. -// Run the compiled tool with --help to get information about usage. +// Run the compiled tool with --help to get information about usage. package main import ( diff --git a/pdf/create.go b/pdf/create.go index 52c3122..f4346a1 100644 --- a/pdf/create.go +++ b/pdf/create.go @@ -16,23 +16,30 @@ type Tree struct { } func (t Tree) pr(a string, text string) { - line(t.PDF, t.Rules.Get(a), text) + line(t.PDF, t.Rules.Get(a), t.Rules.Get(a).Prefix+text+t.Rules.Get(a).Postfix) } func (t Tree) Render() { + var block string for _, row := range t.F { switch row.Type { case "newpage": + block = "" t.PDF.AddPage() continue case "titlepage": + block = "title" t.PDF.SetY(4) case "metasection": + block = "meta" t.PDF.SetY(-2) } - if t.Rules.Get(row.Type).Hide { + if t.Rules.Get(row.Type).Hide && block == "" { continue } + if block != "" { + row.Type = block + } t.pr(row.Type, row.Contents) } } diff --git a/rules/rules.go b/rules/rules.go index acd9282..7537e36 100644 --- a/rules/rules.go +++ b/rules/rules.go @@ -1,13 +1,15 @@ package rules type Format struct { - Width float64 - Left float64 - Font string - Style string - Size float64 - Hide bool - Align string + Width float64 + Left float64 + Font string + Style string + Size float64 + Hide bool + Align string + Prefix string + Postfix string } type Set map[string]Format @@ -79,14 +81,14 @@ var Default = Set{ Width: 6, }, "center": { - Left: 1.5, + Left: 1.5, Width: 6, Align: "C", }, "lyrics": { - Left: 2, + Left: 2, Width: 5, Style: "i", - Font: "Helvetica", + Font: "Helvetica", }, } |