This commit is contained in:
Andrew Gerhold 2024-07-18 09:34:39 +08:00 committed by GitHub
commit b2ecd9e0aa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 2 deletions

View file

@ -39,6 +39,7 @@ type config struct {
common common
encoding string // input encoding encoding string // input encoding
expand bool // expand story passages into single files
sourcePaths []string // slice of paths to seach for source files sourcePaths []string // slice of paths to seach for source files
modulePaths []string // slice of paths to seach for module files modulePaths []string // slice of paths to seach for module files
headFile string // name of the head file headFile string // name of the head file
@ -128,6 +129,7 @@ func newConfig() *config {
options.Add("archive_twine2", "-a|--archive-twine2") options.Add("archive_twine2", "-a|--archive-twine2")
options.Add("archive_twine1", "--archive-twine1") options.Add("archive_twine1", "--archive-twine1")
options.Add("decompile_twee3", "-d|--decompile-twee3|--decompile") // NOTE: "--decompile" is deprecated. options.Add("decompile_twee3", "-d|--decompile-twee3|--decompile") // NOTE: "--decompile" is deprecated.
options.Add("expand", "--expand")
options.Add("decompile_twee1", "--decompile-twee1") options.Add("decompile_twee1", "--decompile-twee1")
options.Add("encoding", "-c=s|--charset=s") options.Add("encoding", "-c=s|--charset=s")
options.Add("format", "-f=s|--format=s") options.Add("format", "-f=s|--format=s")
@ -160,6 +162,8 @@ func newConfig() *config {
c.outMode = outModeTwee1 c.outMode = outModeTwee1
case "encoding": case "encoding":
c.encoding = val.(string) c.encoding = val.(string)
case "expand":
c.expand = true
case "format": case "format":
c.cmdline.formatID = val.(string) c.cmdline.formatID = val.(string)
c.formatID = c.cmdline.formatID c.formatID = c.cmdline.formatID

View file

@ -10,6 +10,7 @@ package main
import ( import (
"log" "log"
"regexp"
) )
const tweegoName = "tweego" const tweegoName = "tweego"
@ -70,10 +71,29 @@ func buildOutput(c *config) *story {
log.Fatalf(`error: %s`, err.Error()) log.Fatalf(`error: %s`, err.Error())
} }
case outModeTwee3, outModeTwee1: case outModeTwee3, outModeTwee1:
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. // Write out the project as Twee source.
if _, err := fileWriteAll(c.outFile, alignRecordSeparators(s.toTwee(c.outMode))); err != nil { if _, err := fileWriteAll(c.outFile, alignRecordSeparators(s.toTwee(c.outMode))); err != nil {
log.Fatalf(`error: %s`, err.Error()) log.Fatalf(`error: %s`, err.Error())
} }
}
case outModeTwine2Archive: case outModeTwine2Archive:
// Write out the project as Twine 2 archived HTML. // Write out the project as Twine 2 archived HTML.
if _, err := fileWriteAll(c.outFile, s.toTwine2Archive(c.startName)); err != nil { if _, err := fileWriteAll(c.outFile, s.toTwine2Archive(c.startName)); err != nil {