github3.py icon indicating copy to clipboard operation
github3.py copied to clipboard

Support for fetching README rendered as HTML

Open mjuenema opened this issue 8 years ago • 1 comments

The Github API supports fetching a repository's README rendered as HTML, i.e. as displayed in the Github web interface. This feature is described here Contents: custom media types. In fact that seems to work for any file although I haven't actually tested this.

With a bit of trickery this is already possible with github3.py,

import github3
repo = github3.repository('sigmavirus24', 'github3.py')

# Here come the clever bits
repo._session.headers['Accept'] = 'application/vnd.github.v3.html'
url = repo._build_url('readme', base_url=repo._api)
response = repo._get(url)
print response.content

# Don't forget to reset the header!!!
repo._session.headers['Accept'] = 'application/vnd.github.v3.full+json'

This could be added to the API by either

  • Adding a Repository.readme_as_html() method, or
  • Adding a format="html" argument to Repository.readme() and Repository.contents() methods.

Any thoughts?

Markus


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

mjuenema avatar May 17 '17 10:05 mjuenema

Interesting .full used to retrieve plain-text, raw, and html formatted bodies. It's disappointing that they silently broke this

sigmavirus24 avatar Mar 22 '18 02:03 sigmavirus24