microformats

package module
v0.0.0-...-4663554 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2019 License: MIT Imports: 5 Imported by: 0

README

microformats Documentation

This package does not have a stable API! If you have a use case that you think this package could work for then please open an issue.

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

func Parse(r io.Reader, baseURL *url.URL, tag string, v interface{}) error

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

func ParseAll(r io.Reader, baseURL *url.URL, tag string, v interface{}) error

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL