Skip to content

Commit dc7ab83

Browse files
committed
fix links are generated in code blocks
1 parent c2fe236 commit dc7ab83

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

parser.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,29 +121,38 @@ func Write(filepath string, classes []Class) {
121121
}
122122
}
123123

124+
func InsertLinkToComment(text string, class_name string) string {
125+
t := text
126+
puncs := []string{" ", ",", ".", ";", "\n"}
127+
class_link := " [" + class_name + "](" + class_name + ".html) "
128+
split_t := strings.Split(t, "```")
129+
for i, _ := range split_t {
130+
if i%2 == 1 {
131+
continue
132+
}
133+
for _, sym := range puncs {
134+
split_t[i] = strings.Replace(split_t[i], " "+class_name+sym, class_link, -1)
135+
}
136+
}
137+
return strings.Join(split_t, "```")
138+
}
139+
124140
func InsertClassLinks(classes Classes) Classes {
125141
var returned_classes Classes
126-
puncs := []string{" ", ",", ".", ";", "\n"}
127142
// loop classes
128143
for _, class := range classes {
129144
text := string(class.Comment)
130145
// insert link to class comment
131146
for _, each_class := range classes {
132-
each_class_link := " [" + each_class.Name + "](" + each_class.Filename + ".html) "
133-
for _, sym := range puncs {
134-
text = strings.Replace(text, " "+each_class.Name+sym, each_class_link, -1)
135-
}
147+
text = InsertLinkToComment(text, each_class.Name)
136148
}
137149

138150
// loop methods in a class
139151
for i, method := range class.InstanceMethods {
140152
text := string(method.Comment)
141153
// insert link to method comment
142154
for _, each_class := range classes {
143-
each_class_link := " [" + each_class.Name + "](" + each_class.Filename + ".html) "
144-
for _, sym := range puncs {
145-
text = strings.Replace(text, " "+each_class.Name+sym, each_class_link, -1)
146-
}
155+
text = InsertLinkToComment(text, each_class.Name)
147156
}
148157
class.InstanceMethods[i].Comment = template.HTML(text)
149158
}

0 commit comments

Comments
 (0)