diff options
Diffstat (limited to 'ref.go')
-rw-r--r-- | ref.go | 53 |
1 files changed, 45 insertions, 8 deletions
@@ -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) } } |