예제 #1
0
    def _wrap_in_section(self, schema, table):

        result = list()
        if "$$target" in schema:
            # Wrap section and table in a target (anchor) node so
            # that it can be referenced from other sections.
            labels = self.app.env.domaindata["std"]["labels"]
            anonlabels = self.app.env.domaindata["std"]["anonlabels"]
            docname = self.app.env.docname
            targets = schema["$$target"]
            if not isinstance(targets, list):
                targets = [targets]

            targetnode = nodes.target()
            for target in targets:
                anchor = normalize_name(target)
                targetnode["ids"].append(anchor)
                targetnode["names"].append(anchor)
                anonlabels[anchor] = docname, targetnode["ids"][0]
                labels[anchor] = (
                    docname,
                    targetnode["ids"][0],
                    (schema["title"] if "title" in schema else anchor),
                )
            targetnode.line = self.lineno
            result.append(targetnode)
            del schema["$$target"]

        if "title" in schema:
            # Wrap the resulting table in a section giving it a caption and an
            # entry in the table of contents.
            memo = self.state.memo
            mylevel = memo.section_level
            memo.section_level += 1
            section_node = nodes.section()
            textnodes, title_messages = self.state.inline_text(
                schema["title"], self.lineno
            )
            titlenode = nodes.title(schema["title"], "", *textnodes)
            name = normalize_name(titlenode.astext())
            section_node["names"].append(name)
            section_node += titlenode
            section_node += title_messages
            self.state.document.note_implicit_target(section_node, section_node)
            section_node += table
            memo.section_level = mylevel
            result.append(section_node)
            del schema["title"]
        else:
            result.append(table)
        return result
예제 #2
0
    def _section(self, schema):
        if 'title' in schema and self.options['lift_title']:
            # Wrap the resulting table in a section giving it a caption and an
            # entry in the table of contents.
            # unable to use self.state.section() to make a section as style is unknown
            # all sections will be placed inside current section
            section_node = nodes.section()
            textnodes, title_messages = self.state.inline_text(schema['title'], self.lineno)
            titlenode = nodes.title(schema['title'], '', *textnodes)
            name = normalize_name(titlenode.astext())
            section_node['names'].append(name)
            section_node += titlenode
            section_node += title_messages
            self.state.document.note_implicit_target(section_node, section_node)

            if self.nesting == 0:
                self.ref_titles[self.nesting] = schema['title']

            if self.options['lift_description']:
                self._get_description(schema, section_node)

            del schema['title']
            return section_node

        return None
예제 #3
0
    def run(self):
        """For each file in noseOfYeti/specs, output nodes to represent each spec file"""
        env = self.env = self.state.document.settings.env
        specdir = os.path.join(env.srcdir, '../noseOfYeti/specs')
        files = [f for f in os.listdir(specdir) if f.endswith('_test.py')]
        tokens = []
        for f in files:
            name = str(f[:-3])
            module = getattr(
                __import__('noseOfYeti.specs', globals(), locals(), [name],
                           -1), name)

            section = nodes.section()
            name = normalize_name(f)
            section['names'].append(name)
            section['ids'].append(name)

            header = nodes.title()
            header += nodes.Text(f)
            section.append(header)

            section.extend(self.nodes_for_module(module))
            tokens.append(section)

        return tokens
예제 #4
0
파일: patch.py 프로젝트: AcrDijon/henet
def new_subsection(self, title, lineno, messages, source, style):
    memo = self.memo
    mylevel = memo.section_level
    memo.section_level += 1
    section_node = nodes.section()
    self.parent += section_node
    textnodes, title_messages = self.inline_text(title, lineno)
    titlenode = nodes.title(title, '', *textnodes)
    titlenode.realsource = source
    titlenode.style = style
    name = normalize_name(titlenode.astext())
    section_node['names'].append(name)
    section_node += titlenode
    section_node += messages
    section_node += title_messages
    self.document.note_implicit_target(section_node, section_node)
    offset = self.state_machine.line_offset + 1
    absoffset = self.state_machine.abs_line_offset() + 1
    newabsoffset = self.nested_parse(
            self.state_machine.input_lines[offset:], input_offset=absoffset,
            node=section_node, match_titles=True)
    self.goto_line(newabsoffset)
    if memo.section_level <= mylevel:
        raise EOFError
    memo.section_level = mylevel
예제 #5
0
def indigo_option_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
    """Link to an Indigo option

    Returns 2 part tuple containing list of nodes to insert into the
    document and a list of system messages.  Both are allowed to be
    empty.

    :param name: The role name used in the document.
    :param rawtext: The entire markup snippet, with role.
    :param text: The text marked with the role.
    :param lineno: The line number where rawtext appears in the input.
    :param inliner: The inliner instance that called us.
    :param options: Directive options for customization.
    :param content: The directive content for customization.
    """
    env = inliner.document.settings.env
    app = env.app

    opts = [opt for opt in env.indigo_options if opt['name'] == text]
    if len(opts) == 0:
        raise ValueError("Cannot find option " + slug)

    opt_info = opts[0]

    newnode = nodes.reference('', '')
    innernode = nodes.Text(opt_info['name'], opt_info['name'])
    newnode['refdocname'] = opt_info['docname']
    newnode['refuri'] = app.builder.get_relative_uri(
        env.docname, opt_info['docname'])
    newnode['refuri'] += '#' + normalize_name(opt_info['name'])
    newnode.append(innernode)

    return [newnode], []
예제 #6
0
    def _wrap_in_section(self, schema, table):

        result = list()
        if '$$target' in schema:
            result.append(self._create_target(schema))

        if 'title' in schema:
            # Wrap the resulting table in a section giving it a caption and an
            # entry in the table of contents.
            memo = self.state.memo
            mylevel = memo.section_level
            memo.section_level += 1
            section_node = nodes.section()
            textnodes, title_messages = self.state.inline_text(schema['title'], self.lineno)
            titlenode = nodes.title(schema['title'], '', *textnodes)
            name = normalize_name(titlenode.astext())
            section_node['names'].append(name)
            section_node += titlenode
            section_node += title_messages
            self.state.document.note_implicit_target(section_node, section_node)
            section_node += table
            memo.section_level = mylevel
            result.append(section_node)
        else:
            result.append(table)
        return result
예제 #7
0
 def new_subsection(self, level, title, lineno, messages):
     """Append new subsection to document tree. On return, check level."""
     memo = self.memo
     mylevel = memo.section_level
     memo.section_level += 1
     section_node = nodes.section()
     self.parent += section_node
     textnodes, title_messages = self.inline_text(title, lineno)
     titlenode = nodes.title(title, '', *textnodes)
     name = normalize_name(titlenode.astext())
     section_node['names'].append(name)
     section_node += titlenode
     section_node += messages
     section_node += title_messages
     self.document.note_implicit_target(section_node, section_node)
     offset = self.state_machine.line_offset + 1
     absoffset = self.state_machine.abs_line_offset() + 1
     newabsoffset = self.nested_parse(
           self.state_machine.input_lines[offset:], input_offset=absoffset,
           node=section_node, match_titles=1)
     self.goto_line(newabsoffset)
     if memo.section_level <= mylevel: # can't handle next section?
         raise EOFError              # bubble up to supersection
     # reset section_level; next pass will detect it properly
     memo.section_level = mylevel
 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, [])
예제 #9
0
    def run(self):
        name = self.options.get('name')

        env = self.state.document.settings.env

        targetid = "indigo-option-%d" % env.new_serialno('indigo-option')
        targetnode = nodes.target('', '', ids=[targetid])

        section_node = OptionInfo()
        section_node['names'].append(normalize_name(name))
        section_node['ids'].append(normalize_name(name))
        #titlenode = nodes.title('', name + ' = ' + self.options.get('default'))
        titlenode = nodes.title('', name)
        section_node += titlenode

        new_list = nodes.field_list()
        new_list += self.make_field('type',
                                    nodes.Text(self.options.get('type')))
        new_list += self.make_field('default',
                                    nodes.Text(self.options.get('default')))
        new_list += self.make_field('description',
                                    nodes.Text(self.options.get('short')))

        section_node += new_list

        text = '\n'.join(self.content)
        if text:
            self.state.nested_parse(self.content, self.content_offset,
                                    section_node)

        if not hasattr(env, 'indigo_options'):
            env.indigo_options = []

        env.indigo_options.append({
            'docname': env.docname,
            'lineno': self.lineno,
            'name': name,
            'type': self.options.get('type'),
            'default': self.options.get('default'),
            'short': self.options.get('short'),
            'target': targetnode
        })

        return [targetnode, section_node]
예제 #10
0
def process_indigo_option_nodes(app, doctree, fromdocname):
    env = app.builder.env

    for node in doctree.traverse(OptionsList):
        content = []
        #sorted_options = sorted(env.indigo_options, key=lambda o:o['name'])

        for op_group, s_options in groupby(
                env.indigo_options,
                key=lambda o: get_title(env.titles[o['docname']])):
            #group = nodes.title('', op_group)

            #print(op_group)
            #for opt_info in s_options:
            #    print(opt_info)
            #sorted_options = list(s_options)
            #print(str(sorted_options))

            #group.source = op_group
            #group.setText(op_group)
            #group=nodes.rubric('', op_group)
            #group.append(nodes.Text(op_group))
            #content.append(group)

            section_node = OptionInfo()
            options_name = op_group
            section_node['names'].append(options_name)
            section_node['ids'].append(options_name)

            titlenode = nodes.title('', options_name)
            section_node += titlenode

            tbody = create_options_table(section_node)

            content.append(section_node)

            for opt_info in s_options:
                row = nodes.row()
                tbody.append(row)

                # Create a reference
                newnode = nodes.reference('', '')
                innernode = nodes.Text(opt_info['name'], opt_info['name'])
                newnode['refdocname'] = opt_info['docname']
                newnode['refuri'] = app.builder.get_relative_uri(
                    fromdocname, opt_info['docname'])
                newnode['refuri'] += '#' + normalize_name(opt_info['name'])
                newnode['classes'].append('option')
                newnode.append(innernode)

                row += create_row_entry(newnode)
                row += create_row_entry_text(opt_info['type'])
                row += create_row_entry_text(opt_info['short'])
                row += create_row_entry_text(opt_info['default'])

        node.replace_self(content)
 def inline_internal_target(self, match: Match, lineno: int) -> DispatchResult:
     """Handle an inline internal target, e.g. _`target` """
     before, inlines, remaining, sysmessages, endstring = self.inline_obj(
         match, lineno, self.patterns.target, nodes.target
     )
     if inlines and isinstance(inlines[0], nodes.target):
         assert len(inlines) == 1
         target = inlines[0]
         name = normalize_name(target.astext())
         target["names"].append(name)
         self.document.note_explicit_target(target, self.parent)
     return before, inlines, remaining, sysmessages
예제 #12
0
    def run(self):
        name = self.options.get('name')

        env = self.state.document.settings.env

        targetid = "indigo-option-%d" % env.new_serialno('indigo-option')
        targetnode = nodes.target('', '', ids=[targetid])

        section_node = optioninfo()
        section_node['names'].append(normalize_name(name))
        section_node['ids'].append(normalize_name(name))
        titlenode = nodes.title('', name + ' = ' + self.options.get('default'))
        section_node += titlenode

        new_list = nodes.field_list()
        new_list += self.make_field('type', nodes.Text(self.options.get('type')))
        new_list += self.make_field('default', nodes.Text(self.options.get('default')))
        new_list += self.make_field('description', nodes.Text(self.options.get('short')))

        section_node += new_list

        text = '\n'.join(self.content)
        if text:
            self.state.nested_parse(self.content, self.content_offset, section_node)

        if not hasattr(env, 'indigo_options'):
            env.indigo_options = []

        env.indigo_options.append({
            'docname': env.docname,
            'lineno': self.lineno,
            'name': name,
            'type': self.options.get('type'),
            'default': self.options.get('default'),
            'short':self.options.get('short'),
            'target': targetnode
        })

        return [ targetnode, section_node ]
예제 #13
0
def process_indigo_option_nodes(app, doctree, fromdocname):
    env = app.builder.env

    for node in doctree.traverse(optionslist):
        content = []

        tbl = nodes.table()
        tgroup = nodes.tgroup(cols=4)
        tbl += tgroup

        tgroup += nodes.colspec(colwidth=35)
        tgroup += nodes.colspec(colwidth=9)
        tgroup += nodes.colspec(colwidth=9)
        tgroup += nodes.colspec(colwidth=73)

        thead = nodes.thead()
        tgroup += thead
        row = nodes.row()
        thead += row
        row += createRowEntryText('Name')
        row += createRowEntryText('Type')
        row += createRowEntryText('Default')
        row += createRowEntryText('Short description')

        tbody = nodes.tbody()
        tgroup += tbody

        content.append(tbl)

        sorted_options = sorted(env.indigo_options, key=lambda o:o['name'])

        for opt_info in sorted_options:
            row = nodes.row()
            tbody += row

            # Create a reference
            newnode = nodes.reference('', '')
            innernode = nodes.Text(opt_info['name'], opt_info['name'])
            newnode['refdocname'] = opt_info['docname']
            newnode['refuri'] = app.builder.get_relative_uri(
                fromdocname, opt_info['docname'])
            newnode['refuri'] += '#' + normalize_name(opt_info['name'])
            newnode.append(innernode)

            row += createRowEntry(newnode)
            row += createRowEntryText(opt_info['type'])
            row += createRowEntryText(opt_info['default'])
            row += createRowEntryText(opt_info['short'])

        node.replace_self(content)
예제 #14
0
def process_indigo_option_nodes(app, doctree, fromdocname):
    env = app.builder.env

    for node in doctree.traverse(optionslist):
        content = []

        tbl = nodes.table()
        tgroup = nodes.tgroup(cols=4)
        tbl += tgroup

        tgroup += nodes.colspec(colwidth=35)
        tgroup += nodes.colspec(colwidth=9)
        tgroup += nodes.colspec(colwidth=9)
        tgroup += nodes.colspec(colwidth=73)

        thead = nodes.thead()
        tgroup += thead
        row = nodes.row()
        thead += row
        row += createRowEntryText('Name')
        row += createRowEntryText('Type')
        row += createRowEntryText('Default')
        row += createRowEntryText('Short description')

        tbody = nodes.tbody()
        tgroup += tbody

        content.append(tbl)

        sorted_options = sorted(env.indigo_options, key=lambda o: o['name'])

        for opt_info in sorted_options:
            row = nodes.row()
            tbody += row

            # Create a reference
            newnode = nodes.reference('', '')
            innernode = nodes.Text(opt_info['name'], opt_info['name'])
            newnode['refdocname'] = opt_info['docname']
            newnode['refuri'] = app.builder.get_relative_uri(
                fromdocname, opt_info['docname'])
            newnode['refuri'] += '#' + normalize_name(opt_info['name'])
            newnode.append(innernode)

            row += createRowEntry(newnode)
            row += createRowEntryText(opt_info['type'])
            row += createRowEntryText(opt_info['default'])
            row += createRowEntryText(opt_info['short'])

        node.replace_self(content)
예제 #15
0
 def reference(self, match, lineno, anonymous=None):
     referencename = match.group('refname')
     refname = normalize_name(referencename)
     referencenode = nodes.reference(
         referencename + match.group('refend'), referencename,
         name=whitespace_normalize_name(referencename))
     if anonymous:
         referencenode['anonymous'] = 1
     else:
         referencenode['refname'] = refname
         self.document.note_refname(referencenode)
     string = match.string
     matchstart = match.start('whole')
     matchend = match.end('whole')
     return (string[:matchstart], [referencenode], string[matchend:], [])
예제 #16
0
    def run(self):
        title = self.arguments[0]

        text_node = nodes.Text(title)
        text_nodes = [text_node]
        title_node = nodes.title(title, '', *text_nodes)
        name = normalize_name(title_node.astext())

        section_node = nodes.section(rawsource=self.block_text)
        section_node['names'].append(name)
        section_node += title_node
        messages = []
        title_messages = []
        section_node += messages
        section_node += title_messages
        section_node.tagname = 'beamer-section'
        return [section_node]
예제 #17
0
    def run(self):
        title = self.arguments[0]

        text_node = nodes.Text(title)
        text_nodes = [text_node]
        title_node = nodes.title(title, '', *text_nodes)
        name = normalize_name(title_node.astext())

        section_node = nodes.section(rawsource=self.block_text)
        section_node['names'].append(name)
        section_node += title_node
        messages = []
        title_messages = []
        section_node += messages
        section_node += title_messages
        section_node.tagname = 'beamer-section'
        return [section_node]
예제 #18
0
    def _create_target(self, schema):
        # Wrap section and table in a target (anchor) node so
        # that it can be referenced from other sections.
        labels = self.app.env.domaindata['std']['labels']
        anonlabels = self.app.env.domaindata['std']['anonlabels']
        docname = self.app.env.docname
        targets = schema['$$target']
        if not isinstance(targets, list):
            targets = [targets]

        targetnode = nodes.target()
        for target in targets:
            anchor = normalize_name(target)
            targetnode['ids'].append(anchor)
            targetnode['names'].append(anchor)
            anonlabels[anchor] = docname, targetnode['ids'][0]
            labels[anchor] = docname, targetnode['ids'][0], (schema['title'] if 'title' in schema else anchor)
        targetnode.line = self.lineno

        return targetnode
 def reference(
     self, match: Match, lineno: int, anonymous: bool = False
 ) -> DispatchResult:
     """Handle simple references,  e.g. reference_ and anonymous__ """
     referencename = match.group("refname")
     refname = normalize_name(referencename)
     referencenode = nodes.reference(
         referencename + match.group("refend"),
         referencename,
         name=whitespace_normalize_name(referencename),
     )
     referencenode[0].rawsource = referencename
     if anonymous:
         referencenode["anonymous"] = 1
     else:
         referencenode["refname"] = refname
         self.document.note_refname(referencenode)
     string = match.string
     matchstart = match.start("whole")
     matchend = match.end("whole")
     return (string[:matchstart], [referencenode], string[matchend:], [])
예제 #20
0
def indigo_option_role(name,
                       rawtext,
                       text,
                       lineno,
                       inliner,
                       options={},
                       content=[]):
    """Link to an Indigo option

    Returns 2 part tuple containing list of nodes to insert into the
    document and a list of system messages.  Both are allowed to be
    empty.

    :param name: The role name used in the document.
    :param rawtext: The entire markup snippet, with role.
    :param text: The text marked with the role.
    :param lineno: The line number where rawtext appears in the input.
    :param inliner: The inliner instance that called us.
    :param options: Directive options for customization.
    :param content: The directive content for customization.
    """
    env = inliner.document.settings.env
    app = env.app

    opts = [opt for opt in env.indigo_options if opt['name'] == text]
    if len(opts) == 0:
        raise ValueError("Cannot find option " + slug)

    opt_info = opts[0]

    newnode = nodes.reference('', '')
    innernode = nodes.Text(opt_info['name'], opt_info['name'])
    newnode['refdocname'] = opt_info['docname']
    newnode['refuri'] = app.builder.get_relative_uri(env.docname,
                                                     opt_info['docname'])
    newnode['refuri'] += '#' + normalize_name(opt_info['name'])
    newnode['classes'].append('option')
    newnode.append(innernode)

    return [newnode], []
예제 #21
0
    def _target(self, schema, pointer=''):
        # Wrap section and table in a target (anchor) node so
        # that it can be referenced from other sections.
        labels = self.app.env.domaindata['std']['labels']
        anonlabels = self.app.env.domaindata['std']['anonlabels']
        docname = self.app.env.docname

        targets = []

        if '$$target' in schema:
            if not isinstance(schema['$$target'], list):
                targets.append(schema['$$target'])
            else:
                targets.extend(schema['$$target'])
            del schema['$$target']

        if self.options['auto_target']:
            # When schema's multiple schema's are writen with content but without a pointer
            # you get multiple equal named targets, all $ref will link to the last created schema
            # The same applies if you would load files with equal name into your documentation
            if len(pointer) > 1:
                targets.append(self.filename + pointer)
            else:
                targets.append(self.filename)

        if targets:
            targetnode = nodes.target()
            anchorid = nodes.make_id((schema['title'] if 'title' in schema else targets[0]))
            targetnode['ids'].append(anchorid)
            targetnode['names'].append(anchorid)
            targetnode.line = self.lineno

            for target in targets:
                anchor = normalize_name(target)
                anonlabels[anchor] = docname, targetnode['ids'][0]
                labels[anchor] = docname, targetnode['ids'][0], (schema['title'] if 'title' in schema else target)

            return targetnode

        return None
 def substitution_reference(self, match: Match, lineno: int) -> DispatchResult:
     """Handle a substitution reference, e.g. |sub| """
     before, inlines, remaining, sysmessages, endstring = self.inline_obj(
         match, lineno, self.patterns.substitution_ref, nodes.substitution_reference
     )
     if len(inlines) == 1:
         subref_node = inlines[0]
         if isinstance(subref_node, nodes.substitution_reference):
             subref_text = subref_node.astext()
             self.document.note_substitution_ref(subref_node, subref_text)
             if endstring[-1:] == "_":
                 reference_node = nodes.reference(
                     "|%s%s" % (subref_text, endstring), ""
                 )
                 if endstring[-2:] == "__":
                     reference_node["anonymous"] = 1
                 else:
                     reference_node["refname"] = normalize_name(subref_text)
                     self.document.note_refname(reference_node)
                 reference_node += subref_node
                 inlines = [reference_node]
     return before, inlines, remaining, sysmessages
예제 #23
0
    def run(self):
        """For each file in noseOfYeti/specs, output nodes to represent each spec file"""
        env = self.env = self.state.document.settings.env
        specdir = os.path.join(env.srcdir, "../noseOfYeti/specs")
        files = [f for f in os.listdir(specdir) if f.endswith("_test.py")]
        tokens = []
        for f in files:
            name = str(f[:-3])
            module = getattr(__import__("noseOfYeti.specs", globals(), locals(), [name], -1), name)

            section = nodes.section()
            name = normalize_name(f)
            section["names"].append(name)
            section["ids"].append(name)

            header = nodes.title()
            header += nodes.Text(f)
            section.append(header)

            section.extend(self.nodes_for_module(module))
            tokens.append(section)

        return tokens
    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, []