@@ -150,25 +150,40 @@ func (doc *GHDoc) GrabToc() *GHToc {
150150 maxDepth = int (MaxHxDepth )
151151 }
152152
153+ hdrs := findHeadersInString (doc .html )
154+
155+ minHxDepth := MaxHxDepth
156+ for _ , hdr := range hdrs {
157+ if hdr .Depth < minHxDepth {
158+ minHxDepth = hdr .Depth
159+ }
160+ }
161+
153162 toc := GHToc {}
154- for _ , hdr := range findHeadersInString ( doc . html ) {
163+ for _ , hdr := range hdrs {
155164 // DEBUG BEGIN
156165 log .Printf ("*** CHUCK: GrabToc hdr: %+#v" , hdr )
157166 log .Printf ("*** CHUCK: GrabToc minDepth: %+#v" , minDepth )
158167 log .Printf ("*** CHUCK: GrabToc maxDepth: %+#v" , maxDepth )
159168 // DEBUG END
160169 hDepth := int (hdr .Depth )
161170 if hDepth >= minDepth && hDepth <= maxDepth {
162- toc = append (toc , doc .tocEntry (listIndentation (), hdr ))
171+ indentDepth := int (hdr .Depth ) - int (minHxDepth ) - doc .StartDepth
172+ // DEBUG BEGIN
173+ log .Printf ("*** CHUCK: GrabToc minHxDepth: %+#v" , minHxDepth )
174+ log .Printf ("*** CHUCK: GrabToc doc.StartDepth: %+#v" , doc .StartDepth )
175+ log .Printf ("*** CHUCK: GrabToc indentDepth: %+#v" , indentDepth )
176+ // DEBUG END
177+ indent := strings .Repeat (listIndentation (), indentDepth )
178+ toc = append (toc , doc .tocEntry (indent , hdr ))
163179 }
164180 }
165181
166182 return & toc
167183}
168184
169185func (doc * GHDoc ) tocEntry (indent string , hdr Header ) string {
170- indentDepth := int (hdr .Depth ) - doc .StartDepth
171- return strings .Repeat (indent , indentDepth ) + "* " +
186+ return indent + "* " +
172187 "[" + doc .tocName (hdr .Name ) + "]" +
173188 "(" + doc .tocLink (hdr .Href ) + ")"
174189}
0 commit comments