From d4f4f0e51f86762de9b47c4ee90d633f5ce061f9 Mon Sep 17 00:00:00 2001 From: WindowsSov8forUs Date: Wed, 22 May 2024 12:05:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=20Quote=20=E5=85=83?= =?UTF-8?q?=E7=B4=A0=E5=88=9D=E5=A7=8B=E5=AD=97=E6=AE=B5=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/message/message_element_meta.go | 25 ++++++++++++++++++++++--- pkg/message/parser_test.go | 1 + pkg/message/parser_test_data.go | 2 +- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/pkg/message/message_element_meta.go b/pkg/message/message_element_meta.go index 9d2ac38..557d76a 100644 --- a/pkg/message/message_element_meta.go +++ b/pkg/message/message_element_meta.go @@ -3,6 +3,8 @@ package message import "golang.org/x/net/html" type MessageElementQuote struct { + Id string + Forward bool *noAliasMessageElement *ChildrenMessageElement *ExtendAttributes @@ -13,7 +15,14 @@ func (e *MessageElementQuote) Tag() string { } func (e *MessageElementQuote) Stringify() string { - result := e.stringifyAttributes() + result := "" + if e.Id != "" { + result += ` id="` + escape(e.Id, true) + `"` + } + if e.Forward { + result += ` forward` + } + result += e.stringifyAttributes() childrenStr := e.stringifyChildren() if childrenStr == "" { return `<` + e.Tag() + result + `/>` @@ -23,9 +32,19 @@ func (e *MessageElementQuote) Stringify() string { func (e *MessageElementQuote) Parse(n *html.Node) (MessageElement, error) { attrMap := attrList2MapVal(n.Attr) - result := &MessageElementQuote{} + result := &MessageElementQuote{ + Forward: false, + } + if id, ok := attrMap["id"]; ok { + result.Id = id + } + if forwardAttr, ok := attrMap["forward"]; ok { + result.Forward = forwardAttr == "" || forwardAttr == "true" || forwardAttr == "1" + } for key, value := range attrMap { - result.ExtendAttributes = result.AddAttribute(key, value) + if key != "id" && key != "forward" { + result.ExtendAttributes = result.AddAttribute(key, value) + } } children, err := result.parseChildren(n) if err != nil { diff --git a/pkg/message/parser_test.go b/pkg/message/parser_test.go index 7207646..d5ca804 100644 --- a/pkg/message/parser_test.go +++ b/pkg/message/parser_test.go @@ -13,6 +13,7 @@ func Test(t *testing.T) { t.Fatalf("%s Parse error: %s", message, err) } result, err := Stringify(elements) + t.Logf("result: %s", result) if err != nil { t.Fatalf("%s Stringify error: %s", elements, err) } diff --git a/pkg/message/parser_test_data.go b/pkg/message/parser_test_data.go index 3574d13..2c91839 100644 --- a/pkg/message/parser_test_data.go +++ b/pkg/message/parser_test_data.go @@ -52,7 +52,7 @@ func _getLayoutRawMessage() []string { func _getMetaRawMessage() []string { return []string{ - `testtest`, + `testtest`, ``, } }