@@ -28,6 +28,7 @@ import (
28
28
"bufio"
29
29
"bytes"
30
30
"fmt"
31
+ "io"
31
32
"log"
32
33
"os"
33
34
"path/filepath"
@@ -72,11 +73,12 @@ func main() {
72
73
depth := len (words [0 ])
73
74
words = words [1 :]
74
75
text := strings .Join (words , " " )
75
- for i := range words {
76
- words [i ] = strings .ToLower (words [i ])
77
- }
78
- line = fmt .Sprintf ("%s1. [%s](#%s)" ,
79
- strings .Repeat ("\t " , depth - 1 ), text , strings .Join (words , "-" ))
76
+ anchor := strings .Join (words , "-" )
77
+ anchor = strings .ToLower (anchor )
78
+ anchor = strings .ReplaceAll (anchor , "**" , "" )
79
+ anchor = strings .ReplaceAll (anchor , "`" , "" )
80
+ anchor = strings .ReplaceAll (anchor , "_" , "" )
81
+ line = fmt .Sprintf ("%s1. [%s](#%s)" , strings .Repeat ("\t " , depth - 1 ), text , anchor )
80
82
toc = append (toc , line )
81
83
}
82
84
}
@@ -85,7 +87,7 @@ func main() {
85
87
}
86
88
87
89
// Pass 2.
88
- if _ , err := f .Seek (0 , os . SEEK_SET ); err != nil {
90
+ if _ , err := f .Seek (0 , io . SeekStart ); err != nil {
89
91
log .Fatalf ("can't rewind input: %v" , err )
90
92
}
91
93
in = bufio .NewScanner (f )
@@ -173,12 +175,6 @@ func include(file, tag string) (string, error) {
173
175
return text .String (), nil
174
176
}
175
177
176
- func isBlank (line string ) bool { return strings .TrimSpace (line ) == "" }
177
-
178
- func indented (line string ) bool {
179
- return strings .HasPrefix (line , " " ) || strings .HasPrefix (line , "\t " )
180
- }
181
-
182
178
// cleanListing removes entirely blank leading and trailing lines from
183
179
// text, and removes n leading tabs.
184
180
func cleanListing (text string ) string {
0 commit comments