summaryrefslogtreecommitdiff
path: root/ref.go
diff options
context:
space:
mode:
authorkaa <kaa@disroot.org>2023-12-07 11:01:44 -0800
committerkaa <kaa@disroot.org>2023-12-07 11:01:44 -0800
commite56eb9d1b5f5ba1b3cb8025d5e0350654765592a (patch)
tree1e8f2c290ece0886e419d4b9bf35ca97c742a1d5 /ref.go
parent6f5f6ea6fddaff6e63f9bb9bcd3f607894c3afe0 (diff)
Added configurability. Some documentation other than code in an error message.
Diffstat (limited to 'ref.go')
-rw-r--r--ref.go53
1 files changed, 45 insertions, 8 deletions
diff --git a/ref.go b/ref.go
index ba30c79..7d62f3b 100644
--- a/ref.go
+++ b/ref.go
@@ -14,20 +14,37 @@ const (
prefix = `.\"s `
end = `.\"e`
section = `.\"§`
- tableHead = ".TS\nexpand;\nl1w(1.5i) l1w(4.5i)."
- tableFoot = ".TE"
+ //tableHead = ".TS\nexpand;\nl1w(1.5i) l1w(4.5i)."
+ //tableFoot = ".TE"
mac = ".ref"
- delim = "()"
- extraPrefix = `\fC`
- extraSuffix = `\fP`
+ //delim = "()"
)
+var tableHead, tableFoot, delim, extraPrefix, extraSuffix string
+
type Reference struct {
name string
contents string
index int
}
+func interpEscape(str string) string {
+ var rt string
+ for i := 0; i < len(str); i++ {
+ if str[i] == '\\' {
+ i++
+ if str[i] == 'n' {
+ rt += "\n"
+ } else {
+ rt += "\\n"
+ }
+ } else {
+ rt += string(str[i])
+ }
+ }
+ return rt + "\n"
+}
+
func getRefTxt(lines []string) string {
var txt string
for _, line := range lines {
@@ -101,8 +118,28 @@ func main() {
div := -1
lines := strings.Split(contents, "\n")
for i, line := range lines {
- if line == section {
+ if strings.HasPrefix(line, section) {
div = i
+ words := strings.Split(line, "#")
+ wc := len(words)
+ if wc < 4 {
+ log.Fatal(`Provide 3 arguments in the § split, delimited by #.
+• A tbl(7) header
+• A tbl(7) footer
+• A pair of delimiters for references, such as "()"
+Below is an example.
+.\"§#.TS\nexpand;\nl1w(1.5i) l1w(4.5i).#.TE#()#\fC#\fP
+The final two arguments in that example are optional.`)
+ }
+ tableHead = interpEscape(words[1])
+ tableFoot = interpEscape(words[2])
+ delim = words[3]
+ if wc > 4 {
+ extraPrefix = words[4]
+ }
+ if wc > 5 {
+ extraSuffix = words[5]
+ }
}
}
// If no split, quietly return contents.
@@ -158,10 +195,10 @@ func main() {
each reference needs its own table. */
for _, ref := range refs {
fmt.Printf(".post.name %d\n", ref.index)
- fmt.Println(tableHead)
+ fmt.Printf(tableHead)
fmt.Printf("T{\n%c%s%c\nT}", delim[0], extraFmt(ref.name),
delim[1])
- fmt.Printf("\tT{\n%s\nT}\n", ref.contents)
+ fmt.Printf("\tT{\n%sT}\n", ref.contents)
fmt.Println(tableFoot)
}
}