Documentation ¶
Overview ¶
Package microformats allows parsing of microformats2 data into structs.
This package is a wrapper around https://github.com/andyleap/microformats to replicate the structtag based parsing of encoding/json (and others).
Note that, contrary to encoding/json, fields must be tagged with `mf:"PROPERTY"` to be set.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Parse ¶
Parse will find within r any instances of the microformat given by tag, resolving any URLs encountered against the baseURL provded, and assign the tagged properties to v.
Example ¶
package main import ( "fmt" "net/url" "strings" microformats "hawx.me/code/microformats" ) func main() { r := strings.NewReader(`<div class="h-card"> <span class="p-name">John Doe</span> </div>`) baseURL, _ := url.Parse("http://example.com/") var output struct { Name string `mf:"name"` } microformats.Parse(r, baseURL, "h-card", &output) fmt.Println(output.Name) }
Output: John Doe
func ParseAll ¶
ParseAll will fill a slice with instances of the tag found when parsing r.
Example ¶
package main import ( "fmt" "net/url" "strings" microformats "hawx.me/code/microformats" ) func main() { r := strings.NewReader(`<div class="h-card"> <span class="p-name">John Doe</span> </div> <div class="h-card"> <span class="p-name">Jane Doe</span> </div>`) baseURL, _ := url.Parse("http://example.com/") var output []struct { Name string `mf:"name"` } microformats.ParseAll(r, baseURL, "h-card", &output) fmt.Println(output[0].Name) fmt.Println(output[1].Name) }
Output: John Doe Jane Doe
Types ¶
This section is empty.
Directories ¶
Path | Synopsis |
---|---|
An implementation of the indieweb authorship algorithm.
|
An implementation of the indieweb authorship algorithm. |
cmd
|
|
Click to show internal directories.
Click to hide internal directories.