Ejemplo n.º 1
0
    def menuitem(role, rawtext, text, lineno, inliner, options={}, content={}):
        items = text.split(',')
        ret = []
        for i in range(len(items)):
            item = items[i]
            if current_builder == 'xdehtml':
                c = nodes.inline()

                n = nodes.Text(item)
#                print dir(n)
                c +=n
                if i != len(items)-1:
                    c['classes'].append('menuitem')
                else:
                    c['classes'].append('menuitemlast')
                ret.append(c)
            else:
                s = nodes.strong()
                s += nodes.Text(item)
                ret.append(s)
                if i != len(items)-1:
                    ret.append(nodes.Text(' '));
                    sub = nodes.substitution_reference()
                    sub['refname'] = 'submenu'
                    ret.append(sub)
        return ret, []
Ejemplo n.º 2
0
    def apply(self):
        if not hasattr(self.document.settings, 'breadcrumb') \
                or not getattr(self.document.settings, 'breadcrumb', None):
            return

        logger.debug('Running breadcrumb xform')

        subrefname = nodes.fully_normalize_name(
            self.document.settings.breadcrumb_substitution_reference)
        subrefid = nodes.make_id(subrefname)

        subreflist = self.document.traverse(nodes.substitution_reference)
        
        if subrefname not in subreflist:
            subloc = self.find_breadcrumb_location()

            # append sub. reference at location
            subrefnode = nodes.substitution_reference(None, subrefname)
            subrefnode['refname'] = subrefname
            subloc.append(subrefnode)
            self.document.note_substitution_ref(subrefnode, subrefname)

        breadcrumb = self.generate_breadcrumb()
        # append sub. definition to document
        subdefnode = nodes.substitution_definition()
        subdefnode.append(breadcrumb)
        subdefnode['names'].append(subrefname)
        self.document.append(subdefnode)
        self.document.note_substitution_def(subdefnode, subrefname) 
Ejemplo n.º 3
0
    def apply(self):
        settings = self.document.settings
        if not hasattr(settings, 'cc_embed') or not settings.cc_embed:
            return

        logger.debug('Running cc_embed xform')

        subrefname = nodes.fully_normalize_name(
                settings.cc_license_substitution_reference)
        subrefid = nodes.make_id(subrefname)
        subrefpath = nodes.fully_normalize_name(
                settings.cc_license_location)

        subreflist = self.document.traverse(nodes.substitution_reference)
        if subrefname not in subreflist:
            subrefloc = self.find_location(subrefpath)

            # append sub. ref. at location
            subrefnode = nodes.substitution_reference(None, None,
                    refname=subrefname)
            subrefloc.append(subrefnode)
            self.document.note_substitution_ref(subrefnode, subrefname)

        license = self.generate_cc_license()
        # append sub. def. to document
        subdefnode = nodes.substitution_definition(names=subrefname)
        subdefnode.append(license)
        self.document.append(subdefnode)
        self.document.note_substitution_def(subdefnode, subrefname)
Ejemplo n.º 4
0
    def apply(self):
        """Create substitution nodes for hyperlinks"""
        # In this phase, we look for hyperlinks (references nodes)
        # that contain substitutions (of the form "|foo|").
        # We then add actual "substitution"s nodes to those references,
        # so that they can be replaced by the substitution processor.
        subst_re = re.compile(self.subst_pattern)

        for link in self.document.traverse(self._maybe_hyperlink):
            if 'refuri' not in link:
                continue

            # Note: "target" nodes do not have a "name" attribute.
            if '|' not in link['refuri'] and '|' not in link.get('name', ''):
                continue

            # This list acts as a cache so that only one substitution node
            # is added as a child for each substitution name.
            substitutions = []

            matches = subst_re.findall(link['refuri']) + \
                subst_re.findall(link.get('name', ''))
            for subref_text in matches:
                if subref_text in substitutions:
                    continue

                substitutions.append(subref_text)
                subref_node = nodes.substitution_reference(subref_text)
                link.append(subref_node)
                self.document.note_substitution_ref(subref_node, subref_text)

            # Build a map of substitutions names to child indices
            # (minus one since the actual link label is in link[0]).
            link['varlinks'] = \
                dict(zip(substitutions, range(len(substitutions))))
Ejemplo n.º 5
0
    def image(self, content, label=None, uri=None, title=None):

        label = make_refname(content if label is None else label)
        if uri is not None:
            img_node = nodes.image()
            img_node['uri'] = uri
        else:
            img_node = nodes.substitution_reference()
            img_node['refname'] = label
            self.document.note_refname(img_node)

        if title:
            img_node['title'] = title

        img_node['alt'] = text_only(content)
        return img_node
Ejemplo n.º 6
0
 def run(self) -> Tuple[List[nodes.Node], List[nodes.system_message]]:
     subref_node = nodes.substitution_reference(self.rawtext, self.text)
     self.set_source_info(subref_node, self.lineno)
     subref_node["refname"] = nodes.fully_normalize_name(self.text)
     return [subref_node], []