def init(self): StandaloneHTMLBuilder.init(self) # the output files for epub must be .html only self.out_suffix = '.xhtml' self.link_suffix = '.xhtml' self.playorder = 0 self.tocid = 0
def init(self): StandaloneHTMLBuilder.init(self) # Pull project data from conf.py if it exists context = self.config.html_context if 'current_version' in context: self.version = context['current_version'] if 'slug' in context: self.project = context['slug'] # Put in our media files instead of putting them in the docs. for index, file in enumerate(self.script_files): if file in MEDIA_MAPPING.keys(): self.script_files[index] = MEDIA_MAPPING[file] % context['MEDIA_URL'] if file == "_static/jquery.js": self.script_files.insert(index+1, "%sjavascript/jquery/jquery-migrate-1.2.1.min.js" % context['MEDIA_URL']) if 'html_theme' in context and context['html_theme'] == 'sphinx_rtd_theme': self.css_files.append('%scss/sphinx_rtd_theme.css' % context['MEDIA_URL']) else: self.css_files.append('%scss/badge_only.css' % context['MEDIA_URL']) # Analytics codes #self.script_files.append('_static/readthedocs-ext.js') #self.script_files.append('%sjavascript/analytics.js' % context['MEDIA_URL']) # We include the media servers version here so we can update rtd.js across all # documentation without rebuilding every one. # If this script is embedded in each build, # then updating the file across all docs is basically impossible. self.script_files.append('%sjavascript/readthedocs-doc-embed.js' % context['MEDIA_URL']) self.css_files.append('%scss/readthedocs-doc-embed.css' % context['MEDIA_URL'])
def test_images(): assert warning_emitted('images', 'image file not readable: foo.png') assert warning_emitted('images', 'nonlocal image URI found: ' 'http://www.python.org/logo.png') tree = env.get_doctree('images') app._warning.reset() htmlbuilder = StandaloneHTMLBuilder(app) htmlbuilder.imgpath = 'dummy' htmlbuilder.post_process_images(tree) image_uri_message = "no matching candidate for image URI u'foo.*'" if PY3: image_uri_message = remove_unicode_literals(image_uri_message) assert image_uri_message in app._warning.content[-1] assert set(htmlbuilder.images.keys()) == \ set(['subdir/img.png', 'img.png', 'subdir/simg.png', 'svgimg.svg']) assert set(htmlbuilder.images.values()) == \ set(['img.png', 'img1.png', 'simg.png', 'svgimg.svg']) app._warning.reset() latexbuilder = LaTeXBuilder(app) latexbuilder.post_process_images(tree) assert image_uri_message in app._warning.content[-1] assert set(latexbuilder.images.keys()) == \ set(['subdir/img.png', 'subdir/simg.png', 'img.png', 'img.pdf', 'svgimg.pdf']) assert set(latexbuilder.images.values()) == \ set(['img.pdf', 'img.png', 'img1.png', 'simg.png', 'svgimg.pdf'])
def write_doc(self, docname, doctree): for node in doctree.traverse(nodes.reference): # add ``target=_blank`` attributes to external links if node.get('internal') is None and 'refuri' in node: node['target'] = '_blank' StandaloneHTMLBuilder.write_doc(self, docname, doctree)
def test_images(): assert warning_emitted('images', 'image file not readable: foo.png') assert warning_emitted( 'images', 'nonlocal image URI found: ' 'http://www.python.org/logo.png') tree = env.get_doctree('images') app._warning.reset() htmlbuilder = StandaloneHTMLBuilder(app) htmlbuilder.imgpath = 'dummy' htmlbuilder.post_process_images(tree) assert set(htmlbuilder.images.keys()) == \ set(['subdir/img.png', 'img.png', 'subdir/simg.png', 'svgimg.svg', 'img.foo.png']) assert set(htmlbuilder.images.values()) == \ set(['img.png', 'img1.png', 'simg.png', 'svgimg.svg', 'img.foo.png']) app._warning.reset() latexbuilder = LaTeXBuilder(app) latexbuilder.post_process_images(tree) assert set(latexbuilder.images.keys()) == \ set(['subdir/img.png', 'subdir/simg.png', 'img.png', 'img.pdf', 'svgimg.pdf', 'img.foo.png']) assert set(latexbuilder.images.values()) == \ set(['img.pdf', 'img.png', 'img1.png', 'simg.png', 'svgimg.pdf', 'img.foo.png'])
def test_images(): assert warning_emitted('images.txt', 'image file not readable: foo.png') assert warning_emitted('images.txt', 'nonlocal image URI found: ' 'http://www.python.org/logo.png') tree = env.get_doctree('images') app._warning.reset() htmlbuilder = StandaloneHTMLBuilder(app, env) htmlbuilder.post_process_images(tree) assert "no matching candidate for image URI u'foo.*'" in \ app._warning.content[-1] assert set(htmlbuilder.images.keys()) == \ set(['subdir/img.png', 'img.png', 'subdir/simg.png', 'svgimg.svg']) assert set(htmlbuilder.images.values()) == \ set(['img.png', 'img1.png', 'simg.png', 'svgimg.svg']) app._warning.reset() latexbuilder = LaTeXBuilder(app, env) latexbuilder.post_process_images(tree) assert "no matching candidate for image URI u'foo.*'" in \ app._warning.content[-1] assert set(latexbuilder.images.keys()) == \ set(['subdir/img.png', 'subdir/simg.png', 'img.png', 'img.pdf', 'svgimg.pdf']) assert set(latexbuilder.images.values()) == \ set(['img.pdf', 'img.png', 'img1.png', 'simg.png', 'svgimg.pdf'])
def init(self): StandaloneHTMLBuilder.init(self) # the output files for epub must be .html only self.out_suffix = '.xhtml' self.link_suffix = '.xhtml' self.playorder = 0 self.tocid = 0 self.use_index = self.get_builder_config('use_index', 'epub')
def init(self): StandaloneHTMLBuilder.init(self) # the output files for HTML help must be .html only self.out_suffix = '.html' # determine the correct locale setting locale = chm_locales.get(self.config.language) if locale is not None: self.lcid, self.encoding = locale
def write_doc(self, docname, doctree): """Write one document file. This method is overwritten in order to fix fragment identifiers and to add visible external links. """ self.fix_ids(doctree) self.add_visible_links(doctree, self.config.epub_show_urls) StandaloneHTMLBuilder.write_doc(self, docname, doctree)
def handle_page(self, pagename, addctx, templatename='page.html', outfilename=None, event_arg=None): """Create a rendered page. This method is overwritten for genindex pages in order to fix href link attributes. """ if pagename.startswith('genindex'): self.fix_genindex(addctx['genindexentries']) StandaloneHTMLBuilder.handle_page(self, pagename, addctx, templatename, outfilename, event_arg)
def handle_page(self, pagename, addctx, templatename="page.html", outfilename=None, event_arg=None): """Create a rendered page. This method is overwritten for genindex pages in order to fix href link attributes. """ if pagename.startswith("genindex"): self.fix_genindex(addctx["genindexentries"]) addctx["doctype"] = self.doctype StandaloneHTMLBuilder.handle_page(self, pagename, addctx, templatename, outfilename, event_arg)
def init(self): # type: () -> None # the output files for HTML help is .html by default self.out_suffix = '.html' self.link_suffix = '.html' StandaloneHTMLBuilder.init(self) # determine the correct locale setting locale = chm_locales.get(self.config.language) if locale is not None: self.lcid, self.encoding = locale
def init(self): # type: () -> None StandaloneHTMLBuilder.init(self) # the output files for epub must be .html only self.out_suffix = '.xhtml' self.link_suffix = '.xhtml' self.playorder = 0 self.tocid = 0 self.id_cache = {} # type: Dict[unicode, unicode] self.use_index = self.get_builder_config('use_index', 'epub')
def write_doc(self, docname, doctree): # type: (unicode, nodes.Node) -> None """Write one document file. This method is overwritten in order to fix fragment identifiers and to add visible external links. """ self.fix_ids(doctree) self.add_visible_links(doctree, self.config.epub_show_urls) StandaloneHTMLBuilder.write_doc(self, docname, doctree)
def test_images(): assert ('image file not readable: foo.png' in app._warning.getvalue()) tree = env.get_doctree('images') htmlbuilder = StandaloneHTMLBuilder(app) htmlbuilder.set_environment(app.env) htmlbuilder.init() htmlbuilder.imgpath = 'dummy' htmlbuilder.post_process_images(tree) assert set(htmlbuilder.images.keys()) == \ set(['subdir/img.png', 'img.png', 'subdir/simg.png', 'svgimg.svg', 'img.foo.png']) assert set(htmlbuilder.images.values()) == \ set(['img.png', 'img1.png', 'simg.png', 'svgimg.svg', 'img.foo.png']) latexbuilder = LaTeXBuilder(app) latexbuilder.set_environment(app.env) latexbuilder.init() latexbuilder.post_process_images(tree) assert set(latexbuilder.images.keys()) == \ set(['subdir/img.png', 'subdir/simg.png', 'img.png', 'img.pdf', 'svgimg.pdf', 'img.foo.png']) assert set(latexbuilder.images.values()) == \ set(['img.pdf', 'img.png', 'img1.png', 'simg.png', 'svgimg.pdf', 'img.foo.png'])
def test_images(app): app.build() assert ('image file not readable: foo.png' in app._warning.getvalue()) tree = app.env.get_doctree('images') htmlbuilder = StandaloneHTMLBuilder(app) htmlbuilder.set_environment(app.env) htmlbuilder.init() htmlbuilder.imgpath = 'dummy' htmlbuilder.post_process_images(tree) assert set(htmlbuilder.images.keys()) == \ set(['subdir/img.png', 'img.png', 'subdir/simg.png', 'svgimg.svg', 'img.foo.png']) assert set(htmlbuilder.images.values()) == \ set(['img.png', 'img1.png', 'simg.png', 'svgimg.svg', 'img.foo.png']) latexbuilder = LaTeXBuilder(app) latexbuilder.set_environment(app.env) latexbuilder.init() latexbuilder.post_process_images(tree) assert set(latexbuilder.images.keys()) == \ set(['subdir/img.png', 'subdir/simg.png', 'img.png', 'img.pdf', 'svgimg.pdf', 'img.foo.png']) assert set(latexbuilder.images.values()) == \ set(['img.pdf', 'img.png', 'img1.png', 'simg.png', 'svgimg.pdf', 'img.foo.png'])
def handle_page(self, pagename, addctx, templatename='page.html', outfilename=None, event_arg=None): # type: (unicode, Dict, unicode, unicode, Any) -> None """Create a rendered page. This method is overwritten for genindex pages in order to fix href link attributes. """ if pagename.startswith('genindex'): if not self.use_index: return self.fix_genindex(addctx['genindexentries']) addctx['doctype'] = self.doctype StandaloneHTMLBuilder.handle_page(self, pagename, addctx, templatename, outfilename, event_arg)
def handle_page( self, docname, addctx, templatename="page.html", outfilename=None, event_arg=None, ): self.toctree.initialize(self.env) lineage = self._get_page_lineage(docname) processed_lineage = self._process_page_lineage(docname, lineage) addctx["lineage"] = processed_lineage StandaloneHTMLBuilder.handle_page(self, docname, addctx, templatename=templatename, outfilename=outfilename, event_arg=event_arg)
def handle_page(self, pagename, addctx, templatename='page.html', outfilename=None, event_arg=None): # type: (unicode, Dict, unicode, unicode, Any) -> None """Create a rendered page. This method is overwritten for genindex pages in order to fix href link attributes. """ if pagename.startswith('genindex') and 'genindexentries' in addctx: if not self.use_index: return self.fix_genindex(addctx['genindexentries']) addctx['doctype'] = self.doctype StandaloneHTMLBuilder.handle_page(self, pagename, addctx, templatename, outfilename, event_arg)
def test_get_toc_for_only(app): app.build() builder = StandaloneHTMLBuilder(app) toctree = TocTree(app.env).get_toc_for('index', builder) assert_node(toctree, [bullet_list, ([list_item, (compact_paragraph, # [0][0] [bullet_list, (addnodes.toctree, # [0][1][0] list_item, # [0][1][1] list_item)])], # [0][1][2] [list_item, (compact_paragraph, # [1][0] [bullet_list, (addnodes.toctree, addnodes.toctree)])], [list_item, compact_paragraph])]) # [2][0] assert_node(toctree[0][0], [compact_paragraph, reference, "Welcome to Sphinx Tests’s documentation!"]) assert_node(toctree[0][1][1], ([compact_paragraph, reference, "Section for HTML"], [bullet_list, addnodes.toctree])) assert_node(toctree[0][1][2], ([compact_paragraph, reference, "subsection"], [bullet_list, list_item, compact_paragraph, reference, "subsubsection"])) assert_node(toctree[1][0], [compact_paragraph, reference, "Test for issue #1157"]) assert_node(toctree[2][0], [compact_paragraph, reference, "Indices and tables"])
def write(self, build_docnames, updated_docnames, method='update'): names = build_docnames and updated_docnames and \ build_docnames + updated_docnames or \ build_docnames or updated_docnames if 'index' not in names: names.append('index') for docname in names: doctree = self.env.get_doctree(docname) nodes = doctree.traverse(addnodes.toctree) if nodes: self.toctrees[docname] = nodes StandaloneHTMLBuilder.write( self, build_docnames, updated_docnames, method=method )
def write_doc(self, docname, doctree): """Write one document file. This method is overwritten in order to fix fragment identifiers and to add visible external links. """ self.fix_ids(doctree) self.add_visible_links(doctree) return StandaloneHTMLBuilder.write_doc(self, docname, doctree)
def from_node(cls, node: mcqnodes.mcq_choice_feedback, builder: Builder) -> "McqFeedback": """Extract data from a mcq_choice_feedback node.""" return cls( is_correct=node.get("is_correct"), text=node.astext(), html=builder.render_partial(node.children[0])["fragment"], )
def init(self): StandaloneHTMLBuilder.init(self) # Pull project data from conf.py if it exists context = self.config.html_context if context.has_key('current_version'): self.version = context['current_version'] if context.has_key('slug'): self.project = context['slug'] self.storage = WebStorage(builder=self) # add our custom bits self.script_files.append('_static/jquery.pageslide.js') self.script_files.append('_static/websupport2-bundle.js') self.css_files.append('_static/websupport2.css') self.css_files.append('_static/sphinxweb.css') self.css_files.append('_static/jquery.pageslide.css')
def test_images(): assert warning_emitted("images", "image file not readable: foo.png") assert warning_emitted("images", "nonlocal image URI found: " "http://www.python.org/logo.png") tree = env.get_doctree("images") app._warning.reset() htmlbuilder = StandaloneHTMLBuilder(app) htmlbuilder.imgpath = "dummy" htmlbuilder.post_process_images(tree) assert set(htmlbuilder.images.keys()) == set( ["subdir/img.png", "img.png", "subdir/simg.png", "svgimg.svg", "img.foo.png"] ) assert set(htmlbuilder.images.values()) == set(["img.png", "img1.png", "simg.png", "svgimg.svg", "img.foo.png"]) app._warning.reset() latexbuilder = LaTeXBuilder(app) latexbuilder.post_process_images(tree) assert set(latexbuilder.images.keys()) == set( ["subdir/img.png", "subdir/simg.png", "img.png", "img.pdf", "svgimg.pdf", "img.foo.png"] ) assert set(latexbuilder.images.values()) == set( ["img.pdf", "img.png", "img1.png", "simg.png", "svgimg.pdf", "img.foo.png"] )
def builder_inited(app): """Update the Sphinx builder. :param sphinx.application.Sphinx app: Sphinx application object. """ # Add this extension's _templates directory to Sphinx. templates_dir = os.path.join(os.path.dirname(__file__), '_templates') app.builder.templates.pathchain.insert(0, templates_dir) app.builder.templates.loaders.insert( 0, SphinxFileSystemLoader(templates_dir)) app.builder.templates.templatepathlen += 1 # Add versions.html to sidebar. if '**' not in app.config.html_sidebars: if 'html_sidebars' in StandaloneHTMLBuilder( app).get_theme_config()[1].keys(): app.config.html_sidebars['**'] = StandaloneHTMLBuilder( app).get_theme_config()[1]['html_sidebars'] + [ 'versions.html' ] else: app.config.html_sidebars['**'] = ['versions.html'] elif 'versions.html' not in app.config.html_sidebars['**']: app.config.html_sidebars['**'].append('versions.html')
def from_node(cls, node: mcqnodes.mcq, builder: Builder) -> "McqQuestion": """Extract data from an mcq node.""" # The prompt of the question is stored in mcq_body body_index = node.first_child_matching_class(mcqnodes.mcq_body) question_body = node.children[body_index] return McqQuestion( id=node.get("ids", [""])[0], text=question_body.astext(), html=builder.render_partial(question_body)["fragment"], answer=node.get("answer"), show_feedback=node.get("show_feedback"), numbered=node.get("numbered"), )
def test_images(app): app.build() tree = app.env.get_doctree('images') htmlbuilder = StandaloneHTMLBuilder(app) htmlbuilder.set_environment(app.env) htmlbuilder.init() htmlbuilder.imgpath = 'dummy' htmlbuilder.post_process_images(tree) assert set(htmlbuilder.images.keys()) == \ {'subdir/img.png', 'img.png', 'subdir/simg.png', 'svgimg.svg', 'img.foo.png'} assert set(htmlbuilder.images.values()) == \ {'img.png', 'img1.png', 'simg.png', 'svgimg.svg', 'img.foo.png'} latexbuilder = LaTeXBuilder(app) latexbuilder.set_environment(app.env) latexbuilder.init() latexbuilder.post_process_images(tree) assert set(latexbuilder.images.keys()) == \ {'subdir/img.png', 'subdir/simg.png', 'img.png', 'img.pdf', 'svgimg.pdf', 'img.foo.png'} assert set(latexbuilder.images.values()) == \ {'img.pdf', 'img.png', 'img1.png', 'simg.png', 'svgimg.pdf', 'img.foo.png'}
def from_node(cls, node: mcqnodes.mcq_choice, builder: Builder) -> "McqChoice": """Extract data from a mcq_choice node.""" # Find children of mcq_choice that aren't feedback. # FIXME: this is a bad idea. We should create separate node for value of # choice so we can separate it from feedback not_feedback = [ child for child in node.children if type(child) is not mcqnodes.mcq_choice_feedback ] # Create a node so we can render not_feedback nodes choice_body = nodes.container("", classes=[]) choice_body += not_feedback return cls( text=choice_body.astext(), html=builder.render_partial(choice_body)["fragment"], )
def init(self): # type: () -> None StandaloneHTMLBuilder.init(self) self.out_suffix = '.html' self.link_suffix = '.html'
def init(self): StandaloneHTMLBuilder.init(self) # the output files for HTML help must be .html only self.out_suffix = '.html'
def write_doc(self, docname, doctree): mathjax.counter = mathjax.ExpressionNumbers() StandaloneHTMLBuilder.write_doc(self, docname, doctree)
def init(self): StandaloneHTMLBuilder.init(self) self.out_suffix = '.html'
def init(self): StandaloneHTMLBuilder.init(self) finalize_media(self)
def init(self): # type: () -> None StandaloneHTMLBuilder.init(self) # the output files for HTML help must be .html only self.out_suffix = '.html' self.link_suffix = '.html'
def __init__(self, *args, **kwargs): StandaloneHTMLBuilder.__init__(self, *args, **kwargs) self.toctrees = {} self.index_node = nodes.list_item('', addnodes.compact_paragraph(''))
def init(self): StandaloneHTMLBuilder.init(self) # the output files for mobi must be .html only self.out_suffix = '.html' self.playorder = 0
def handle_page(self, pagename, addctx, templatename='page.html', outfilename=None, event_arg=None): self.toctree.initialize(self.env) StandaloneHTMLBuilder.handle_page(self, pagename, addctx, templatename=templatename, outfilename=outfilename, event_arg=event_arg)
def init(self): StandaloneHTMLBuilder.init(self) finalize_comment_media(self)
def init(self): StandaloneHTMLBuilder.init(self)
def __init__(self, app): StandaloneHTMLBuilder.__init__(self, app)
def init(self): StandaloneHTMLBuilder.init(self) self.toctree = Toctree(self._render_title, self.get_relative_uri)