Skip to content

Commit

Permalink
新增高亮块和表格换行处理功能 (#133)
Browse files Browse the repository at this point in the history
* Update client.go

新增传入userAccessToken作为可选参数功能

* Update parser.go

新增高亮块,表格中内容可换行功能

* Update client.go

* Update client.go

* Update parser.go

1.新增高亮块类型处理
2.新增表格中内容换行处理
  • Loading branch information
DdGnoybab authored Aug 27, 2024
1 parent ab9846e commit 58f876a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion core/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ func (p *Parser) ParseDocxBlock(b *lark.DocxBlock, indentLevel int) string {
buf.WriteString(p.ParseDocxBlockPage(b))
case lark.DocxBlockTypeText:
buf.WriteString(p.ParseDocxBlockText(b.Text))
case lark.DocxBlockTypeCallout:
buf.WriteString(p.ParseDocxBlockCallout(b))
case lark.DocxBlockTypeHeading1:
buf.WriteString(p.ParseDocxBlockHeading(b, 1))
case lark.DocxBlockTypeHeading2:
Expand Down Expand Up @@ -217,6 +219,18 @@ func (p *Parser) ParseDocxBlockText(b *lark.DocxBlockText) string {
return buf.String()
}

func (p *Parser) ParseDocxBlockCallout(b *lark.DocxBlock) string {
buf := new(strings.Builder)

buf.WriteString(">[!TIP] \n")

for _, childId := range b.Children {
childBlock := p.blockMap[childId]
buf.WriteString(p.ParseDocxBlock(childBlock, 0))
}

return buf.String()
}
func (p *Parser) ParseDocxTextElement(e *lark.DocxTextElement, inline bool) string {
buf := new(strings.Builder)
if e.TextRun != nil {
Expand Down Expand Up @@ -364,7 +378,7 @@ func (p *Parser) ParseDocxBlockTableCell(b *lark.DocxBlock) string {
for _, child := range b.Children {
block := p.blockMap[child]
content := p.ParseDocxBlock(block, 0)
buf.WriteString(content)
buf.WriteString(content + "<br/>")
}

return buf.String()
Expand Down

0 comments on commit 58f876a

Please sign in to comment.