def resolve_xref(self, env, fromdocname, builder, typ, target, node, contnode): refdoc = env.domaindata['cite'].get('refdoc') if not refdoc: env.warn( fromdocname, 'no `refs` directive found; citations will have dead links', node.line) refuri = '' else: refuri = builder.get_relative_uri(fromdocname, refdoc) for nd in node.children: if isinstance(nd, nodes.pending): nd.details['refs'] = [] if builder.name == 'latex': cite_keys = nd.details['keys'] cite_keys = ','.join(cite_keys) cite_node = nodes.citation_reference(cite_keys, cite_keys) return cite_node for key in nd.details.pop('keys'): ref = self.citations.get(key) if ref is None: continue nd.details['refs'].append(ref) transform = nd.transform(**nd.details) node = transform.cite( typ, refuri, global_keys=env.domaindata['cite']['keys']) return node
def footnote_reference(self, match: Match, lineno: int) -> DispatchResult: """Handles footnote/citation references, e.g. [1]_""" label = match.group("footnotelabel") refname = normalize_name(label) string = match.string before = string[: match.start("whole")] remaining = string[match.end("whole") :] if match.group("citationlabel"): refnode = nodes.citation_reference(f"[{label}]_", refname=refname) refnode += nodes.Text(label) self.document.note_citation_ref(refnode) else: refnode = nodes.footnote_reference(f"[{label}]_") if refname[0] == "#": refname = refname[1:] refnode["auto"] = 1 self.document.note_autofootnote_ref(refnode) elif refname == "*": refname = "" refnode["auto"] = "*" self.document.note_symbol_footnote_ref(refnode) else: refnode += nodes.Text(label) if refname: refnode["refname"] = refname self.document.note_footnote_ref(refnode) if get_trim_footnote_ref_space(self.document.settings): before = before.rstrip() return (before, [refnode], remaining, [])
def resolve_xref(self, env, fromdocname, builder, typ, target, node, contnode): refdoc = env.domaindata['cite'].get('refdoc') if not refdoc: env.warn(fromdocname , 'no `refs` directive found; citations will have dead links', node.line) refuri = '' else: refuri = builder.get_relative_uri(fromdocname, refdoc) for nd in node.children: if isinstance(nd, nodes.pending): nd.details['refs'] = [] if builder.name == 'latex': cite_keys = nd.details['keys'] cite_keys = ','.join(cite_keys) cite_node = nodes.citation_reference(cite_keys, cite_keys) return cite_node for key in nd.details.pop('keys'): ref = self.citations.get(key) if ref is None: continue nd.details['refs'].append(ref) transform = nd.transform(**nd.details) node = transform.cite(typ, refuri, global_keys=env.domaindata['cite']['keys']) return node
def resolve_xref(self, env, fromdocname, builder, typ, target, node, contnode): refdoc = env.domaindata["cite"].get("refdoc") if not refdoc: env.warn(fromdocname, "no `refs` directive found; citations will have dead links", node.line) refuri = "" else: refuri = builder.get_relative_uri(fromdocname, refdoc) for nd in node.children: if isinstance(nd, nodes.pending): nd.details["refs"] = [] if builder.name == "latex": cite_keys = nd.details["keys"] cite_keys = ",".join(cite_keys) cite_node = nodes.citation_reference(cite_keys, cite_keys) return cite_node for key in nd.details.pop("keys"): ref = self.citations.get(key) if ref is None: continue nd.details["refs"].append(ref) transform = nd.transform(**nd.details) node = transform.cite(typ, refuri, global_keys=env.domaindata["cite"]["keys"]) return node
def run(self, **kwargs) -> None: domain = cast(CitationDomain, self.env.get_domain('citation')) matcher = NodeMatcher(addnodes.pending_xref, refdomain='citation', reftype='ref') for node in self.document.traverse(matcher): # type: addnodes.pending_xref docname, labelid, _ = domain.citations.get(node['reftarget'], ('', '', 0)) if docname: citation_ref = nodes.citation_reference('', '', *node.children, docname=docname, refname=labelid) node.replace_self(citation_ref)
def make_bib_reference(app, bibentry, refdoc): """ Create a docutils node with a reference to to an entry in the bibliography. If the bibliography entry exists, the returned node will be rendered as a hyperlink of the form ``[my-bibentry-label]`` pointing to the entry in the bibliography. Otherwise, a non-hyperlinked entry will be returned and a warning printed. """ docname, labelid = get_citation_ref(app.builder.env, bibentry) if docname: if app.builder.format == "latex": # Bodge: To make the LaTeX writer produce a citation in the # output, we must create a citation_reference node. If we # created a ref node (as we do for other output modes), two # problems would arise: # # * The LaTeX output doesn't include labels for # bibliography entries so the ref would not produce a # valid hyperlink # * When latex_show_pagerefs is used, the ref would result # in the page number of the bibliography being shown # which would be confusing. (Especially as the ref # would not resolve and so ?? would be shown). # # Ordinarily, citation_reference nodes would have been # converted into pending_xrefs long ago by # sphinx.domains.citation.CitationReferenceTransform, # however when using the LaTeX builder, another # transformer, # sphinx.builders.latex.transforms.CitationReferenceTransform, # immediately undoes this transformation causing them to # survive all the way to the writer output. bibref = nodes.citation_reference(text="[{}]".format(bibentry)) bibref["docname"] = docname bibref["refname"] = labelid return bibref else: # Construct a reference to the citation definition. # # Note that we can't just make a citation_reference because # these have already been transformed into pending_xrefs by # sphinx.domains.citation.CitationReferenceTransform in an # earlier build step (which in turn are being resolved # right now). return make_refnode( app.builder, refdoc, docname, labelid, nodes.Text("[{}]".format(bibentry)), ) else: logger.warning("Intertex found no citation for %r", bibentry) return nodes.Text("[{}]".format(bibentry))
def apply(self, **kwargs): # type: (Any) -> None if self.app.builder.name != 'latex': return matcher = NodeMatcher(addnodes.pending_xref, refdomain='std', reftype='citation') citations = self.env.get_domain('std').data['citations'] for node in self.document.traverse(matcher): # type: addnodes.pending_xref docname, labelid, _ = citations.get(node['reftarget'], ('', '', 0)) if docname: citation_ref = nodes.citation_reference('', '', *node.children, docname=docname, refname=labelid) node.replace_self(citation_ref)
def apply(self): # type: () -> None if self.app.builder.name != 'latex': return matcher = NodeMatcher(addnodes.pending_xref, refdomain='std', reftype='citation') citations = self.env.get_domain('std').data['citations'] for node in self.document.traverse(matcher): docname, labelid, _ = citations.get(node['reftarget'], ('', '', 0)) if docname: citation_ref = nodes.citation_reference('', *node.children, docname=docname, refname=labelid) node.replace_self(citation_ref)
def apply(self): # type: () -> None if self.app.builder.name != 'latex': return citations = self.env.get_domain('std').data['citations'] for node in self.document.traverse(addnodes.pending_xref): if node['refdomain'] == 'std' and node['reftype'] == 'citation': docname, labelid, _ = citations.get(node['reftarget'], ('', '', 0)) if docname: citation_ref = nodes.citation_reference('', *node.children, docname=docname, refname=labelid) node.replace_self(citation_ref)
def run(self, **kwargs): # type: (Any) -> None matcher = NodeMatcher(addnodes.pending_xref, refdomain='std', reftype='citation') citations = self.env.get_domain('std').data['citations'] for node in self.document.traverse( matcher): # type: addnodes.pending_xref docname, labelid, _ = citations.get(node['reftarget'], ('', '', 0)) if docname: citation_ref = nodes.citation_reference('', '', *node.children, docname=docname, refname=labelid) node.replace_self(citation_ref)