feat: 支持解析表格(简单粗暴的原生html方式)

This commit is contained in:
fengxxc
2023-08-27 12:55:50 +08:00
parent c266359a76
commit cafe91bbc1
4 changed files with 22 additions and 3 deletions

View File

@@ -64,6 +64,8 @@ func parseSection(s *goquery.Selection, imagePolicy ImagePolicy, lastPieceType P
pieces = append(pieces, parseBlockQuote(sc, imagePolicy)...)
} else if sc.Is("strong") {
pieces = append(pieces, parseStrong(sc)...)
} else if sc.Is("table") {
pieces = append(pieces, parseTable(sc)...)
} else {
if sc.Text() != "" {
pieces = append(pieces, Piece{NORMAL_TEXT, sc.Text(), nil})
@@ -123,6 +125,14 @@ func parseBlockQuote(s *goquery.Selection, imagePolicy ImagePolicy) []Piece {
return bq
}
func parseTable(s *goquery.Selection) []Piece {
// 先简单粗暴把原生的挪过去
var table []Piece
html, _ := s.Html()
table = append(table, Piece{TABLE, "<table>" + html + "</table>", map[string]string{"type": "native"}})
return table
}
func parseStrong(s *goquery.Selection) []Piece {
var bt []Piece
bt = append(bt, Piece{BOLD_TEXT, strings.TrimSpace(s.Text()), nil})