Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Microformats Logo Microformats Ruby

A Ruby gem for parsing HTML documents containing microformats.

Gem Downloads Build Maintainability Coverage

Key Features

Getting Started

Before installing and using microformats-ruby, you'll want to have Ruby 2.4.10 (or newer) installed. It's recommended that you use a Ruby version management tool like rbenv, chruby, or rvm.

microformats-ruby is developed using Ruby 2.7.1 and is additionally tested against versions 2.4, 2.5, 2.6, 2.7, 3.0, and 3.1 using github Actions.


If you're using Bundler to manage gem dependencies, add microformats-ruby to your project's Gemfile:

source ''

gem 'microformats', '~> 4.0', '>= 4.2.1'

…and then run:

bundle install

You may also install microformats-ruby directly using:

gem install microformats


An example working with a basic h-card:

source = '<div class="h-card"><p class="p-name">Jessica Lynn Suttles</p></div>'
collection = Microformats.parse(source)

# Get a copy of the canonical microformats hash structure

# The above as JSON in a string

# Return a string if there is only one item found #=> "Jessica Lynn Suttles"

Below is a more complex markup structure using an h-entry with a nested h-card:

source = '<article class="h-entry">
  <h1 class="p-name">Microformats 2</h1>
  <div class="h-card p-author">
    <p class="p-name"><span class="p-first-name">Jessica</span> Lynn Suttles</p>

collection = Microformats.parse(source) #=> "Microformats 2"

# Accessing nested microformats #=> "Jessica Lynn Suttles"

# Accessing nested microformats can use shortcuts or expanded method #=> "Jessica Lynn Suttles" #=> "Jessica Lynn Suttles"

# Use `_` instead of `-` to return property values #=> "Jessica"
collection.rel_urls #=> {}

Using the same markup patterns as above, here's an h-entry with multiple authors, each marked up as h-cards:

source = '<article class="h-entry">
  <h1 class="p-name">Microformats 2</h1>
  <div class="h-card p-author">
    <p class="p-name"><span class="p-first-name">Jessica</span> Lynn Suttles</p>
  <div class="h-card p-author">
    <p class="p-name"><span class="p-first-name">Brandon</span> Edens</p>

collection = Microformats.parse(source)

# Arrays of items will always return the first item by default #=> "Jessica Lynn Suttles" #=> "Brandon Edens"

# Get the actual array of items by using `:all` #=> 2[1].name #=> "Brandon Edens"

Command Line Interface

microformats-ruby also includes a command like program that will parse HTML and return a JSON representation of the included microformats.


The program accepts URLs, file paths, or strings of HTML as an argument. Additionally, the script accepts piped input from other programs:

curl | microformats

Implementation Status

Status Specification or Parsing Rule
Parse a document for microformats
Parsing a p- property
Parsing a u- property
Parsing a dt- property
Parsing an e- property
Parsing for implied properties
Nested properties
Nested microformat with associated property
Nested microformat without associated property
Recognize dynamically created properties
Support for rel attribute values
Normalizing u-* property values
Parse the value class pattern
Recognize vendor extensions
Support for classic microformats
Recognize the include pattern

Improving microformats-ruby

Have questions about using microformats-ruby? Found a bug? Have ideas for new or improved features? Want to pitch in and write some code?

Check out for more on how you can help!


The microformats-ruby logo is derived from the microformats logo mark by Rémi Prévost.

microformats-ruby is written and maintained by:


microformats-ruby is dedicated to the public domain using the Creative Commons CC0 1.0 Universal license.

The authors waive all of their rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, and distribute the work, even for commercial purposes, all without asking permission.

See LICENSE for more details.


Ruby gem that parse HTML containing microformats/microformats2 and returns Ruby objects, a Ruby hash or a JSON hash








No packages published