Add slightly hacky workaround to fix #316
This commit is contained in:
parent
1ea20b6df7
commit
1b4aa60114
@ -43,6 +43,10 @@ func (be *BaseEntity) AdjustStyle(fn AdjustStyleFunc) Entity {
|
||||
return be
|
||||
}
|
||||
|
||||
func (be *BaseEntity) IsEmpty() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsBlock returns whether or not this is a block-type entity.
|
||||
func (be *BaseEntity) IsBlock() bool {
|
||||
return be.Block
|
||||
|
@ -32,6 +32,10 @@ type ContainerEntity struct {
|
||||
Indent int
|
||||
}
|
||||
|
||||
func (ce *ContainerEntity) IsEmpty() bool {
|
||||
return len(ce.Children) == 0
|
||||
}
|
||||
|
||||
// PlainText returns the plaintext content in this entity and all its children.
|
||||
func (ce *ContainerEntity) PlainText() string {
|
||||
if len(ce.Children) == 0 {
|
||||
@ -84,8 +88,7 @@ func (ce *ContainerEntity) String() string {
|
||||
return fmt.Sprintf(`&html.ContainerEntity{Base=%s, Indent=%d, Children=[]}`, ce.BaseEntity, ce.Indent)
|
||||
}
|
||||
var buf strings.Builder
|
||||
_, _ = fmt.Fprintf(&buf, `&html.ContainerEntity{Base=%s,
|
||||
Indent=%d, Children=[`, ce.BaseEntity, ce.Indent)
|
||||
_, _ = fmt.Fprintf(&buf, `&html.ContainerEntity{Base=%s, Indent=%d, Children=[`, ce.BaseEntity, ce.Indent)
|
||||
for _, child := range ce.Children {
|
||||
buf.WriteString("\n ")
|
||||
buf.WriteString(strings.Join(strings.Split(strings.TrimRight(child.String(), "\n"), "\n"), "\n "))
|
||||
|
@ -46,4 +46,6 @@ type Entity interface {
|
||||
CalculateBuffer(width, startX int, bare bool) int
|
||||
|
||||
getStartX() int
|
||||
|
||||
IsEmpty() bool
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ func (parser *htmlParser) basicFormatToEntity(node *html.Node) Entity {
|
||||
entity.AdjustStyle(AdjustStyleStrikethrough)
|
||||
case "u", "ins":
|
||||
entity.AdjustStyle(AdjustStyleUnderline)
|
||||
case "font":
|
||||
case "font", "span":
|
||||
fgColor, ok := parser.parseColor(node, "data-mx-color", "color")
|
||||
if ok {
|
||||
entity.AdjustStyle(AdjustStyleTextColor(fgColor))
|
||||
@ -348,7 +348,7 @@ func (parser *htmlParser) tagNodeToEntity(node *html.Node) Entity {
|
||||
return parser.headerToEntity(node)
|
||||
case "br":
|
||||
return NewBreakEntity()
|
||||
case "b", "strong", "i", "em", "s", "strike", "del", "u", "ins", "font":
|
||||
case "b", "strong", "i", "em", "s", "strike", "del", "u", "ins", "font", "span":
|
||||
return parser.basicFormatToEntity(node)
|
||||
case "a":
|
||||
return parser.linkToEntity(node)
|
||||
@ -384,7 +384,11 @@ func (parser *htmlParser) singleNodeToEntity(node *html.Node) Entity {
|
||||
}
|
||||
return NewTextEntity(node.Data)
|
||||
case html.ElementNode:
|
||||
return parser.tagNodeToEntity(node)
|
||||
parsed := parser.tagNodeToEntity(node)
|
||||
if parsed != nil && !parsed.IsBlock() && parsed.IsEmpty() {
|
||||
return nil
|
||||
}
|
||||
return parsed
|
||||
case html.DocumentNode:
|
||||
if node.FirstChild.Data == "html" && node.FirstChild.NextSibling == nil {
|
||||
return parser.singleNodeToEntity(node.FirstChild)
|
||||
|
@ -45,6 +45,10 @@ func NewTextEntity(text string) *TextEntity {
|
||||
}
|
||||
}
|
||||
|
||||
func (te *TextEntity) IsEmpty() bool {
|
||||
return len(te.Text) == 0
|
||||
}
|
||||
|
||||
func (te *TextEntity) AdjustStyle(fn AdjustStyleFunc) Entity {
|
||||
te.BaseEntity = te.BaseEntity.AdjustStyle(fn).(*BaseEntity)
|
||||
return te
|
||||
|
@ -54,7 +54,7 @@ func ParseEvent(matrix ifc.MatrixContainer, mainView ifc.MainView, room *rooms.R
|
||||
if replyToMsg := getCachedEvent(mainView, room.ID, content.GetReplyTo()); replyToMsg != nil {
|
||||
msg.ReplyTo = replyToMsg.Clone()
|
||||
} else if replyToEvt, _ := matrix.GetEvent(room, content.GetReplyTo()); replyToEvt != nil {
|
||||
if replyToMsg := directParseEvent(matrix, room, replyToEvt); replyToMsg != nil {
|
||||
if replyToMsg = directParseEvent(matrix, room, replyToEvt); replyToMsg != nil {
|
||||
msg.ReplyTo = replyToMsg
|
||||
msg.ReplyTo.Reactions = nil
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user