Skip to content

Commit 4d1d8a4

Browse files
committed
fine tune comments
1 parent 4afb1cc commit 4d1d8a4

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

services/gitdiff/highlightdiff.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -136,20 +136,20 @@ func (hcd *highlightCodeDiff) convertToPlaceholders(htmlCode string) string {
136136
}
137137

138138
var tokenInMap string
139-
if strings.HasSuffix(token, "</") { // for closed tag
139+
if strings.HasSuffix(token, "</") { // for closing tag
140140
if len(tagStack) == 0 {
141-
break // invalid diff result, no open tag but see close tag
141+
break // invalid diff result, no opening tag but see closing tag
142142
}
143-
// make sure the closed tag in map is related to the open tag, to make the diff algorithm can match the open/closed tags
144-
// the closed tag will be recorded in the map by key "</span><!-- <span the-open> -->" for "<span the-open>"
143+
// make sure the closing tag in map is related to the open tag, to make the diff algorithm can match the opening/closing tags
144+
// the closing tag will be recorded in the map by key "</span><!-- <span the-opening> -->" for "<span the-opening>"
145145
tokenInMap = token + "<!-- " + tagStack[len(tagStack)-1] + "-->"
146146
tagStack = tagStack[:len(tagStack)-1]
147-
} else if strings.HasPrefix(token, "<") { // for open tag
147+
} else if token[0] == '<' { // for opening tag
148148
tokenInMap = token
149149
tagStack = append(tagStack, token)
150-
} else if strings.HasPrefix(token, "&") { // for html entity
150+
} else if token[0] == '&' { // for html entity
151151
tokenInMap = token
152-
}
152+
} // else: impossible
153153

154154
// remember the placeholder and token in the map
155155
placeholder, ok := hcd.tokenPlaceholderMap[tokenInMap]
@@ -191,31 +191,31 @@ func (hcd *highlightCodeDiff) recoverOneDiff(diff *diffmatchpatch.Diff) {
191191
continue
192192
}
193193
var tokenToRecover string
194-
if token[1] == '/' { // Closing tag
194+
if strings.HasPrefix(token, "</") { // for closing tag
195195
// only get the tag itself, ignore the trailing comment (for how the comment is generated, see the code in `convert` function)
196196
tokenToRecover = token[:strings.IndexByte(token, '>')+1]
197197
if len(tagStack) == 0 {
198-
continue // if no open tag in stack yet, skip the closed tag
198+
continue // if no opening tag in stack yet, skip the closing tag
199199
}
200200
tagStack = tagStack[:len(tagStack)-1]
201-
} else if token[0] == '<' {
201+
} else if token[0] == '<' { // for opening tag
202202
tokenToRecover = token
203203
tagStack = append(tagStack, token)
204-
} else { // html entity
204+
} else if token[0] == '&' { // for html entity
205205
tokenToRecover = token
206-
}
206+
} // else: impossible
207207
sb.WriteString(tokenToRecover)
208208
}
209209

210210
if len(tagStack) > 0 {
211-
// close all open tags
211+
// close all opening tags
212212
for i := len(tagStack) - 1; i >= 0; i-- {
213213
tagToClose := tagStack[i]
214-
// get the closed tag "</span>" from "<span class=...>" or "<span>"
214+
// get the closing tag "</span>" from "<span class=...>" or "<span>"
215215
pos := strings.IndexAny(tagToClose, " >")
216216
if pos != -1 {
217217
sb.WriteString("</" + tagToClose[1:pos] + ">")
218-
} // else: impossible. every tag was pushed into the stack by the code above and is valid HTML open tag
218+
} // else: impossible. every tag was pushed into the stack by the code above and is valid HTML opening tag
219219
}
220220
}
221221

0 commit comments

Comments
 (0)