(spec)
return validator
Yeah.

    It doesn't allow using a class because it does annoying stuff like
    try to set attributes on the callable object rather than just
    keeping a dict.
Yeah.
Yeah .
def docutils_does_not_allow_using_classes(spec):
    """
    Yeah.

    It doesn't allow using a class because it does annoying stuff like
    try to set attributes on the callable object rather than just
    keeping a dict.
    """

    def validator(name, raw_text, text, lineno, inliner):
        """
        Link to the JSON Schema documentation for a validator.

        Arguments:

            name (str):

                the name of the role in the document

            raw_source (str):

                the raw text (role with argument)

            text (str):

                the argument given to the role

            lineno (int):

                the line number

            inliner (docutils.parsers.rst.states.Inliner):

                the inliner

        Returns:

            tuple:

                a 2-tuple of nodes to insert into the document and an
                iterable of system messages, both possibly empty
        """

        if text == "$ref":
            return [nodes.reference(raw_text, text, refuri=REF_URL)], []
        elif text == "$schema":
            return [nodes.reference(raw_text, text, refuri=SCHEMA_URL)], []

        # find the header in the validation spec containing matching text
        header = spec.xpath("//h1[contains(text(), '{0}')]".format(text))

        if len(header) == 0:
            inliner.reporter.warning(
                "Didn't find a target for {0}".format(text),
            )
            uri = VALIDATION_SPEC
        else:
            if len(header) > 1:
                inliner.reporter.info(
                    "Found multiple targets for {0}".format(text),
                )

            # get the href from link in the header
            uri = urljoin(VALIDATION_SPEC, header[0].find("a").attrib["href"])

        reference = nodes.reference(raw_text, text, refuri=uri)
        return [reference], []

    return validator
def docutils_does_not_allow_using_classes ( spec ) : def validator ( name , raw_text , text , lineno , inliner ) : """
        Link to the JSON Schema documentation for a validator.

        Arguments:

            name (str):

                the name of the role in the document

            raw_source (str):

                the raw text (role with argument)

            text (str):

                the argument given to the role

            lineno (int):

                the line number

            inliner (docutils.parsers.rst.states.Inliner):

                the inliner

        Returns:

            tuple:

                a 2-tuple of nodes to insert into the document and an
                iterable of system messages, both possibly empty
        """ if text == "$ref" : return [ nodes . reference ( raw_text , text , refuri = REF_URL ) ] , [ ] elif text == "$schema" : return [ nodes . reference ( raw_text , text , refuri = SCHEMA_URL ) ] , [ ] # find the header in the validation spec containing matching text header = spec . xpath ( "//h1[contains(text(), '{0}')]" . format ( text ) ) if len ( header ) == 0 : inliner . reporter . warning ( "Didn't find a target for {0}" . format ( text ) , ) uri = VALIDATION_SPEC else : if len ( header ) > 1 : inliner . reporter . info ( "Found multiple targets for {0}" . format ( text ) , ) # get the href from link in the header uri = urljoin ( VALIDATION_SPEC , header [ 0 ] . find ( "a" ) . attrib [ "href" ] ) reference = nodes . reference ( raw_text , text , refuri = uri ) return [ reference ] , [ ] return validator