willnorris/microformats


Go library for parsing microformats

https://pkg.go.dev/willnorris.com/go/microformats

License: MIT

Language: Go

Keywords: microformats


microformats

GoDoc Test Status Test Coverage

microformats is a go library and tool for parsing microformats, supporting both classic v1 and v2 syntax. It is based on Andy Leap's original library.

Usage

To see this package in action, the simplest way is to install the command line app and use it to fetch and parse a webpage with microformats on it:

% go install willnorris.com/go/microformats/cmd/gomf@latest
% gomf https://indieweb.org

To use it in your own code, import the package:

import "willnorris.com/go/microformats"

If you have the HTML contents of a page in an io.Reader, call Parse like in this example:

content := `<article class="h-entry"><h1 class="p-name">Hello</h1></article>`
r := strings.NewReader(content)

data := microformats.Parse(r, nil)

// do something with data, or just print it out as JSON:
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", "  ")
enc.Encode(data)

Alternately, if you have already parsed the page and have an html.Node, then call ParseNode. For example, you might want to select a subset of the DOM, and parse only that for microformats. An example of doing this with the goquery package can be seen in cmd/gomf/main.go.

To see that in action using the gomf app installed above, you can parse the microformats from indieweb.org that appear within the #content element:

% gomf https://indieweb.org "#content"

{
  "items": [
    {
      "id": "content",
      "type": [
        "h-entry"
      ],
      "properties": ...
      "children": ...
    }
  ],
  "rels": {},
  "rel-urls": {}
}

Additional helper packages

Use the ptd package to perform Post Type Discovery.

Use the rhc package to find a Representative h-card.

Project Statistics

Sourcerank 9
Repository Size 208 KB
Stars 64
Forks 6
Watchers 6
Open issues 2
Dependencies 10
Contributors 8
Tags 4
Created
Last updated
Last pushed

Top Contributors See all

Will Norris andyleap Arijit Basu Henrique Dias Nenad Stojanovikj Evgeny Kuznetsov Shane Becker Peter Stuifzand

Packages Referencing this Repo

willnorris.com/go/microformats
Go library for parsing microformats
Latest release v1.2.0 - Updated - 64 stars
github.com/willnorris/microformats
Go library for parsing microformats
Latest release v1.2.0 - Published - 64 stars

Recent Tags See all

v1.2.0 January 31, 2023
v1.1.1 October 29, 2020
v1.1.0 May 21, 2020
v1.0.0 September 13, 2018

Something wrong with this page? Make a suggestion

Last synced: 2024-11-10 16:17:03 UTC

Login to resync this repository