[New, Update] Messy commit.

* [Update] Add module paths to watch files.  From the old Bitbucket repo, submitted by `MarkSill`.
* [Fix] Trim erroneous whitespace surrounding the story title.  From the old Bitbucket repo.
* [Update, Devel, Docs] Changed import and doc paths to point to the GitHub repo and removed Mercurial references.
* [Fix] Leading whitespace on passages is trimmed as intended.
* [New, Docs] Added an option to disable passage trimming (`--no-trim`).
* [Update] Update IFID commentary and cleanup.
* [Update] Switched to another SemVer module due to a few issues with the old one.
* [Update] Purged commented legacy & debug code.
This commit is contained in:
Thomas M. Edwards 2019-12-23 14:25:57 -06:00
parent 57e1aa52ff
commit 1bb4278938
15 changed files with 123 additions and 64 deletions

View file

@ -14,10 +14,9 @@ import (
"path/filepath"
"strconv"
"strings"
"unicode"
// internal packages
twee2 "bitbucket.org/tmedwards/tweego/internal/twee2compat"
twlex "bitbucket.org/tmedwards/tweego/internal/tweelexer"
twee2 "github.com/tmedwards/tweego/internal/twee2compat"
twlex "github.com/tmedwards/tweego/internal/tweelexer"
// external packages
"golang.org/x/net/html"
)
@ -32,11 +31,11 @@ func (s *story) load(filenames []string, c *config) {
switch normalizedFileExt(filename) {
// NOTE: The case values here should match those in `filesystem.go:knownFileType()`.
case "tw", "twee":
if err := s.loadTwee(filename, c.encoding, c.twee2Compat); err != nil {
if err := s.loadTwee(filename, c.encoding, c.trim, c.twee2Compat); err != nil {
log.Fatalf("error: load %s: %s", filename, err.Error())
}
case "tw2", "twee2":
if err := s.loadTwee(filename, c.encoding, true); err != nil {
if err := s.loadTwee(filename, c.encoding, c.trim, true); err != nil {
log.Fatalf("error: load %s: %s", filename, err.Error())
}
case "htm", "html":
@ -89,7 +88,7 @@ func (s *story) load(filenames []string, c *config) {
}
}
func (s *story) loadTwee(filename, encoding string, twee2Compat bool) error {
func (s *story) loadTwee(filename, encoding string, trim, twee2Compat bool) error {
source, err := fileReadAllWithEncoding(filename, encoding)
if err != nil {
return err
@ -109,12 +108,6 @@ ParseLoop:
for {
p := &passage{}
for item, ok := lex.NextItem(); ok; item, ok = lex.NextItem() {
// switch item.Type {
// case twlex.ItemEOF, twlex.ItemHeader:
// log.Println()
// }
// log.Printf("%v\n", item)
switch item.Type {
case twlex.ItemError:
return fmt.Errorf("line %d: Malformed twee source; %s.", item.Line, item.Val)
@ -157,8 +150,13 @@ ParseLoop:
}
case twlex.ItemContent:
// p.text = string(bytes.TrimSpace(item.Val))
p.text = string(bytes.TrimRightFunc(item.Val, unicode.IsSpace))
if trim {
// Trim whitespace surrounding (leading and trailing) passages.
p.text = string(bytes.TrimSpace(item.Val))
} else {
// Do not trim whitespace surrounding passages.
p.text = string(item.Val)
}
}
lastType = item.Type