Skip to content

Instantly share code, notes, and snippets.

@tk0miya
Created November 22, 2012 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tk0miya/4130196 to your computer and use it in GitHub Desktop.
Save tk0miya/4130196 to your computer and use it in GitHub Desktop.
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