def _create_element_from_result(domain: Domain, inv_name: Optional[str], data: InventoryItem, node: pending_xref, contnode: TextElement) -> Element: proj, version, uri, dispname = data if '://' not in uri and node.get('refdoc'): # get correct path in case of subdirectories uri = path.join(relative_path(node['refdoc'], '.'), uri) if version: reftitle = _('(in %s v%s)') % (proj, version) else: reftitle = _('(in %s)') % (proj, ) newnode = nodes.reference('', '', internal=False, refuri=uri, reftitle=reftitle) if node.get('refexplicit'): # use whatever title was given newnode.append(contnode) elif dispname == '-' or \ (domain.name == 'std' and node['reftype'] == 'keyword'): # use whatever title was given, but strip prefix title = contnode.astext() if inv_name is not None and title.startswith(inv_name + ':'): newnode.append( contnode.__class__(title[len(inv_name) + 1:], title[len(inv_name) + 1:])) else: newnode.append(contnode) else: # else use the given display name (used for :ref:) newnode.append(contnode.__class__(dispname, dispname)) return newnode
def describe_signature(self, signode: TextElement) -> None: if len(self.attrs) == 0: return self.attrs[0].describe_signature(signode) if len(self.attrs) == 1: return for attr in self.attrs[1:]: signode.append(addnodes.desc_sig_space()) attr.describe_signature(signode)
def strip_doctest_flags(self, node: TextElement) -> None: if not node.get('trim_flags', self.config.trim_doctest_flags): return source = node.rawsource source = doctest.blankline_re.sub('', source) source = doctest.doctestopt_re.sub('', source) node.rawsource = source node[:] = [nodes.Text(source)]
def parse(self, document: TextElement) -> TextElement: """Parses a text and build TextElement.""" if len(document) == 0: return document reader = TextReader(cast(Text, document.pop())) while reader.remain: for _, processor in self.processors: if processor.match(reader): if processor.run(reader, document) is True: break else: if len(document) > 0 and isinstance(document[-1], SparseText): tail = document[-1] tail.spread(end=1) else: tail = SparseText(reader.subject, reader.position, reader.position + 1) document += tail if reader.remain[0] == '\\': # escaped tail.spread(end=1) reader.step(2) else: reader.step(1) return document
def missing_reference(app: Sphinx, env: BuildEnvironment, node: Element, contnode: TextElement) -> nodes.reference: """Attempt to resolve a missing reference via intersphinx references.""" target = node['reftarget'] inventories = InventoryAdapter(env) objtypes = None # type: List[str] if node['reftype'] == 'any': # we search anything! objtypes = [ '%s:%s' % (domain.name, objtype) for domain in env.domains.values() for objtype in domain.object_types ] domain = None else: domain = node.get('refdomain') if not domain: # only objects in domains are in the inventory return None objtypes = env.get_domain(domain).objtypes_for_role(node['reftype']) if not objtypes: return None objtypes = ['%s:%s' % (domain, objtype) for objtype in objtypes] if 'std:cmdoption' in objtypes: # until Sphinx-1.6, cmdoptions are stored as std:option objtypes.append('std:option') if 'py:attribute' in objtypes: # Since Sphinx-2.1, properties are stored as py:method objtypes.append('py:method') to_try = [(inventories.main_inventory, target)] if domain: full_qualified_name = env.get_domain(domain).get_full_qualified_name( node) if full_qualified_name: to_try.append((inventories.main_inventory, full_qualified_name)) in_set = None if ':' in target: # first part may be the foreign doc set name setname, newtarget = target.split(':', 1) if setname in inventories.named_inventory: in_set = setname to_try.append((inventories.named_inventory[setname], newtarget)) if domain: node['reftarget'] = newtarget full_qualified_name = env.get_domain( domain).get_full_qualified_name(node) if full_qualified_name: to_try.append((inventories.named_inventory[setname], full_qualified_name)) for inventory, target in to_try: for objtype in objtypes: if objtype not in inventory or target not in inventory[objtype]: continue proj, version, uri, dispname = inventory[objtype][target] if '://' not in uri and node.get('refdoc'): # get correct path in case of subdirectories uri = path.join(relative_path(node['refdoc'], '.'), uri) if version: reftitle = _('(in %s v%s)') % (proj, version) else: reftitle = _('(in %s)') % (proj, ) newnode = nodes.reference('', '', internal=False, refuri=uri, reftitle=reftitle) if node.get('refexplicit'): # use whatever title was given newnode.append(contnode) elif dispname == '-' or \ (domain == 'std' and node['reftype'] == 'keyword'): # use whatever title was given, but strip prefix title = contnode.astext() if in_set and title.startswith(in_set + ':'): newnode.append( contnode.__class__(title[len(in_set) + 1:], title[len(in_set) + 1:])) else: newnode.append(contnode) else: # else use the given display name (used for :ref:) newnode.append(contnode.__class__(dispname, dispname)) return newnode # at least get rid of the ':' in the target if no explicit title given if in_set is not None and not node.get('refexplicit', True): if len(contnode) and isinstance(contnode[0], nodes.Text): contnode[0] = nodes.Text(newtarget, contnode[0].rawsource) return None
def describe_signature(self, signode: TextElement) -> None: txt = str(self) signode.append(nodes.Text(txt, txt))
def describe_signature(self, signode: TextElement) -> None: signode.append(nodes.Text(self.id, self.id))
def describe_signature(self, signode: TextElement) -> None: signode.append(addnodes.desc_sig_punctuation('[[', '[[')) signode.append(nodes.Text(self.arg)) signode.append(addnodes.desc_sig_punctuation(']]', ']]'))
def _passthrough_role( name, rawtext, text, lineno, inliner, options={}, content=[]): return [TextElement(rawtext, text)], []
def missing_reference(app: Sphinx, env: BuildEnvironment, node: Element, contnode: TextElement) -> Optional[nodes.reference]: """Linking to Qt documentation.""" target: str = node["reftarget"] inventories = InventoryAdapter(env) objtypes: Optional[List[str]] = None if node["reftype"] == "any": # we search anything! objtypes = [ "%s:%s" % (domain.name, objtype) for domain in env.domains.values() for objtype in domain.object_types ] domain = None else: domain = node.get("refdomain") if not domain: # only objects in domains are in the inventory return None objtypes = env.get_domain(domain).objtypes_for_role(node["reftype"]) if not objtypes: return None objtypes = ["%s:%s" % (domain, objtype) for objtype in objtypes] if target.startswith("PySide2"): head, tail = target.split(".", 1) target = "PyQt5." + tail if signal_pattern.match(target): uri = signal_slot_uri[app.config.qt_documentation] dispname = signal_name[app.config.qt_documentation] version = QT_VERSION elif slot_pattern.match(target): uri = signal_slot_uri[app.config.qt_documentation] dispname = slot_name[app.config.qt_documentation] version = QT_VERSION else: target_list = [target, "PyQt5." + target] target_list += [ name + "." + target for name in inventories.named_inventory["PyQt5"]["sip:module"].keys() ] if node.get("reftype") in type_translate_dict: type_names = type_translate_dict[node.get("reftype")] else: type_names = [node.get("reftype")] for name in type_names: obj_type_name = "sip:{}".format(name) if obj_type_name not in inventories.named_inventory["PyQt5"]: return None for target_name in target_list: if target_name in inventories.main_inventory[obj_type_name]: proj, version, uri, dispname = inventories.named_inventory[ "PyQt5"][obj_type_name][target_name] uri = uri.replace("##", "#") # print(node) # print nodes with unresolved references break else: continue break else: return None if app.config.qt_documentation == "Qt5": html_name = uri.split("/")[-1] uri = "https://doc.qt.io/qt-5/" + html_name elif app.config.qt_documentation == "PySide2": if node.get("reftype") == "meth": split_tup = target_name.split(".")[1:] ref_name = ".".join(["PySide2", split_tup[0], "PySide2"] + split_tup) html_name = "/".join(split_tup[:-1]) + ".html#" + ref_name else: html_name = "/".join(target_name.split(".")[1:]) + ".html" uri = "https://doc.qt.io/qtforpython/PySide2/" + html_name # remove this line if you would like straight to pyqt documentation if version: reftitle = _("(in %s v%s)") % (app.config.qt_documentation, version) else: reftitle = _("(in %s)") % (app.config.qt_documentation, ) newnode = nodes.reference("", "", internal=False, refuri=uri, reftitle=reftitle) if node.get("refexplicit"): # use whatever title was given newnode.append(contnode) else: # else use the given display name (used for :ref:) newnode.append(contnode.__class__(dispname, dispname)) return newnode