Create a gist now

Instantly share code, notes, and snippets.

sphinxcontrib_remoteinclude
.. remoteinclude:: http://www.yahoo.co.jp/
# -*- coding: utf-8 -*-
"""
sphinxcontrib_remoteinclude
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
literalinclude for remote files
:copyright: Copyright 2012 by Takeshi Komiya.
:license: BSDL.
"""
from urllib2 import urlopen
from docutils import nodes
from docutils.parsers.rst import Directive, directives
from sphinx.util.nodes import set_source_info
class RemoteInclude(Directive):
required_arguments = 1
final_argument_whitespace = False
option_spec = {
'encoding': directives.unchanged,
}
def run(self):
url = self.arguments[0]
encoding = self.options.get('encoding', 'utf8')
content = urlopen(url).read()
literal = nodes.literal_block(content, content, source=url)
set_source_info(self, literal)
return [literal]
def setup(app):
app.add_directive('remoteinclude', RemoteInclude)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment