# -*- coding: utf-8 -*- """ sphinx.environment ~~~~~~~~~~~~~~~~~~ Global creation environment. :copyright: Copyright 2007-2010 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ import re import os import sys import time import types import codecs import imghdr import string import posixpath import cPickle as pickle from os import path from glob import glob from itertools import izip, groupby from docutils import nodes from docutils.io import FileInput, NullOutput from docutils.core import Publisher from docutils.utils import Reporter, relative_path, new_document from docutils.readers import standalone from docutils.parsers.rst import roles, directives, Parser as RSTParser from docutils.parsers.rst.languages import en as english from docutils.parsers.rst.directives.html import MetaBody from docutils.writers import UnfilteredWriter from docutils.transforms import Transform from docutils.transforms.parts import ContentsFilter from sphinx import addnodes from sphinx.util import url_re, get_matching_docs, docname_join, \ FilenameUniqDict from sphinx.util.nodes import clean_astext, make_refnode, extract_messages from sphinx.util.osutil import movefile, SEP, ustrftime from sphinx.util.matching import compile_matchers from sphinx.util.pycompat import all, class_types from sphinx.errors import SphinxError, ExtensionError from sphinx.locale import _, init as init_locale fs_encoding = sys.getfilesystemencoding() or sys.getdefaultencoding() orig_role_function = roles.role orig_directive_function = directives.directive class ElementLookupError(Exception): pass default_settings = { 'embed_stylesheet': False, 'cloak_email_addresses': True, 'pep_base_url': 'http://www.python.org/dev/peps/', 'rfc_base_url': 'http://tools.ietf.org/html/', 'input_encoding': 'utf-8-sig', 'doctitle_xform': False, 'sectsubtitle_xform': False, 'halt_level': 5, } # This is increased every time an environment attribute is added # or changed to properly invalidate pickle files. ENV_VERSION = 38 default_substitutions = set([ 'version', 'release', 'today', ]) dummy_reporter = Reporter('', 4, 4) class WarningStream(object): def __init__(self, warnfunc): self.warnfunc = warnfunc def write(self, text): if text.strip(): self.warnfunc(text.strip(), None, '') class NoUri(Exception): """Raised by get_relative_uri if there is no URI available.""" pass class DefaultSubstitutions(Transform): """ Replace some substitutions if they aren't defined in the document. """ # run before the default Substitutions default_priority = 210 def apply(self): config = self.document.settings.env.config # only handle those not otherwise defined in the document to_handle = default_substitutions - set(self.document.substitution_defs) for ref in self.document.traverse(nodes.substitution_reference): refname = ref['refname'] if refname in to_handle: text = config[refname] if refname == 'today' and not text: # special handling: can also specify a strftime format text = ustrftime(config.today_fmt or _('%B %d, %Y')) ref.replace_self(nodes.Text(text, text)) class MoveModuleTargets(Transform): """ Move module targets that are the first thing in a section to the section title. XXX Python specific """ default_priority = 210 def apply(self): for node in self.document.traverse(nodes.target): if not node['ids']: continue if (node.has_key('ismod') and node.parent.__class__ is nodes.section and # index 0 is the section title node node.parent.index(node) == 1): node.parent['ids'][0:0] = node['ids'] node.parent.remove(node) class HandleCodeBlocks(Transform): """ Several code block related transformations. """ default_priority = 210 def apply(self): # move doctest blocks out of blockquotes for node in self.document.traverse(nodes.block_quote): if all(isinstance(child, nodes.doctest_block) for child in node.children): node.replace_self(node.children) # combine successive doctest blocks #for node in self.document.traverse(nodes.doctest_block): # if node not in node.parent.children: # continue # parindex = node.parent.index(node) # while len(node.parent) > parindex+1 and \ # isinstance(node.parent[parindex+1], nodes.doctest_block): # node[0] = nodes.Text(node[0] + '\n\n' + # node.parent[parindex+1][0]) # del node.parent[parindex+1] class SortIds(Transform): """ Sort secion IDs so that the "id[0-9]+" one comes last. """ default_priority = 261 def apply(self): for node in self.document.traverse(nodes.section): if len(node['ids']) > 1 and node['ids'][0].startswith('id'): node['ids'] = node['ids'][1:] + [node['ids'][0]] class CitationReferences(Transform): """ Replace citation references by pending_xref nodes before the default docutils transform tries to resolve them. """ default_priority = 619 def apply(self): for citnode in self.document.traverse(nodes.citation_reference): cittext = citnode.astext() refnode = addnodes.pending_xref(cittext, reftype='citation', reftarget=cittext) refnode += nodes.Text('[' + cittext + ']') citnode.parent.replace(citnode, refnode) class Locale(Transform): """ Replace translatable nodes with their translated doctree. """ default_priority = 0 def apply(self): env = self.document.settings.env settings, source = self.document.settings, self.document['source'] # XXX check if this is reliable assert source.startswith(env.srcdir) docname = posixpath.splitext(source[len(env.srcdir):].lstrip('/'))[0] section = docname.split(SEP, 1)[0] # fetch translations dirs = [path.join(env.srcdir, x) for x in env.config.locale_dirs] catalog, has_catalog = init_locale(dirs, env.config.language, section) if not has_catalog: return parser = RSTParser() for node, msg in extract_messages(self.document): patch = new_document(source, settings) msgstr = catalog.gettext(msg) # XXX add marker to untranslated parts if not msgstr or msgstr == msg: # as-of-yet untranslated continue parser.parse(msgstr, patch) patch = patch[0] #XXX doctest and other block markup if not isinstance(patch, nodes.paragraph): continue # skip for now for child in patch.children: # update leaves child.parent = node node.children = patch.children class SphinxStandaloneReader(standalone.Reader): """ Add our own transforms. """ transforms = [Locale, CitationReferences, DefaultSubstitutions, MoveModuleTargets, HandleCodeBlocks, SortIds] def get_transforms(self): return standalone.Reader.get_transforms(self) + self.transforms class SphinxDummyWriter(UnfilteredWriter): supported = ('html',) # needed to keep "meta" nodes def translate(self): pass class SphinxContentsFilter(ContentsFilter): """ Used with BuildEnvironment.add_toc_from() to discard cross-file links within table-of-contents link nodes. """ def visit_pending_xref(self, node): text = node.astext() self.parent.append(nodes.literal(text, text)) raise nodes.SkipNode def visit_image(self, node): raise nodes.SkipNode class BuildEnvironment: """ The environment in which the ReST files are translated. Stores an inventory of cross-file targets and provides doctree transformations to resolve links to them. """ # --------- ENVIRONMENT PERSISTENCE ---------------------------------------- @staticmethod def frompickle(config, filename): picklefile = open(filename, 'rb') try: env = pickle.load(picklefile) finally: picklefile.close() if env.version != ENV_VERSION: raise IOError('env version not current') env.config.values = config.values return env def topickle(self, filename): # remove unpicklable attributes warnfunc = self._warnfunc self.set_warnfunc(None) values = self.config.values del self.config.values domains = self.domains del self.domains # first write to a temporary file, so that if dumping fails, # the existing environment won't be overwritten picklefile = open(filename + '.tmp', 'wb') # remove potentially pickling-problematic values from config for key, val in vars(self.config).items(): if key.startswith('_') or \ isinstance(val, types.ModuleType) or \ isinstance(val, types.FunctionType) or \ isinstance(val, class_types): del self.config[key] try: pickle.dump(self, picklefile, pickle.HIGHEST_PROTOCOL) finally: picklefile.close() movefile(filename + '.tmp', filename) # reset attributes self.domains = domains self.config.values = values self.set_warnfunc(warnfunc) # --------- ENVIRONMENT INITIALIZATION ------------------------------------- def __init__(self, srcdir, doctreedir, config): self.doctreedir = doctreedir self.srcdir = srcdir self.config = config # the application object; only set while update() runs self.app = None # all the registered domains, set by the application self.domains = {} # the docutils settings for building self.settings = default_settings.copy() self.settings['env'] = self # the function to write warning messages with self._warnfunc = None # this is to invalidate old pickles self.version = ENV_VERSION # All "docnames" here are /-separated and relative and exclude # the source suffix. self.found_docs = set() # contains all existing docnames self.all_docs = {} # docname -> mtime at the time of build # contains all built docnames self.dependencies = {} # docname -> set of dependent file # names, relative to documentation root # File metadata self.metadata = {} # docname -> dict of metadata items # TOC inventory self.titles = {} # docname -> title node self.longtitles = {} # docname -> title node; only different if # set differently with title directive self.tocs = {} # docname -> table of contents nodetree self.toc_num_entries = {} # docname -> number of real entries # used to determine when to show the TOC # in a sidebar (don't show if it's only one item) self.toc_secnumbers = {} # docname -> dict of sectionid -> number self.toctree_includes = {} # docname -> list of toctree includefiles self.files_to_rebuild = {} # docname -> set of files # (containing its TOCs) to rebuild too self.glob_toctrees = set() # docnames that have :glob: toctrees self.numbered_toctrees = set() # docnames that have :numbered: toctrees # domain-specific inventories, here to be pickled self.domaindata = {} # domainname -> domain-specific dict # Other inventories self.citations = {} # citation name -> docname, labelid self.indexentries = {} # docname -> list of # (type, string, target, aliasname) self.versionchanges = {} # version -> list of (type, docname, # lineno, module, descname, content) # these map absolute path -> (docnames, unique filename) self.images = FilenameUniqDict() self.dlfiles = FilenameUniqDict() # temporary data storage while reading a document self.temp_data = {} def set_warnfunc(self, func): self._warnfunc = func self.settings['warning_stream'] = WarningStream(func) def warn(self, docname, msg, lineno=None): # strange argument order is due to backwards compatibility self._warnfunc(msg, (docname, lineno)) def clear_doc(self, docname): """Remove all traces of a source file in the inventory.""" if docname in self.all_docs: self.all_docs.pop(docname, None) self.metadata.pop(docname, None) self.dependencies.pop(docname, None) self.titles.pop(docname, None) self.longtitles.pop(docname, None) self.tocs.pop(docname, None) self.toc_secnumbers.pop(docname, None) self.toc_num_entries.pop(docname, None) self.toctree_includes.pop(docname, None) self.indexentries.pop(docname, None) self.glob_toctrees.discard(docname) self.numbered_toctrees.discard(docname) self.images.purge_doc(docname) self.dlfiles.purge_doc(docname) for subfn, fnset in self.files_to_rebuild.items(): fnset.discard(docname) if not fnset: del self.files_to_rebuild[subfn] for key, (fn, _) in self.citations.items(): if fn == docname: del self.citations[key] for version, changes in self.versionchanges.items(): new = [change for change in changes if change[1] != docname] changes[:] = new for domain in self.domains.values(): domain.clear_doc(docname) def doc2path(self, docname, base=True, suffix=None): """Return the filename for the document name. If *base* is True, return absolute path under self.srcdir. If *base* is None, return relative path to self.srcdir. If *base* is a path string, return absolute path under that. If *suffix* is not None, add it instead of config.source_suffix. """ docname = docname.replace(SEP, path.sep) suffix = suffix or self.config.source_suffix if base is True: return path.join(self.srcdir, docname) + suffix elif base is None: return docname + suffix else: return path.join(base, docname) + suffix def relfn2path(self, filename, docname=None): """Return paths to a file referenced from a document, relative to documentation root and absolute. Absolute filenames are relative to the source dir, while relative filenames are relative to the dir of the containing document. """ if filename.startswith('/') or filename.startswith(os.sep): rel_fn = filename[1:] else: docdir = path.dirname(self.doc2path(docname or self.docname, base=None)) rel_fn = path.join(docdir, filename) try: return rel_fn, path.join(self.srcdir, rel_fn) except UnicodeDecodeError: # the source directory is a bytestring with non-ASCII characters; # let's try to encode the rel_fn in the file system encoding enc_rel_fn = rel_fn.encode(sys.getfilesystemencoding()) return rel_fn, path.join(self.srcdir, enc_rel_fn) def find_files(self, config): """Find all source files in the source dir and put them in self.found_docs. """ matchers = compile_matchers( config.exclude_patterns[:] + config.exclude_trees + [d + config.source_suffix for d in config.unused_docs] + ['**/' + d for d in config.exclude_dirnames] + ['**/_sources'] ) self.found_docs = set(get_matching_docs( self.srcdir, config.source_suffix, exclude_matchers=matchers)) def get_outdated_files(self, config_changed): """Return (added, changed, removed) sets.""" # clear all files no longer present removed = set(self.all_docs) - self.found_docs added = set() changed = set() if config_changed: # config values affect e.g. substitutions added = self.found_docs else: for docname in self.found_docs: if docname not in self.all_docs: added.add(docname) continue # if the doctree file is not there, rebuild if not path.isfile(self.doc2path(docname, self.doctreedir, '.doctree')): changed.add(docname) continue # check the mtime of the document mtime = self.all_docs[docname] newmtime = path.getmtime(self.doc2path(docname)) if newmtime > mtime: changed.add(docname) continue # finally, check the mtime of dependencies for dep in self.dependencies.get(docname, ()): try: # this will do the right thing when dep is absolute too deppath = path.join(self.srcdir, dep) if not path.isfile(deppath): changed.add(docname) break depmtime = path.getmtime(deppath) if depmtime > mtime: changed.add(docname) break except EnvironmentError: # give it another chance changed.add(docname) break return added, changed, removed def update(self, config, srcdir, doctreedir, app=None): """(Re-)read all files new or changed since last update. Returns a summary, the total count of documents to reread and an iterator that yields docnames as it processes them. Store all environment docnames in the canonical format (ie using SEP as a separator in place of os.path.sep). """ config_changed = False if self.config is None: msg = '[new config] ' config_changed = True else: # check if a config value was changed that affects how # doctrees are read for key, descr in config.values.iteritems(): if descr[1] != 'env': continue if self.config[key] != config[key]: msg = '[config changed] ' config_changed = True break else: msg = '' # this value is not covered by the above loop because it is handled # specially by the config class if self.config.extensions != config.extensions: msg = '[extensions changed] ' config_changed = True # the source and doctree directories may have been relocated self.srcdir = srcdir self.doctreedir = doctreedir self.find_files(config) self.config = config added, changed, removed = self.get_outdated_files(config_changed) # if files were added or removed, all documents with globbed toctrees # must be reread if added or removed: changed.update(self.glob_toctrees) msg += '%s added, %s changed, %s removed' % (len(added), len(changed), len(removed)) def update_generator(): self.app = app # clear all files no longer present for docname in removed: if app: app.emit('env-purge-doc', self, docname) self.clear_doc(docname) # read all new and changed files for docname in sorted(added | changed): yield docname self.read_doc(docname, app=app) if config.master_doc not in self.all_docs: self.warn(None, 'master file %s not found' % self.doc2path(config.master_doc)) self.app = None if app: app.emit('env-updated', self) return msg, len(added | changed), update_generator() def check_dependents(self, already): to_rewrite = self.assign_section_numbers() for docname in to_rewrite: if docname not in already: yield docname # --------- SINGLE FILE READING -------------------------------------------- def warn_and_replace(self, error): """Custom decoding error handler that warns and replaces.""" linestart = error.object.rfind('\n', 0, error.start) lineend = error.object.find('\n', error.start) if lineend == -1: lineend = len(error.object) lineno = error.object.count('\n', 0, error.start) + 1 self.warn(self.docname, 'undecodable source characters, ' 'replacing with "?": %r' % (error.object[linestart+1:error.start] + '>>>' + error.object[error.start:error.end] + '<<<' + error.object[error.end:lineend]), lineno) return (u'?', error.end) def lookup_domain_element(self, type, name): """Lookup a markup element (directive or role), given its name which can be a full name (with domain). """ name = name.lower() # explicit domain given? if ':' in name: domain_name, name = name.split(':', 1) if domain_name in self.domains: domain = self.domains[domain_name] element = getattr(domain, type)(name) if element is not None: return element, [] # else look in the default domain else: def_domain = self.temp_data.get('default_domain') if def_domain is not None: element = getattr(def_domain, type)(name) if element is not None: return element, [] # always look in the std domain element = getattr(self.domains['std'], type)(name) if element is not None: return element, [] raise ElementLookupError def patch_lookup_functions(self): """Monkey-patch directive and role dispatch, so that domain-specific markup takes precedence. """ def directive(name, lang_module, document): try: return self.lookup_domain_element('directive', name) except ElementLookupError: return orig_directive_function(name, lang_module, document) def role(name, lang_module, lineno, reporter): try: return self.lookup_domain_element('role', name) except ElementLookupError: return orig_role_function(name, lang_module, lineno, reporter) directives.directive = directive roles.role = role def read_doc(self, docname, src_path=None, save_parsed=True, app=None): """Parse a file and add/update inventory entries for the doctree. If srcpath is given, read from a different source file. """ # remove all inventory entries for that file if app: app.emit('env-purge-doc', self, docname) self.clear_doc(docname) if src_path is None: src_path = self.doc2path(docname) self.temp_data['docname'] = docname # defaults to the global default, but can be re-set in a document self.temp_data['default_domain'] = \ self.domains.get(self.config.primary_domain) self.settings['input_encoding'] = self.config.source_encoding self.settings['trim_footnote_reference_space'] = \ self.config.trim_footnote_reference_space self.patch_lookup_functions() if self.config.default_role: role_fn, messages = roles.role(self.config.default_role, english, 0, dummy_reporter) if role_fn: roles._roles[''] = role_fn else: self.warn(docname, 'default role %s not found' % self.config.default_role) codecs.register_error('sphinx', self.warn_and_replace) class SphinxSourceClass(FileInput): def decode(self_, data): if isinstance(data, unicode): return data return data.decode(self_.encoding, 'sphinx') def read(self_): data = FileInput.read(self_) if app: arg = [data] app.emit('source-read', docname, arg) data = arg[0] if self.config.rst_epilog: data = data + '\n' + self.config.rst_epilog + '\n' if self.config.rst_prolog: data = self.config.rst_prolog + '\n' + data return data # publish manually pub = Publisher(reader=SphinxStandaloneReader(), writer=SphinxDummyWriter(), source_class=SphinxSourceClass, destination_class=NullOutput) pub.set_components(None, 'restructuredtext', None) pub.process_programmatic_settings(None, self.settings, None) pub.set_source(None, src_path.encode(fs_encoding)) pub.set_destination(None, None) try: pub.publish() doctree = pub.document except UnicodeError, err: raise SphinxError(str(err)) # post-processing self.filter_messages(doctree) self.process_dependencies(docname, doctree) self.process_images(docname, doctree) self.process_downloads(docname, doctree) self.process_metadata(docname, doctree) self.process_refonly_bullet_lists(docname, doctree) self.create_title_from(docname, doctree) self.note_indexentries_from(docname, doctree) self.note_citations_from(docname, doctree) self.build_toc_from(docname, doctree) for domain in self.domains.itervalues(): domain.process_doc(self, docname, doctree) # allow extension-specific post-processing if app: app.emit('doctree-read', doctree) # store time of build, for outdated files detection self.all_docs[docname] = time.time() # make it picklable doctree.reporter = None doctree.transformer = None doctree.settings.warning_stream = None doctree.settings.env = None doctree.settings.record_dependencies = None for metanode in doctree.traverse(MetaBody.meta): # docutils' meta nodes aren't picklable because the class is nested metanode.__class__ = addnodes.meta # cleanup self.temp_data.clear() if save_parsed: # save the parsed doctree doctree_filename = self.doc2path(docname, self.doctreedir, '.doctree') dirname = path.dirname(doctree_filename) if not path.isdir(dirname): os.makedirs(dirname) f = open(doctree_filename, 'wb') try: pickle.dump(doctree, f, pickle.HIGHEST_PROTOCOL) finally: f.close() else: return doctree # utilities to use while reading a document @property def docname(self): """Backwards compatible alias.""" return self.temp_data['docname'] @property def currmodule(self): """Backwards compatible alias.""" return self.temp_data.get('py:module') @property def currclass(self): """Backwards compatible alias.""" return self.temp_data.get('py:class') def new_serialno(self, category=''): """Return a serial number, e.g. for index entry targets.""" key = category + 'serialno' cur = self.temp_data.get(key, 0) self.temp_data[key] = cur + 1 return cur def note_dependency(self, filename): self.dependencies.setdefault(self.docname, set()).add(filename) def note_versionchange(self, type, version, node, lineno): self.versionchanges.setdefault(version, []).append( (type, self.temp_data['docname'], lineno, self.temp_data.get('py:module'), self.temp_data.get('object'), node.astext())) # post-processing of read doctrees def filter_messages(self, doctree): """Filter system messages from a doctree.""" filterlevel = self.config.keep_warnings and 2 or 5 for node in doctree.traverse(nodes.system_message): if node['level'] < filterlevel: node.parent.remove(node) def process_dependencies(self, docname, doctree): """Process docutils-generated dependency info.""" cwd = os.getcwd() frompath = path.join(path.normpath(self.srcdir), 'dummy') deps = doctree.settings.record_dependencies if not deps: return for dep in deps.list: # the dependency path is relative to the working dir, so get # one relative to the srcdir relpath = relative_path(frompath, path.normpath(path.join(cwd, dep))) self.dependencies.setdefault(docname, set()).add(relpath) def process_downloads(self, docname, doctree): """Process downloadable file paths. """ for node in doctree.traverse(addnodes.download_reference): targetname = node['reftarget'] rel_filename, filename = self.relfn2path(targetname, docname) self.dependencies.setdefault(docname, set()).add(rel_filename) if not os.access(filename, os.R_OK): self.warn(docname, 'download file not readable: %s' % filename, getattr(node, 'line', None)) continue uniquename = self.dlfiles.add_file(docname, filename) node['filename'] = uniquename def process_images(self, docname, doctree): """Process and rewrite image URIs.""" for node in doctree.traverse(nodes.image): # Map the mimetype to the corresponding image. The writer may # choose the best image from these candidates. The special key * is # set if there is only single candidate to be used by a writer. # The special key ? is set for nonlocal URIs. node['candidates'] = candidates = {} imguri = node['uri'] if imguri.find('://') != -1: self.warn(docname, 'nonlocal image URI found: %s' % imguri, node.line) candidates['?'] = imguri continue rel_imgpath, full_imgpath = self.relfn2path(imguri, docname) # set imgpath as default URI node['uri'] = rel_imgpath if rel_imgpath.endswith(os.extsep + '*'): for filename in glob(full_imgpath): new_imgpath = relative_path(self.srcdir, filename) if filename.lower().endswith('.pdf'): candidates['application/pdf'] = new_imgpath elif filename.lower().endswith('.svg'): candidates['image/svg+xml'] = new_imgpath else: try: f = open(filename, 'rb') try: imgtype = imghdr.what(f) finally: f.close() except (OSError, IOError), err: self.warn(docname, 'image file %s not ' 'readable: %s' % (filename, err), node.line) if imgtype: candidates['image/' + imgtype] = new_imgpath else: candidates['*'] = rel_imgpath # map image paths to unique image names (so that they can be put # into a single directory) for imgpath in candidates.itervalues(): self.dependencies.setdefault(docname, set()).add(imgpath) if not os.access(path.join(self.srcdir, imgpath), os.R_OK): self.warn(docname, 'image file not readable: %s' % imgpath, node.line) continue self.images.add_file(docname, imgpath) def process_metadata(self, docname, doctree): """Process the docinfo part of the doctree as metadata. Keep processing minimal -- just return what docutils says. """ self.metadata[docname] = md = {} try: docinfo = doctree[0] except IndexError: # probably an empty document return if docinfo.__class__ is not nodes.docinfo: # nothing to see here return for node in docinfo: # nodes are multiply inherited... if isinstance(node, nodes.authors): md['authors'] = [author.astext() for author in node] elif isinstance(node, nodes.TextElement): # e.g. author md[node.__class__.__name__] = node.astext() else: name, body = node md[name.astext()] = body.astext() del doctree[0] def process_refonly_bullet_lists(self, docname, doctree): """Change refonly bullet lists to use compact_paragraphs. Specifically implemented for 'Indices and Tables' section, which looks odd when html_compact_lists is false. """ if self.config.html_compact_lists: return class RefOnlyListChecker(nodes.GenericNodeVisitor): """Raise `nodes.NodeFound` if non-simple list item is encountered. Here 'simple' means a list item containing only a paragraph with a single reference in it. """ def default_visit(self, node): raise nodes.NodeFound def visit_bullet_list(self, node): pass def visit_list_item(self, node): children = [] for child in node.children: if not isinstance(child, nodes.Invisible): children.append(child) if len(children) != 1: raise nodes.NodeFound if not isinstance(children[0], nodes.paragraph): raise nodes.NodeFound para = children[0] if len(para) != 1: raise nodes.NodeFound if not isinstance(para[0], addnodes.pending_xref): raise nodes.NodeFound raise nodes.SkipChildren def invisible_visit(self, node): """Invisible nodes should be ignored.""" pass def check_refonly_list(node): """Check for list with only references in it.""" visitor = RefOnlyListChecker(doctree) try: node.walk(visitor) except nodes.NodeFound: return False else: return True for node in doctree.traverse(nodes.bullet_list): if check_refonly_list(node): for item in node.traverse(nodes.list_item): para = item[0] ref = para[0] compact_para = addnodes.compact_paragraph() compact_para += ref item.replace(para, compact_para) def create_title_from(self, docname, document): """Add a title node to the document (just copy the first section title), and store that title in the environment. """ titlenode = nodes.title() longtitlenode = titlenode # explicit title set with title directive; use this only for # the
and