Example #1
0
    def __call__(self, *args, **kwargs):
        nodes, messages = XRefRole.__call__(self, *args, **kwargs)
        for node in nodes:
            attrs = node.attributes
            target = attrs['reftarget']
            parens = ''
            if target.endswith('()'):
                # Function call, :symbol:`mongoc_init()`
                target = target[:-2]
                parens = '()'

            if ':' in target:
                # E.g., 'bson:bson_t' has domain 'bson', target 'bson_t'
                attrs['domain'], name = target.split(':', 1)
                attrs['reftarget'] = name

                old = node.children[0].children[0]
                assert isinstance(old, Text)
                new = Text(name + parens, name + parens)
                # Ensure setup_child is called.
                node.children[0].replace(old, new)

            else:
                attrs['reftarget'] = target

            attrs['reftype'] = 'doc'
            attrs['classes'].append('symbol')

            if sphinx_version_info >= (1, 6):
                # https://github.com/sphinx-doc/sphinx/issues/3698
                attrs['refdomain'] = 'std'

        return nodes, messages
Example #2
0
    def __call__(self, *args, **kwargs):
        nodes, messages = XRefRole.__call__(self, *args, **kwargs)
        for node in nodes:
            attrs = node.attributes
            target = attrs['reftarget']
            parens = ''
            if target.endswith('()'):
                # Function call, :symbol:`mongoc_init()`
                target = target[:-2]
                parens = '()'

            if ':' in target:
                # E.g., 'bson:bson_t' has domain 'bson', target 'bson_t'
                attrs['domain'], name = target.split(':', 1)
                attrs['reftarget'] = name

                assert isinstance(node.children[0].children[0], Text)
                node.children[0].children[0] = Text(name + parens,
                                                    name + parens)

            else:
                attrs['reftarget'] = target

            attrs['reftype'] = 'doc'
            attrs['classes'].append('symbol')
        return nodes, messages
Example #3
0
 def __call__(self, typ, rawtext, text, *args, **keys):
     # Translate CMake command cross-references of the form:
     #  `command_name(SUB_COMMAND)`
     # to have an explicit target:
     #  `command_name(SUB_COMMAND) <command_name>`
     if typ == 'cmake:command':
         m = CMakeXRefRole._re_sub.match(text)
         if m:
             text = '%s <%s>' % (text, m.group(1))
     elif typ == 'cmake:genex':
         m = CMakeXRefRole._re_genex.match(text)
         if m:
             text = '%s <%s>' % (text, m.group(1))
     elif typ == 'cmake:guide':
         m = CMakeXRefRole._re_guide.match(text)
         if m:
             text = '%s <%s>' % (m.group(2), text)
     # CMake cross-reference targets frequently contain '<' so escape
     # any explicit `<target>` with '<' not preceded by whitespace.
     while True:
         m = CMakeXRefRole._re.match(text)
         if m and len(m.group(2)) == 0:
             text = '%s\x00<%s>' % (m.group(1), m.group(3))
         else:
             break
     return XRefRole.__call__(self, typ, rawtext, text, *args, **keys)
Example #4
0
    def __call__(self, typ, rawtext, text, lineno, inliner,
                 options={}, content=[]):

        typ = 'std:ref'
        self._reporter = inliner.document.reporter
        self._lineno = lineno
        return XRefRole.__call__(self, typ, rawtext, text, lineno,
                                 inliner, options, content)
Example #5
0
    def __call__(self, typ, rawtext, text, lineno, inliner,
                 options={}, content=[]):

        typ = 'std:ref'
        self._reporter = inliner.document.reporter
        self._lineno = lineno
        return XRefRole.__call__(self, typ, rawtext, text, lineno,
                                 inliner, options, content)
Example #6
0
 def __call__(self, typ, rawtext, text, *args, **keys):
     # CMake cross-reference targets may contain '<' so escape
     # any explicit `<target>` with '<' not preceded by whitespace.
     while True:
         m = ECMXRefRole._re.match(text)
         if m and len(m.group(2)) == 0:
             text = '%s\x00<%s>' % (m.group(1), m.group(3))
         else:
             break
     return XRefRole.__call__(self, typ, rawtext, text, *args, **keys)
Example #7
0
 def __call__(self, typ, rawtext, text, *args, **keys):
     # CMake cross-reference targets may contain '<' so escape
     # any explicit `<target>` with '<' not preceded by whitespace.
     while True:
         m = ECMXRefRole._re.match(text)
         if m and len(m.group(2)) == 0:
             text = '%s\x00<%s>' % (m.group(1), m.group(3))
         else:
             break
     return XRefRole.__call__(self, typ, rawtext, text, *args, **keys)
Example #8
0
File: cmake.py Project: dbcfd/CMake
 def __call__(self, typ, rawtext, text, *args, **keys):
     # Translate CMake command cross-references of the form:
     #  `command_name(SUB_COMMAND)`
     # to have an explicit target:
     #  `command_name(SUB_COMMAND) <command_name>`
     if typ == 'cmake:command':
         m = CMakeXRefRole._re_sub.match(text)
         if m:
             text = '%s <%s>' % (text, m.group(1))
     # CMake cross-reference targets frequently contain '<' so escape
     # any explicit `<target>` with '<' not preceded by whitespace.
     while True:
         m = CMakeXRefRole._re.match(text)
         if m and len(m.group(2)) == 0:
             text = '%s\x00<%s>' % (m.group(1), m.group(3))
         else:
             break
     return XRefRole.__call__(self, typ, rawtext, text, *args, **keys)
Example #9
0
    def __call__(self, *args, **kwargs):
        nodes, messages = XRefRole.__call__(self, *args, **kwargs)
        for node in nodes:
            attrs = node.attributes
            target = attrs['reftarget']
            if target.endswith('()'):
                # Function call, :symbol:`mongoc_init()`
                target = target[:-2]

            if ':' in target:
                # E.g., 'bson:bson_t' has domain 'bson', target 'bson_t'
                attrs['domain'], attrs['reftarget'] = target.split(':', 1)
            else:
                attrs['reftarget'] = target

            attrs['reftype'] = 'doc'
            attrs['classes'].append('symbol')
        return nodes, messages
Example #10
0
 def __call__(self, typ, rawtext, text, lineno, inliner,
              options={}, content=[]):
     
     typ = 'std:ref'
     return XRefRole.__call__(self, typ, rawtext, text, lineno,
                              inliner, options, content)
Example #11
0
 def __call__(self, typ, rawtext, text, lineno, inliner,
              options={}, content=[]):
     #~ print('20130901',typ, rawtext, text, lineno, inliner,options, content)
     typ = 'std:ref'
     return XRefRole.__call__(self, typ, rawtext, text, lineno, 
         inliner, options, content)
Example #12
0
 def __call__(self, *args, **kwargs):
     res = XRefRole.__call__(self, *args, **kwargs)
     return res