def update_body(app, pagename, templatename, context, doctree):
STATIC_URL = context.get('<STR_LIT>', DEFAULT_STATIC_URL)<EOL>online_builders = [<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>'<EOL>]<EOL>if app.builder.name == '<STR_LIT>':<EOL><INDENT>if '<STR_LIT>' in context and context['<STR_LIT>'] == '<STR_LIT>':<EOL><INDENT>theme_css = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>theme_css = '<STR_LIT>'<EOL><DEDENT><DEDENT>elif app.builder.name in online_builders:<EOL><INDENT>if '<STR_LIT>' in context and context['<STR_LIT>'] == '<STR_LIT>':<EOL><INDENT>theme_css = '<STR_LIT>' % STATIC_URL<EOL><DEDENT>else:<EOL><INDENT>theme_css = '<STR_LIT>' % STATIC_URL<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return<EOL><DEDENT>inject_css = True<EOL>if theme_css.endswith('<STR_LIT>'):<EOL><INDENT>try:<EOL><INDENT>import sphinx_rtd_theme<EOL>inject_css = LooseVersion(sphinx_rtd_theme.__version__) < LooseVersion('<STR_LIT>')<EOL><DEDENT>except ImportError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>if inject_css and theme_css not in app.builder.css_files:<EOL><INDENT>if sphinx.version_info < (<NUM_LIT:1>, <NUM_LIT:8>):<EOL><INDENT>app.builder.css_files.insert(<NUM_LIT:0>, theme_css)<EOL><DEDENT>else:<EOL><INDENT>app.add_css_file(theme_css)<EOL><DEDENT><DEDENT>if not hasattr(app.builder.templates.render, '<STR_LIT>'):<EOL><INDENT>old_render = app.builder.templates.render<EOL>def rtd_render(self, template, render_context):<EOL><INDENT>"""<STR_LIT>"""<EOL>template_context = render_context.copy()<EOL>template_context['<STR_LIT>'] = '<STR_LIT>'.format(STATIC_URL)<EOL>template_context['<STR_LIT>'] = '<STR_LIT>'.format(<EOL>STATIC_URL,<EOL>)<EOL>source = os.path.join(<EOL>os.path.abspath(os.path.dirname(__file__)),<EOL>'<STR_LIT>',<EOL>'<STR_LIT>'<EOL>)<EOL>templ = open(source).read()<EOL>rtd_content = app.builder.templates.render_string(templ, template_context)<EOL>content = old_render(template, render_context)<EOL>end_body = content.lower().find('<STR_LIT>')<EOL>if end_body != -<NUM_LIT:1>:<EOL><INDENT>content = content[:end_body] + rtd_content + "<STR_LIT:\n>" + content[end_body:]<EOL><DEDENT>else:<EOL><INDENT>log.debug("<STR_LIT>")<EOL><DEDENT>return content<EOL><DEDENT>rtd_render._patched = True<EOL>app.builder.templates.render = types.MethodType(rtd_render,<EOL>app.builder.templates)<EOL><DEDENT>
Add Read the Docs content to Sphinx body content.

This is the most reliable way to inject our content into the page.