def new_document(self): # type: () -> nodes.document """Creates a new document object which having a special reporter object good for logging. """ document = standalone.Reader.new_document(self) reporter = document.reporter document.reporter = LoggingReporter.from_reporter(reporter) document.reporter.set_source(self.source) return document
def new_document(self) -> nodes.document: """Creates a new document object which having a special reporter object good for logging. """ document = super().new_document() # substitute transformer document.transformer = SphinxTransformer(document) document.transformer.set_environment(self.settings.env) # substitute reporter reporter = document.reporter document.reporter = LoggingReporter.from_reporter(reporter) return document
def new_document(self): # type: () -> nodes.document """Creates a new document object which having a special reporter object good for logging. """ document = standalone.Reader.new_document(self) # substitute transformer document.transformer = SphinxTransformer(document) document.transformer.set_environment(self.env) # substitute reporter reporter = document.reporter document.reporter = LoggingReporter.from_reporter(reporter) return document
def new_document(self): # type: () -> nodes.document """Creates a new document object which having a special reporter object good for logging. """ document = standalone.Reader.new_document(self) # substitute transformer document.transformer = SphinxTransformer(document) document.transformer.set_environment(self.env) # substitute reporter reporter = document.reporter document.reporter = LoggingReporter.from_reporter(reporter) return document
def new_document(self) -> nodes.document: """ Creates a new document object which has a special reporter object good for logging. """ document = super().new_document() document.__class__ = addnodes.document # replace the class with patched version # substitute transformer document.transformer = SphinxTransformer(document) document.transformer.set_environment(self.settings.env) # substitute reporter reporter = document.reporter document.reporter = LoggingReporter.from_reporter(reporter) return document
def apply(self): config = self.document.settings.env.config settings, source = self.document.settings, self.document['source'] codes = resource_filename(__name__, 'codes.json') replacements = json.load(open(codes, encoding='utf-8')) to_handle = (set(replacements.keys()) - set(self.document.substitution_defs)) for ref in self.document.traverse(nodes.substitution_reference): refname = ref['refname'] if refname in to_handle: text = replacements[refname] doc = new_document(source, settings) doc.reporter = LoggingReporter.from_reporter(doc.reporter) self.parser.parse(text, doc) substitution = doc.next_node() # Remove encapsulating paragraph if isinstance(substitution, nodes.paragraph): substitution = substitution.next_node() ref.replace_self(substitution)
def apply(self): # type: () -> None config = self.document.settings.env.config settings, source = self.document.settings, self.document['source'] global_substitutions = config['global_substitutions'] to_handle = (set(global_substitutions.keys()) - set(self.document.substitution_defs)) for ref in self.document.traverse(nodes.substitution_reference): refname = ref['refname'] if refname in to_handle: text = global_substitutions[refname] doc = new_document(source, settings) doc.reporter = LoggingReporter.from_reporter(doc.reporter) self.parser.parse(text, doc) substitution = doc.next_node() # Remove encapsulating paragraph if isinstance(substitution, nodes.paragraph): substitution = substitution.next_node() ref.replace_self(substitution)