def uri(argument): """ Return the URI argument with unescaped whitespace removed. (Directive option conversion function.) Raise ``ValueError`` if no argument is found. """ if argument is None: raise ValueError('argument required but none supplied') else: parts = split_escaped_whitespace(escape2null(argument)) uri = ' '.join(''.join(unescape(part).split()) for part in parts) return uri
def uri(argument): """ Return the URI argument with unescaped whitespace removed. (Directive option conversion function.) Raise ``ValueError`` if no argument is found. """ if argument is None: raise ValueError('argument required but none supplied') else: parts = split_escaped_whitespace(escape2null(argument)) uri = ' '.join(''.join(unescape(part).split()) for part in parts) return uri
def phrase_ref( self, before: str, after: str, rawsource: str, escaped: str, text: str ) -> DispatchResult: """Handle phrase references e.g. `phrase ref`_, `embedded <ref_>`_ """ match = self.patterns.embedded_link.search(escaped) if match: # embedded <URI> or <alias_> text = unescape(escaped[: match.start(0)]) rawtext = unescape(escaped[: match.start(0)], True) aliastext = unescape(match.group(2)) rawaliastext = unescape(match.group(2), True) underscore_escaped = rawaliastext.endswith(r"\_") if aliastext.endswith("_") and not ( underscore_escaped or self.patterns.uri.match(aliastext) ): aliastype = "name" alias = normalize_name(aliastext[:-1]) target = nodes.target(match.group(1), refname=alias) target.indirect_reference_name = aliastext[:-1] else: aliastype = "uri" alias_parts = split_escaped_whitespace(match.group(2)) alias = " ".join( "".join(unescape(part).split()) for part in alias_parts ) alias = self.adjust_uri(alias) if alias.endswith(r"\_"): alias = alias[:-2] + "_" target = nodes.target(match.group(1), refuri=alias) target.referenced = 1 if not aliastext: raise ApplicationError("problem with embedded link: %r" % aliastext) if not text: text = alias rawtext = rawaliastext else: target = None rawtext = unescape(escaped, True) refname = normalize_name(text) reference = nodes.reference( rawsource, text, name=whitespace_normalize_name(text) ) reference[0].rawsource = rawtext node_list = [reference] if rawsource[-2:] == "__": if target and (aliastype == "name"): reference["refname"] = alias self.document.note_refname(reference) # self.document.note_indirect_target(target) # required? elif target and (aliastype == "uri"): reference["refuri"] = alias else: reference["anonymous"] = 1 else: if target: target["names"].append(refname) if aliastype == "name": reference["refname"] = alias self.document.note_indirect_target(target) self.document.note_refname(reference) else: reference["refuri"] = alias self.document.note_explicit_target(target, self.parent) # target.note_referenced_by(name=refname) node_list.append(target) else: reference["refname"] = refname self.document.note_refname(reference) return before, node_list, after, []