#!/usr/bin/env ruby require 'microformats' require 'json' def print_usage puts "Usage: microformats (URL, filepath, or HTML)" end def process_html(html) collection = Microformats.parse(html) puts JSON.pretty_generate(JSON[collection.to_json.to_s]) end if STDIN.tty? unless ARGV[0].nil? process_html(ARGV[0]) else print_usage end else html = STDIN.read unless html.nil? process_html(html) else print_usage end end