Skip to content

Commit

Permalink
Add better support of Atom text constructs
Browse files Browse the repository at this point in the history
- Note that Miniflux does not render entry title with HTML tags as of now
- Omit XHTML div element because it should not be part of the content
  • Loading branch information
fguillot committed Mar 20, 2021
1 parent 96f3e88 commit c8c1f05
Show file tree
Hide file tree
Showing 2 changed files with 172 additions and 68 deletions.
24 changes: 19 additions & 5 deletions reader/atom/atom_10.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,19 +221,33 @@ func (a *atom10Entry) entryCommentsURL() string {
}

type atom10Text struct {
Type string `xml:"type,attr"`
CharData string `xml:",chardata"`
InnerXML string `xml:",innerxml"`
Type string `xml:"type,attr"`
CharData string `xml:",chardata"`
InnerXML string `xml:",innerxml"`
XHTMLRootElement atomXHTMLRootElement `xml:"http://www.w3.org/1999/xhtml div"`
}

func (a *atom10Text) String() string {
var content string

if a.Type == "xhtml" {
switch {
case strings.HasPrefix(a.InnerXML, `<![CDATA[`):
content = a.CharData
case a.Type == "", a.Type == "text", a.Type == "text/plain":
content = a.InnerXML
} else {
case a.Type == "xhtml":
if a.XHTMLRootElement.InnerXML != "" {
content = a.XHTMLRootElement.InnerXML
} else {
content = a.InnerXML
}
default:
content = a.CharData
}

return strings.TrimSpace(content)
}

type atomXHTMLRootElement struct {
InnerXML string `xml:",innerxml"`
}
Loading

0 comments on commit c8c1f05

Please sign in to comment.