Skip to content

Instantly share code, notes, and snippets.

@tk0miya tk0miya/index.txt
Created Nov 22, 2012

What would you like to do?
.. remoteinclude::
# -*- coding: utf-8 -*-
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
You can’t perform that action at this time.