A Ruby gem to parse HTML containing one or more microformats2 and return a collection of dynamically defined Ruby objects.
A work in progress.
- parsing depth first, doc order
- parsing a p- property
- parsing a u- property
- parsing a dt- property
- parsing a e- property
- parsing implied properties
- nested properties
- nested microformat with associated property
- dynamic creation of properties
- normalize u-* property values
- nested microformat without associated property
- recognition of vendor extensions
- backwards compatable support for microformats v1
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install microformats2
require "microformats2" source = '<div class="h-card"><p class="p-name">Jessica Lynn Suttles</p></div>' collection = Microformats2.parse(source) # using singular accessors collection.card.name.to_s #=> "Jessica Lynn Suttles" # using plural accessors collection.cards.first.names.first.to_s #=> "Jessica Lynn Suttles" source = '<article class="h-entry"> <h1 class="p-name">Microformats 2</h1> <div class="h-card p-author"><p class="p-name">Jessica Lynn Suttles</p></div> </article>' collection = Microformats2.parse(source) collection.entry.name.to_s #=> "Microformats 2" # accessing nested microformats collection.entry.author.format.name.to_s #=> "Jessica Lynn Suttles" # getting a copy of the canonical microformats2 hash structure collection.to_hash # the above, as JSON in a string collection.to_json
sourcecan be a URL, filepath, or HTML
- Jessica Lynn Suttles / @jlsuttles
- Shane Becker / @veganstraightedge
- Chris Stringer / @jcstringer
- Michael Mitchell / @variousred
- Jessica Dillon / @jessicard
- Fork it
- Get it running (see Installation above)
- Create your feature branch (
git checkout -b my-new-feature)
- Write your code and specs
- Commit your changes (
git commit -am 'Add some feature')
- Push to the branch (
git push origin my-new-feature)
- Create new Pull Request
If you find bugs, have feature requests or questions, please file an issue.
To update spec cases that are scraped from other sites. Warning: This could break specs.
To run specs
To keep specs running
Copyright (c) 2013 G5
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.