mirror of
https://github.com/fengxxc/wechatmp2markdown.git
synced 2026-02-28 09:41:01 +08:00
fix: 列表项段落、引用段落换行的bug
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
package parse
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Article struct {
|
||||
Title Piece
|
||||
Meta []string
|
||||
@@ -7,6 +12,32 @@ type Article struct {
|
||||
Content []Piece
|
||||
}
|
||||
|
||||
func (article Article) ToString() string {
|
||||
return ToString(article.Content)
|
||||
}
|
||||
|
||||
func ToString(pieces []Piece) string {
|
||||
var res []string
|
||||
for _, p := range pieces {
|
||||
var val = "[null]"
|
||||
|
||||
switch p.Val.(type) {
|
||||
case string:
|
||||
val = p.Val.(string)
|
||||
if len(val) > 90 {
|
||||
val = val[:90]
|
||||
}
|
||||
res = append(res, "type: "+strconv.Itoa(int(p.Type))+", value: "+val+"\n")
|
||||
case []Piece:
|
||||
res = append(res, ToString(p.Val.([]Piece)))
|
||||
default:
|
||||
res = append(res, "type: "+strconv.Itoa(int(p.Type))+", value: "+val+"\n")
|
||||
}
|
||||
// fmt.Printf("%+v %+v\n", p.Type, val)
|
||||
}
|
||||
return strings.Join(res, "")
|
||||
}
|
||||
|
||||
type Header struct {
|
||||
Level int
|
||||
Text string
|
||||
@@ -39,4 +70,5 @@ const (
|
||||
U_LIST // 13 无序列表
|
||||
HR // 14 分隔线
|
||||
BR // 15 换行
|
||||
NULL // 无
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user