Skip to content

Commit ed5e73f

Browse files
committed
Show word's part of speech
Deal with situations that the query word does not return part of speech
1 parent ec4aa7c commit ed5e73f

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

query.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,17 @@ func query(words []string, withVoice, withMore, isMulti bool) {
9292
if isChinese {
9393
// Find the result
9494
fmt.Println()
95-
doc.Find(".trans-container > ul > p > span.contentTitle").Each(func(i int, s *goquery.Selection) {
96-
color.Green(" %s", s.Find(".search-js").Text())
95+
doc.Find(".trans-container > ul > p").Each(func(i int, s *goquery.Selection) {
96+
partOfSpeech := s.Children().Not(".contentTitle").Text()
97+
if partOfSpeech != "" {
98+
fmt.Printf("%14s ", color.MagentaString(partOfSpeech))
99+
}
100+
101+
meanings := []string{}
102+
s.Find(".contentTitle > .search-js").Each(func(ii int, ss *goquery.Selection) {
103+
meanings = append(meanings, ss.Text())
104+
})
105+
fmt.Printf("%s\n", color.GreenString(strings.Join(meanings, "; ")))
97106
})
98107
} else {
99108

0 commit comments

Comments
 (0)