Created
November 22, 2012 09:28
-
-
Save tk0miya/4130196 to your computer and use it in GitHub Desktop.
sphinxcontrib_remoteinclude
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.. remoteinclude:: http://www.yahoo.co.jp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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