Implement XML data support

Example:

```
{{ with resources.Get "https://example.com/rss.xml" | transform.Unmarshal }}
    {{ range .channel.item }}
        <strong>{{ .title | plainify | htmlUnescape }}</strong><br />
        <p>{{ .description | plainify | htmlUnescape }}</p>
        {{ $link := .link | plainify | htmlUnescape }}
        <a href="{{ $link }}">{{ $link }}</a><br />
        <hr>
    {{ end }}
{{ end }}
```

Closes #4470
This commit is contained in:
Paul van Brouwershaven 2021-12-02 17:30:36 +01:00 committed by GitHub
parent 58adbeef88
commit 0eaaa8fee3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 167 additions and 12 deletions

View file

@ -591,9 +591,9 @@ func TestResourceChains(t *testing.T) {
case "/mydata/xml1.xml":
w.Write([]byte(`
<hello>
<world>Hugo Rocks!</<world>
</hello>`))
<hello>
<world>Hugo Rocks!</<world>
</hello>`))
return
case "/mydata/svg1.svg":
@ -872,16 +872,19 @@ Publish 2: {{ $cssPublish2.Permalink }}
{{ $toml := "slogan = \"Hugo Rocks!\"" | resources.FromString "slogan.toml" | transform.Unmarshal }}
{{ $csv1 := "\"Hugo Rocks\",\"Hugo is Fast!\"" | resources.FromString "slogans.csv" | transform.Unmarshal }}
{{ $csv2 := "a;b;c" | transform.Unmarshal (dict "delimiter" ";") }}
{{ $xml := "<?xml version=\"1.0\" encoding=\"UTF-8\"?><note><to>You</to><from>Me</from><heading>Reminder</heading><body>Do not forget XML</body></note>" | transform.Unmarshal }}
Slogan: {{ $toml.slogan }}
CSV1: {{ $csv1 }} {{ len (index $csv1 0) }}
CSV2: {{ $csv2 }}
XML: {{ $xml.body }}
`)
}, func(b *sitesBuilder) {
b.AssertFileContent("public/index.html",
`Slogan: Hugo Rocks!`,
`[[Hugo Rocks Hugo is Fast!]] 2`,
`CSV2: [[a b c]]`,
`XML: Do not forget XML`,
)
}},
{"resources.Get", func() bool { return true }, func(b *sitesBuilder) {