mirror of
https://github.com/tmedwards/tweego.git
synced 2025-07-05 14:10:27 -04:00
Merge 93e9a79494
into a6cbd2a752
This commit is contained in:
commit
b2ecd9e0aa
2 changed files with 26 additions and 2 deletions
|
@ -39,6 +39,7 @@ type config struct {
|
|||
common
|
||||
|
||||
encoding string // input encoding
|
||||
expand bool // expand story passages into single files
|
||||
sourcePaths []string // slice of paths to seach for source files
|
||||
modulePaths []string // slice of paths to seach for module files
|
||||
headFile string // name of the head file
|
||||
|
@ -128,6 +129,7 @@ func newConfig() *config {
|
|||
options.Add("archive_twine2", "-a|--archive-twine2")
|
||||
options.Add("archive_twine1", "--archive-twine1")
|
||||
options.Add("decompile_twee3", "-d|--decompile-twee3|--decompile") // NOTE: "--decompile" is deprecated.
|
||||
options.Add("expand", "--expand")
|
||||
options.Add("decompile_twee1", "--decompile-twee1")
|
||||
options.Add("encoding", "-c=s|--charset=s")
|
||||
options.Add("format", "-f=s|--format=s")
|
||||
|
@ -160,6 +162,8 @@ func newConfig() *config {
|
|||
c.outMode = outModeTwee1
|
||||
case "encoding":
|
||||
c.encoding = val.(string)
|
||||
case "expand":
|
||||
c.expand = true
|
||||
case "format":
|
||||
c.cmdline.formatID = val.(string)
|
||||
c.formatID = c.cmdline.formatID
|
||||
|
|
24
tweego.go
24
tweego.go
|
@ -10,6 +10,7 @@ package main
|
|||
|
||||
import (
|
||||
"log"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
const tweegoName = "tweego"
|
||||
|
@ -70,10 +71,29 @@ func buildOutput(c *config) *story {
|
|||
log.Fatalf(`error: %s`, err.Error())
|
||||
}
|
||||
case outModeTwee3, outModeTwee1:
|
||||
// Write out the project as Twee source.
|
||||
if _, err := fileWriteAll(c.outFile, alignRecordSeparators(s.toTwee(c.outMode))); err != nil {
|
||||
|
||||
switch c.expand {
|
||||
case true:
|
||||
// Make a Regex to say we only want letters and numbers
|
||||
reg, err := regexp.Compile("[^a-zA-Z0-9]+")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
for _, p := range s.passages {
|
||||
processedString := reg.ReplaceAllString(p.name, "")
|
||||
if _, err := fileWriteAll(processedString, []byte(p.toTwee(c.outMode))); err != nil {
|
||||
log.Fatalf(`error: %s`, err.Error())
|
||||
}
|
||||
}
|
||||
case false:
|
||||
// Write out the project as Twee source.
|
||||
if _, err := fileWriteAll(c.outFile, alignRecordSeparators(s.toTwee(c.outMode))); err != nil {
|
||||
log.Fatalf(`error: %s`, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
case outModeTwine2Archive:
|
||||
// Write out the project as Twine 2 archived HTML.
|
||||
if _, err := fileWriteAll(c.outFile, s.toTwine2Archive(c.startName)); err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue