Skip to content

Commit

Permalink
mmcdole#151: Add atom namespaces to known namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Necoro committed Jul 10, 2024
1 parent 468e0dd commit c7484c4
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions internal/shared/extparser.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
package shared

import (
"slices"
"strings"

"github.com/mmcdole/gofeed/extensions"
"github.com/mmcdole/goxpp"
ext "github.com/mmcdole/gofeed/extensions"
xpp "github.com/mmcdole/goxpp"
)

var knownPrefixes = []string{
"rss",
"rdf",
"content",
"atom",
"atom03",
}

// IsExtension returns whether or not the current
// XML element is an extension element (if it has a
// non empty prefix)
func IsExtension(p *xpp.XMLPullParser) bool {
space := strings.TrimSpace(p.Space)
prefix := PrefixForNamespace(space, p)
return !(prefix == "" || prefix == "rss" || prefix == "rdf" || prefix == "content")

if prefix == "" {
return false
}

return !slices.Contains(knownPrefixes, prefix)
}

// ParseExtension parses the current element of the
Expand Down Expand Up @@ -118,6 +132,8 @@ func PrefixForNamespace(space string, p *xpp.XMLPullParser) string {
// These canonical prefixes override any prefixes used in the feed itself.
var canonicalNamespaces = map[string]string{
"http://webns.net/mvcb/": "admin",
"http://www.w3.org/2005/Atom": "atom",
"http://purl.org/atom/ns#": "atom03",
"http://purl.org/rss/1.0/modules/aggregation/": "ag",
"http://purl.org/rss/1.0/modules/annotate/": "annotate",
"http://media.tangent.org/rss/1.0/": "audio",
Expand Down

0 comments on commit c7484c4

Please sign in to comment.