GithubHelp home page GithubHelp logo

isabella232 / mf2py Goto Github PK

View Code? Open in Web Editor NEW

This project forked from microformats/mf2py

0.0 0.0 0.0 607 KB

Microformats2 parser written in Python

Home Page: http://microformats.org/wiki/mf2py

License: Other

Makefile 0.04% Python 66.19% HTML 33.77%

mf2py's Introduction

mf2py

Build Status

Can I Use Python 3?

Python parser for microformats 2.

Current status: Full-featured and mostly stable. Implements the full mf2 spec, including backward compatibility with microformats1.

Documentation, code tidying and so on is rather lacking.

License: MIT

Install

pip install mf2py

Usage

Import the parser using

import mf2py

Parse a file containing the content

with open('file/content.html','r') as file:
    obj = mf2py.parse(doc=file)

Parse string containing content

content = '<article class="h-entry"><h1 class="p-name">Hello</h1></article>'
obj = mf2py.parse(doc=content)

Parse content from a URL

obj = mf2py.parse(url="http://tommorris.org/")

parse is a convenience method that actually delegates to mf2py.Parser to do the real work. More sophisticated behaviors are available by invoking the object directly.

Get parsed microformat in a variety of formats

p = mf2py.Parser(...)
p.to_dict()  # returns a python dictionary
p.to_json()  # returns a JSON string

Filter by microformat type

p.to_dict(filter_by_type="h-entry")
p.to_json(filter_by_type="h-entry")

Experimental features

  • pass the optional argument img_with_alt=True to either the Parser object or to the parse method to enable parsing of the alt attribute of <img> tags according to issue: image alt text is lost during parsing. By default this is False to be backwards compatible.

FAQ

  • I passed mf2py.parse() a BeautifulSoup document, and it got modified!

Yes, mf2py currently does that. We're working on preventing it! Hopefully soon.

Frontends

A basic web interface for mf2py and mf2util is available at mf2py-web.

A hosted live version can be found at python.microformats.io.

Contributions

We welcome contributions and bug reports via Github, and on the microformats wiki.

We try to follow the IndieWebCamp code of conduct. Please be respectful of other contributors, and forge a spirit of positive co-operation without discrimination or disrespect.

mf2py's People

Contributors

barnabywalters avatar dependabot-support avatar kartikprabhu avatar kevinmarks avatar kylewm avatar pawelmhm avatar sknebel avatar snarfed avatar tommorris avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.