Skip to content

Commit

Permalink
feat: Support 'strong' HTML Tag
Browse files Browse the repository at this point in the history
fix:  Parsing 'span' HTML Tag with recursive
  • Loading branch information
fengxxc committed Oct 17, 2022
1 parent 98806d1 commit cf2b343
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package parse

import (
"bytes"
"fmt"
"io"
"io/ioutil"
"log"
Expand All @@ -19,9 +18,7 @@ func parseSection(s *goquery.Selection) []Piece {
var pieces []Piece
s.Contents().Each(func(i int, sc *goquery.Selection) {
attr := make(map[string]string)
if sc.Is("span") {
pieces = append(pieces, Piece{NORMAL_TEXT, sc.Text(), nil})
} else if sc.Is("a") {
if sc.Is("a") {
attr["href"], _ = sc.Attr("href")
pieces = append(pieces, Piece{LINK, removeBrAndBlank(sc.Text()), attr})
} else if sc.Is("img") {
Expand All @@ -36,12 +33,14 @@ func parseSection(s *goquery.Selection) []Piece {
} else if sc.Is("pre") || sc.Is("section.code-snippet__fix") {
// 代码块
pieces = append(pieces, parsePre(sc)...)
} else if sc.Is("p") || sc.Is("section") {
} else if sc.Is("p") || sc.Is("section") || sc.Is("span") {
pieces = append(pieces, parseSection(sc)...)
} else if sc.Is("h1") || sc.Is("h2") || sc.Is("h3") || sc.Is("h4") || sc.Is("h5") || sc.Is("h6") {
pieces = append(pieces, parseHeader(sc)...)
} else if sc.Is("blockquote") {
pieces = append(pieces, parseBlockQuote(sc)...)
} else if sc.Is("strong") {
pieces = append(pieces, parseStrong(sc)...)
} else {
pieces = append(pieces, Piece{NORMAL_TEXT, sc.Text(), nil})
}
Expand Down Expand Up @@ -98,6 +97,12 @@ func parseBlockQuote(s *goquery.Selection) []Piece {
return bq
}

func parseStrong(s *goquery.Selection) []Piece {
var bt []Piece
bt = append(bt, Piece{BOLD_TEXT, strings.TrimSpace(s.Text()), nil})
return bt
}

func parseMeta(s *goquery.Selection) []string {
var res []string
s.Children().Each(func(i int, sc *goquery.Selection) {
Expand All @@ -107,7 +112,6 @@ func parseMeta(s *goquery.Selection) []string {
// t := sc.Text()
t := sc.Nodes[0].Data
// t, _ := sc.Html()
fmt.Println(t)
res = append(res, t)
}
})
Expand Down

0 comments on commit cf2b343

Please sign in to comment.