diff --git a/Makefile b/Makefile index fc1643a..cd7e0e3 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ BUILD_ENV := CGO_ENABLED=0 APP=wechatmp2markdown -VERSION=v1.1.4 +VERSION=v1.1.5 # linux or mac 环境编译 # make [cmd] diff --git a/README.md b/README.md index a70eb69..9d027d9 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ mingw32-make win-build-win32 编译好的文件在`./build`目录下 ## TODO -- [ ] 支持解析表格元素(table tag) +- [x] 支持解析表格元素(table tag) ## 最后 抓紧时间窗口。努力记录。黑暗中记得光的模样。 \ No newline at end of file diff --git a/format/format.go b/format/format.go index 01085b2..4914078 100644 --- a/format/format.go +++ b/format/format.go @@ -174,7 +174,7 @@ func formatContent(pieces []parse.Piece, depth int) (string, map[string][]byte) pieceMdStr = formatImageRefer(piece, len(base64Imgs)) base64Imgs = append(base64Imgs, piece.Val.(string)) case parse.TABLE: - // TODO + pieceMdStr = formatTable(piece) case parse.CODE_INLINE: // TODO case parse.CODE_BLOCK: @@ -201,6 +201,15 @@ func formatContent(pieces []parse.Piece, depth int) (string, map[string][]byte) return contentMdStr, saveImageBytes } +func formatTable(piece parse.Piece) string { + var tableMdStr string + if piece.Attrs != nil && piece.Attrs["type"] == "native" { + tableMdStr = piece.Val.(string) + } + // TODO + return tableMdStr +} + func formatBlockQuote(piece parse.Piece, depth int) (string, map[string][]byte) { var bqMdString string var prefix string = ">" diff --git a/parse/parse.go b/parse/parse.go index 61df768..aed126c 100644 --- a/parse/parse.go +++ b/parse/parse.go @@ -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, "