def setup(app): from sphinx import __version__ revisions = map(lambda x: x.isdigit() and int(x) or 0, __version__.split('.')) major, minor = revisions[0], revisions[1] if major * 10 + minor < 6: raise Exception("You should upgrade Sphinx to version 0.6 or higher") from sphinx.writers.html import HTMLTranslator, BaseTranslator import pickle # load unique_path dict: comments_path_pickle_filename = "comments_path.pickle" if os.path.exists(comments_path_pickle_filename): comments_path_pickle_file = open(comments_path_pickle_filename, 'r') comments_path_dict = pickle.load(comments_path_pickle_file) comments_path_pickle_file.close() else: comments_path_dict = {} this_build_comments_path_dict = {} def save_comments_path_dict(): comments_path_pickle_file = open(comments_path_pickle_filename, 'w') pickle.dump(comments_path_dict, comments_path_pickle_file) comments_path_pickle_file.close() import atexit atexit.register(save_comments_path_dict) def depart_title_new(self, node): res = old_depart_title(self, node) # call the original depart_title. if self.builder.globalcontext.get('builder') == 'html': parent_class_name = node.parent.__class__.__name__ if parent_class_name == 'section' and self.section_level == 2: title_id = "/" + node.parent.attributes['ids'][0] link_anchor = "#" + node.parent.attributes['ids'][0] ## paths should be unique: ## -> build a database (pickled dict) with already used paths and ## create a new unique path if already used. title_path = self.document['source'] path_start = title_path.find('%ssource%s' % (os.sep, os.sep)) title_path = title_path[path_start + 8:].replace('.rst', '') if title_id not in this_build_comments_path_dict: # first time we process this path title_id = comments_path_dict.get(title_id, title_id) this_build_comments_path_dict[title_id] = title_id comments_path_dict[title_id] = title_id else: # it's a double title_id = u"""/%s%s""" % ( title_path, title_id, ) this_build_comments_path_dict[title_id] = title_id comments_path_dict[title_id] = title_id # we need a uniq attribute that never changes, but the permalink will be computed after rendering # the page so we can figure out the final URL, up to the correct anchor (Echo generates a default # permalink using the document.location if it's missing, but that will cause twitter post etc. to # appear on each section, as it is not able to distinguish sections on the same page! # See http://wiki.js-kit.com/Echo+-+Install+-+A+custom+website#Settinguptheuniqandpermalinkattributes # See the runtime computation in source/.templates/layout.html self.body.append( u"""<div class="js-kit-comments" uniq="%s" permalink_anchor="%s" ></div>""" % (title_id, link_anchor)) return res if js_kit_comments: old_depart_title = HTMLTranslator.depart_title HTMLTranslator.depart_title = depart_title_new app.add_directive('end_foreword', end_foreword_directive, 1, (0, 0, 0)) app.add_directive('begin_conclusion', begin_conclusion_directive, 1, (0, 0, 0))
html_static_path = ['_static'] def setup(app): # RTD does not line wrap CSV tables, so we override this behavior. app.add_stylesheet("theme_overrides.css") # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. #html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. # Better to disable this to prevent alteration of command-line arguments # Sphinx <1.6 use `html_use_smartypants` and >=1.6 use `smartquotes` from sphinx import __version__ as sphinx_version sphinx_version_parts = [int(i) for i in sphinx_version.split('.')] if sphinx_version_parts[0] <= 1 and sphinx_version_parts[1] < 6: html_use_smartypants = False else: smartquotes = False # Custom sidebar templates, maps document names to template names. #html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. #html_additional_pages = {} # If false, no module index is generated. #html_domain_indices = True
# The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. html_favicon = '../img/favicon.ico' # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['_static'] # ensure quotes and dashes are preserved and not converted to lang-specific # entities (fix issue#250). done by disabling `html_use_smartypants` on Sphinx # version older than 1.6 and by disabling `smartquotes` on newer versions. from sphinx import __version__ as sphinx_version sphinx_version_parts = [int(i) for i in sphinx_version.split('.')] if sphinx_version_parts[0] <= 1 and sphinx_version_parts[1] < 6: html_use_smartypants = False else: smartquotes = False # -- Options for HTMLHelp output ------------------------------------------ # Output file base name for HTML help builder. htmlhelp_basename = 'Modulesdoc' # -- Options for LaTeX output --------------------------------------------- latex_elements = { # The paper size ('letterpaper' or 'a4paper'). #
def setup(app): from sphinx import __version__ revisions = map(lambda x: x.isdigit() and int(x) or 0, __version__.split('.')) major, minor = revisions[0], revisions[1] if major*10+minor < 6: raise Exception("You should upgrade Sphinx to version 0.6 or higher") from sphinx.writers.html import HTMLTranslator, BaseTranslator import pickle # load unique_path dict: comments_path_pickle_filename = "comments_path.pickle" if os.path.exists(comments_path_pickle_filename): comments_path_pickle_file = open(comments_path_pickle_filename, 'r') comments_path_dict = pickle.load(comments_path_pickle_file) comments_path_pickle_file.close() else: comments_path_dict = {} this_build_comments_path_dict = {} def save_comments_path_dict(): comments_path_pickle_file = open(comments_path_pickle_filename, 'w') pickle.dump(comments_path_dict, comments_path_pickle_file) comments_path_pickle_file.close() import atexit atexit.register(save_comments_path_dict) def depart_title_new(self, node): res = old_depart_title(self, node) # call the original depart_title. if self.builder.globalcontext.get('builder') == 'html': parent_class_name = node.parent.__class__.__name__ if parent_class_name == 'section' and self.section_level == 2: title_id = "/" + node.parent.attributes['ids'][0] link_anchor = "#" + node.parent.attributes['ids'][0] ## paths should be unique: ## -> build a database (pickled dict) with already used paths and ## create a new unique path if already used. title_path = self.document['source'] path_start = title_path.find('%ssource%s' % (os.sep, os.sep)) title_path = title_path[path_start+8:].replace('.rst', '') if title_id not in this_build_comments_path_dict: # first time we process this path title_id = comments_path_dict.get(title_id, title_id) this_build_comments_path_dict[title_id] = title_id comments_path_dict[title_id] = title_id else: # it's a double title_id = u"""/%s%s""" % (title_path, title_id, ) this_build_comments_path_dict[title_id] = title_id comments_path_dict[title_id] = title_id # we need a uniq attribute that never changes, but the permalink will be computed after rendering # the page so we can figure out the final URL, up to the correct anchor (Echo generates a default # permalink using the document.location if it's missing, but that will cause twitter post etc. to # appear on each section, as it is not able to distinguish sections on the same page! # See http://wiki.js-kit.com/Echo+-+Install+-+A+custom+website#Settinguptheuniqandpermalinkattributes # See the runtime computation in source/.templates/layout.html self.body.append(u"""<div class="js-kit-comments" uniq="%s" permalink_anchor="%s" ></div>""" % (title_id, link_anchor)) return res if js_kit_comments: old_depart_title = HTMLTranslator.depart_title HTMLTranslator.depart_title = depart_title_new app.add_directive('end_foreword', end_foreword_directive, 1, (0, 0, 0)) app.add_directive('begin_conclusion', begin_conclusion_directive, 1, (0, 0, 0))