Ejemplo n.º 1
0
def container(name, arguments, options, content, lineno, content_offset,
              block_text, state, state_machine):
    text = '\n'.join(content)
    if not text:
        error = state_machine.reporter.error(
            'The "%s" directive is empty; content required.' % name,
            nodes.literal_block(block_text, block_text),
            line=lineno)
        return [error]
    try:
        if arguments:
            classes = directives.class_option(arguments[0])
        else:
            classes = []
    except ValueError:
        error = state_machine.reporter.error(
            'Invalid class attribute value for "%s" directive: "%s".' %
            (name, arguments[0]),
            nodes.literal_block(block_text, block_text),
            line=lineno)
        return [error]
    node = nodes.container(text)
    node['classes'].extend(classes)
    state.nested_parse(content, content_offset, node)
    return [node]
Ejemplo n.º 2
0
def add_role(app, new_role_name):
    options = {
        'class': directives.class_option(new_role_name),
    }
    role = roles.CustomRole(new_role_name, roles.generic_custom_role, options,
                            "")
    app.add_role(new_role_name, role)
Ejemplo n.º 3
0
    def run(self):
        self.assert_has_content()
        text = '\n'.join(self.content)
        node = nodes.container(text, **self.options)
        node['classes'] = []

        if 'vertical' in self.options:
            node['classes'] += ['btn-group-vertical']
        else:
            node['classes'] += ['btn-group']

        node['classes'] += self.options.get('class', [])
        node['html_attributes'] = {
            'role': 'group',
        }

        try:
            if self.arguments:
                node['classes'] += directives.class_option(self.arguments[0])
        except ValueError:
            val_error = 'Invalid class argument for "%s" directive: "%s".'
            raise self.error(val_error % (self.name, " ".join(self.arguments)))

        bs_classes = ['justified', 'xs', 'sm', 'md', 'lg']

        for i, cls in enumerate(node['classes']):
            if cls in bs_classes:
                node['classes'][i] = 'btn-group-%s' % node['classes'][i]

        self.state.nested_parse(self.content, self.content_offset, node)
        self.add_name(node)
        return [node]
Ejemplo n.º 4
0
def class_directive(name, arguments, options, content, lineno,
                       content_offset, block_text, state, state_machine):
    """
    Set a "class" attribute on the directive content or the next element.
    When applied to the next element, a "pending" element is inserted, and a
    transform does the work later.
    """
    try:
        class_value = directives.class_option(arguments[0])
    except ValueError:
        error = state_machine.reporter.error(
            'Invalid class attribute value for "%s" directive: "%s".'
            % (name, arguments[0]),
            nodes.literal_block(block_text, block_text), line=lineno)
        return [error]
    node_list = []
    if content:
        container = nodes.Element()
        state.nested_parse(content, content_offset, container)
        for node in container:
            node['classes'].extend(class_value)
        node_list.extend(container.children)
    else:
        pending = nodes.pending(misc.ClassAttribute,
                                {'class': class_value, 'directive': name},
                                block_text)
        state_machine.document.note_pending(pending)
        node_list.append(pending)
    return node_list
Ejemplo n.º 5
0
    def run(self):
        self.assert_has_content()

        node = tabs()
        node.document = self.state.document
        set_source_info(self, node)

        try:
            if self.arguments:
                node['classes'] += directives.class_option(self.arguments[0])
        except ValueError:  # pragma: no cover
            val_error = 'Invalid class attribute value for "%s" directive: "%s".'
            raise self.error(val_error % (self.name, self.arguments[0]))

        node['classes'] += self.options.get('class', [])

        self.state.nested_parse(self.content, self.content_offset, node)
        self.add_name(node)

        wrapper = nodes.container()
        wrapper['classes'] += ['tab-content']
        wrapper += node.children

        nav_list = nodes.bullet_list()
        nav_list['classes'] += ['nav', 'nav-tabs']
        nav_list['html_attributes'] = {'role': 'tablist'}

        has_active_class = False

        for child_tab in wrapper.children:
            if not isinstance(child_tab, tab):
                raise self.error('.. tabs can only have .. tab children.')

            if 'active' in child_tab['classes']:
                has_active_class = True
            item = nodes.list_item()
            item['html_attributes'] = {'role': 'presentation'}

            html_attributes = {'role': 'tab', 'data-toggle': 'tab'}
            ref_opts = {
                'internal': True,
                'refid': child_tab['tab_id'],
                'html_attributes': html_attributes,
            }
            reference = nodes.reference('', '', **ref_opts)
            reference += child_tab['tab_title']
            para = addnodes.compact_paragraph('', '', reference)

            item += [para]
            nav_list += item

        if not has_active_class:
            wrapper.children[0]['classes'] += ['active']
            nav_list.children[0]['classes'] += ['active']

        node.clear()
        node.insert(0, nav_list)
        node.insert(1, wrapper)

        return [node]
Ejemplo n.º 6
0
def class_directive(name, arguments, options, content, lineno, content_offset,
                    block_text, state, state_machine):
    """
    Set a "class" attribute on the directive content or the next element.
    When applied to the next element, a "pending" element is inserted, and a
    transform does the work later.
    """
    try:
        class_value = directives.class_option(arguments[0])
    except ValueError:
        error = state_machine.reporter.error(
            'Invalid class attribute value for "%s" directive: "%s".' %
            (name, arguments[0]),
            nodes.literal_block(block_text, block_text),
            line=lineno)
        return [error]
    node_list = []
    if content:
        container = nodes.Element()
        state.nested_parse(content, content_offset, container)
        for node in container:
            node['classes'].extend(class_value)
        node_list.extend(container.children)
    else:
        pending = nodes.pending(misc.ClassAttribute, {
            'class': class_value,
            'directive': name
        }, block_text)
        state_machine.document.note_pending(pending)
        node_list.append(pending)
    return node_list
Ejemplo n.º 7
0
    def run(self):
        self.assert_has_content()

        node = media()
        node.document = self.state.document
        set_source_info(self, node)

        node['classes'] = [self.name]
        node['classes'] += self.options.get('class', [])

        try:
            if self.arguments:
                node['classes'] += directives.class_option(self.arguments[0])
        except ValueError:
            err = 'Invalid class attribute value for "%s" directive: "%s".'
            raise self.error(err % (self.name, self.arguments[0]))

        self.add_name(node)
        self.state.nested_parse(self.content, self.content_offset, node)

        # Add media-object class to child images
        if isinstance(node.children[0], nodes.reference):
            child_is_image = isinstance(node.children[0].children[0],
                                        nodes.image)
            if len(node.children[0].children) and child_is_image:
                node.children[0].children[0]['classes'] += ['media-object']
        elif isinstance(node.children[0], nodes.image):
            node.children[0]['classes'] += ['media-object']

        return [node]
Ejemplo n.º 8
0
class Role(Directive):

    has_content = True

    argument_pattern = re.compile(r'(%s)\s*(\(\s*(%s)\s*\)\s*)?$' %
                                  ((states.Inliner.simplename, ) * 2))

    def run(self):
        """Dynamically create and register a custom interpreted text role."""
        if self.content_offset > self.lineno or not self.content:
            raise self.error('"%s" directive requires arguments on the first '
                             'line.' % self.name)
        args = self.content[0]
        match = self.argument_pattern.match(args)
        if not match:
            raise self.error('"%s" directive arguments not valid role names: '
                             '"%s".' % (self.name, args))
        new_role_name = match.group(1)
        base_role_name = match.group(3)
        messages = []
        if base_role_name:
            base_role, messages = roles.role(base_role_name,
                                             self.state_machine.language,
                                             self.lineno, self.state.reporter)
            if base_role is None:
                error = self.state.reporter.error(
                    'Unknown interpreted text role "%s".' % base_role_name,
                    nodes.literal_block(self.block_text, self.block_text),
                    line=self.lineno)
                return messages + [error]
        else:
            base_role = roles.generic_custom_role
        assert not hasattr(base_role, 'arguments'), (
            'Supplemental directive arguments for "%s" directive not '
            'supported (specified by "%r" role).' % (self.name, base_role))
        try:
            converted_role = convert_directive_function(base_role)
            (arguments, options, content,
             content_offset) = (self.state.parse_directive_block(
                 self.content[1:],
                 self.content_offset,
                 converted_role,
                 option_presets={}))
        except states.MarkupError, detail:
            error = self.state_machine.reporter.error(
                'Error in "%s" directive:\n%s.' % (self.name, detail),
                nodes.literal_block(self.block_text, self.block_text),
                line=self.lineno)
            return messages + [error]
        if 'class' not in options:
            try:
                options['class'] = directives.class_option(new_role_name)
            except ValueError, detail:
                error = self.state_machine.reporter.error(
                    u'Invalid argument for "%s" directive:\n%s.' %
                    (self.name, SafeString(detail)),
                    nodes.literal_block(self.block_text, self.block_text),
                    line=self.lineno)
                return messages + [error]
Ejemplo n.º 9
0
def class_option_list(argument):
   """ convert to list of list of classes
   """
   if ',' in argument:
      args = argument.split(',')
   else:
      args = argument.split()
   return [directives.class_option(arg) for arg in args]
Ejemplo n.º 10
0
def class_option_list(argument):
    """ convert to list of list of classes
   """
    if ',' in argument:
        args = argument.split(',')
    else:
        args = argument.split()
    return [directives.class_option(arg) for arg in args]
Ejemplo n.º 11
0
    def run(self):
        try:
            class_value = directives.class_option(self.arguments[0])
        except ValueError:
            raise self.error('Invalid class attribute value for "%s" directive: "%s".' % (self.name, self.arguments[0]))

        parent = self.state.parent
        if isinstance(parent, nodes.list_item):
            parent["classes"].extend(class_value)
        return []
Ejemplo n.º 12
0
    def run(self):
        node = nodes.container()
        node['classes'] = ['clearfix']

        if self.arguments:
            classes = directives.class_option(self.arguments[0])
            node['classes'].extend(classes)
        node['classes'] += self.options.get('class', [])
        self.add_name(node)

        return [node]
Ejemplo n.º 13
0
    def run(self):
        try:
            class_value = directives.class_option(self.arguments[0])
        except ValueError:
            raise self.error(
                'Invalid class attribute value for "%s" directive: "%s".'
                % (self.name, self.arguments[0]))

        parent = self.state.parent
        if isinstance(parent,nodes.list_item):
            parent['classes'].extend(class_value)
        return []
Ejemplo n.º 14
0
    def run(self):

        if self.arguments[0] in ('left', 'flushleft'):
            align_type = 'fresh-left'
        elif self.arguments[0] in ('right', 'flushright'):
            align_type = 'fresh-right'
        else:
            align_type = 'fresh-center'
        self.options['align_type'] = align_type
        self.options['classes'] = directives.class_option(align_type)

        self.assert_has_content()
        align_node = align(rawsource='\n'.join(self.content), **self.options)
        self.state.nested_parse(self.content, self.content_offset, align_node)
        for node in align_node:
            node['classes'].extend(directives.class_option(align_type))
            if ('center' not in node['classes']
                    and 'flushleft' not in node['classes']
                    and 'flushright' not in node['classes']):
                node['classes'].extend(directives.class_option(align_type))
        return [align_node]
Ejemplo n.º 15
0
 def run(self):
     """Dynamically create and register a custom interpreted text role."""
     if self.content_offset > self.lineno or not self.content:
         raise self.error('"%s" directive requires arguments on the first '
                          'line.' % self.name)
     args = self.content[0]
     match = self.argument_pattern.match(args)
     if not match:
         raise self.error('"%s" directive arguments not valid role names: '
                          '"%s".' % (self.name, args))
     new_role_name = match.group(1)
     base_role_name = match.group(3)
     messages = []
     if base_role_name:
         base_role, messages = roles.role(
             base_role_name, self.state_machine.language, self.lineno,
             self.state.reporter)
         if base_role is None:
             error = self.state.reporter.error(
                 'Unknown interpreted text role "%s".' % base_role_name,
                 nodes.literal_block(self.block_text, self.block_text),
                 line=self.lineno)
             return messages + [error]
     else:
         base_role = roles.generic_custom_role
     assert not hasattr(base_role, 'arguments'), (
         'Supplemental directive arguments for "%s" directive not '
         'supported (specified by "%r" role).' % (self.name, base_role))
     try:
         converted_role = convert_directive_function(base_role)
         (arguments, options, content, content_offset) = (
             self.state.parse_directive_block(
             self.content[1:], self.content_offset, converted_role,
             option_presets={}))
     except states.MarkupError as detail:
         error = self.state_machine.reporter.error(
             'Error in "%s" directive:\n%s.' % (self.name, detail),
             nodes.literal_block(self.block_text, self.block_text),
             line=self.lineno)
         return messages + [error]
     if 'class' not in options:
         try:
             options['class'] = directives.class_option(new_role_name)
         except ValueError as detail:
             error = self.state_machine.reporter.error(
                 'Invalid argument for "%s" directive:\n%s.'
                 % (self.name, SafeString(detail)), nodes.literal_block(
                 self.block_text, self.block_text), line=self.lineno)
             return messages + [error]
     role = roles.CustomRole(new_role_name, base_role, options, content)
     roles.register_local_role(new_role_name, role)
     return messages
Ejemplo n.º 16
0
    def run(self):

        if self.arguments[0] in ('left', 'flushleft'):
            align_type = 'fresh-left'
        elif self.arguments[0] in ('right', 'flushright'):
            align_type = 'fresh-right'
        else:
            align_type = 'fresh-center'
        self.options['align_type'] = align_type
        self.options['classes'] = directives.class_option(align_type)


        self.assert_has_content()
        align_node = align(rawsource='\n'.join(self.content), **self.options)
        self.state.nested_parse(self.content, self.content_offset, align_node)
        for node in align_node:
            node['classes'].extend(directives.class_option(align_type))
            if ('center' not in node['classes'] and
                    'flushleft' not in node['classes'] and
                    'flushright' not in node['classes'] ):
                node['classes'].extend(directives.class_option(align_type))
        return [align_node]
Ejemplo n.º 17
0
    def run(self):
        self.assert_has_content()
        env = self.state.document.settings.env
        text = '\n'.join(self.content)
        node = DivNode(text)

        node['classes'].extend(directives.class_option(env.config['bootstrap_styled_topic_classes']))
        if 'class' in self.options:
            node['classes'].extend(self.options['class'])

        self.state.nested_parse(self.content, self.content_offset, node)

        return [node]
Ejemplo n.º 18
0
 def run(self):
     details = self.options
     args = self.arguments
     if args:
         try:
             details.update(class_=directives.class_option(args[0]))
         except ValueError:
             raise self.error(
                 'Invalid class attribute value for "%s" directive: "%s".' %
                 (self.name, args[0]))
     pending = nodes.pending(RevealData, details, self.block_text)
     self.state_machine.document.note_pending(pending)
     return [pending]
Ejemplo n.º 19
0
    def run(self):
        self.assert_has_content()

        node = list_group()
        node['classes'] = ['list-group']
        node['classes'] += self.options.get('class', [])

        if self.arguments:
            node['classes'] += directives.class_option(self.arguments[0])

        self.add_name(node)
        self.state.nested_parse(self.content, self.content_offset, node)

        return [node]
Ejemplo n.º 20
0
Archivo: body.py Proyecto: srid/debris
 def run(self):
     self.assert_has_content()
     text = "\n".join(self.content)
     try:
         if self.arguments:
             classes = directives.class_option(self.arguments[0])
         else:
             classes = []
     except ValueError:
         raise self.error('Invalid class attribute value for "%s" directive: "%s".' % (self.name, self.arguments[0]))
     node = nodes.container(text)
     node["classes"].extend(classes)
     self.state.nested_parse(self.content, self.content_offset, node)
     return [node]
Ejemplo n.º 21
0
    def run(self):
        # css class is the same as the directive name
        classes = [self.name]
        if self.arguments:
            try:
                classes.extend(directives.class_option(self.arguments[0]))
            except ValueError:
                raise self.error(
                    'Invalid class attribute value for "%s" directive: "%s".' % (self.name, self.arguments[0])
                )

        pending = nodes.pending(
            BlockLines, {"directive": self.name, "class": classes, "allpage": self.allpage}, self.block_text
        )
        self.state_machine.document.note_pending(pending)
        return [pending]
Ejemplo n.º 22
0
 def run(self):
     self.assert_has_content()
     text = '\n'.join(self.content)
     try:
         if self.arguments:
             classes = directives.class_option(self.arguments[0])
         else:
             classes = []
     except ValueError:
         raise self.error(
             'Invalid class attribute value for "%s" directive: "%s".' %
             (self.name, self.arguments[0]))
     node = nodes.container(text)
     node['classes'].extend(classes)
     self.state.nested_parse(self.content, self.content_offset, node)
     return [node]
Ejemplo n.º 23
0
    def run(self):
        self.assert_has_content()

        node = nodes.bullet_list()
        node.document = self.state.document
        set_source_info(self, node)

        node['classes'] = ['media-list']
        node['classes'] += self.options.get('class', [])

        if self.arguments:
            node['classes'] += directives.class_option(self.arguments[0])

        self.add_name(node)
        self.state.nested_parse(self.content, self.content_offset, node)

        return [node]
Ejemplo n.º 24
0
    def run(self):
        self.assert_has_content()
        text = '\n'.join(self.content)
        node = nodes.container(text, **self.options)
        node['classes'] = ['btn-toolbar']
        node['classes'] += self.options.get('class', [])
        node['html_attributes'] = {
            'role': 'toolbar',
        }

        if self.arguments:
            node['classes'] += directives.class_option(self.arguments[0])

        self.state.nested_parse(self.content, self.content_offset, node)
        self.add_name(node)

        return [node]
Ejemplo n.º 25
0
def class_directive(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine):
    """
    Set a "class" attribute on the next element.
    A "pending" element is inserted, and a transform does the work later.
    """
    try:
        class_value = directives.class_option(arguments[0])
    except ValueError:
        error = state_machine.reporter.error(
            'Invalid class attribute value for "%s" directive: "%s".' % (name, arguments[0]),
            nodes.literal_block(block_text, block_text),
            line=lineno,
        )
        return [error]
    pending = nodes.pending(misc.ClassAttribute, {"class": class_value, "directive": name}, block_text)
    state_machine.document.note_pending(pending)
    return [pending]
Ejemplo n.º 26
0
    def run(self):
        global id_count

        self.assert_has_content()
        text = '\n'.join(self.content)

        classes = directives.class_option(self.arguments[0])

        node = specialnote(text)

        node['classes'].extend(classes)
        node['title'] = self.arguments[0]
        node['myid'] = "specialnote-id" + str(id_count)
        id_count = id_count + 1

        self.state.nested_parse(self.content, self.content_offset, node)

        return [node]
Ejemplo n.º 27
0
    def run(self):
        global id_count

        self.assert_has_content()
        text = '\n'.join(self.content)

        classes = directives.class_option(self.arguments[0])

        node = specialnote(text)

        node['classes'].extend(classes)
        node['title'] = self.arguments[0]
        node['myid'] = "specialnote-id" + str(id_count)
        id_count = id_count + 1

        self.state.nested_parse(self.content, self.content_offset, node)

        return [node]
Ejemplo n.º 28
0
    def run(self):
        node = nodes.container()
        node['classes'] = [self.node_class]

        if self.arguments:
            try:
                classes = directives.class_option(self.arguments[0])
                node['classes'].extend(classes)
            except ValueError:
                err = 'Invalid class attribute value for "%s" directive: "%s".'
                raise self.error(err % (self.name, self.arguments[0]))
        node['classes'] += self.options.get('class', [])

        node['html_attributes'] = {}

        self.state.nested_parse(self.content, self.content_offset, node)
        self.add_name(node)

        return [node]
Ejemplo n.º 29
0
Archivo: misc.py Proyecto: srid/debris
 def run(self):
     try:
         class_value = directives.class_option(self.arguments[0])
     except ValueError:
         raise self.error('Invalid class attribute value for "%s" directive: "%s".' % (self.name, self.arguments[0]))
     node_list = []
     if self.content:
         container = nodes.Element()
         self.state.nested_parse(self.content, self.content_offset, container)
         for node in container:
             node["classes"].extend(class_value)
         node_list.extend(container.children)
     else:
         pending = nodes.pending(
             misc.ClassAttribute, {"class": class_value, "directive": self.name}, self.block_text
         )
         self.state_machine.document.note_pending(pending)
         node_list.append(pending)
     return node_list
Ejemplo n.º 30
0
    def set_classes(self, node):
        """Set the classes on the node."""
        try:
            if self.default_class is not None and self.arguments:
                classes = self.default_class + self.arguments
            elif self.arguments:
                classes = directives.class_option(self.arguments[0])
            else:
                classes = self.default_class
        except ValueError:
            raise self.error(
                "Invalid class attribute value for '{}' directive: '{}'.".format(
                    self.name, self.arguments[0]
                )
            )

        if classes:
            node["classes"].extend(classes)

        return node
Ejemplo n.º 31
0
    def match_shorthand_class_via_argument(self, argument):
        """
        Users can pass `12,-,6,-` via an *argument*, match and return it if so
        also, create and return other user provided node classes
        """
        arg_classes = argument.split(' ')
        shorthand = None
        node_classes = []

        for i, c in enumerate(arg_classes):
            rx = r"^(?:[0-9]+|[-]{,1})(?:,?)((?:[0-9]+|[-]{,1})(?:,))?" \
                 r"((?:[0-9]+|[-]{,1})(?:,))?(?:[0-9]+|[-]{,1})$"
            match = re.match(rx, c)
            if match:
                shorthand = match.group()
                arg_classes[i] = ''
            else:
                node_classes += directives.class_option(c)

        return shorthand, node_classes
Ejemplo n.º 32
0
def class_directive(name, arguments, options, content, lineno, content_offset,
                    block_text, state, state_machine):
    """
    Set a "class" attribute on the next element.
    A "pending" element is inserted, and a transform does the work later.
    """
    try:
        class_value = directives.class_option(arguments[0])
    except ValueError:
        error = state_machine.reporter.error(
            'Invalid class attribute value for "%s" directive: "%s".' %
            (name, arguments[0]),
            nodes.literal_block(block_text, block_text),
            line=lineno)
        return [error]
    pending = nodes.pending(misc.ClassAttribute, {
        'class': class_value,
        'directive': name
    }, block_text)
    state_machine.document.note_pending(pending)
    return [pending]
Ejemplo n.º 33
0
    def run(self):
        self.assert_has_content()

        node = media()
        node.document = self.state.document
        set_source_info(self, node)

        node['classes'] = ['media']
        node['classes'] += self.options.get('class', [])

        if self.arguments:
            node['classes'] += directives.class_option(self.arguments[0])

        self.add_name(node)
        self.state.nested_parse(self.content, self.content_offset, node)

        if isinstance(node.children[0], media) and \
                'media-right' in node.children[0]['classes']:
            # Move media-right to after media-body
            node.children.append(node.children.pop(0))

        return [node]
Ejemplo n.º 34
0
    def run(self):
        self.assert_has_content()
        text = '\n'.join(self.content)

        node = modal(text, **self.options)
        node.document = self.state.document
        set_source_info(self, node)

        node['classes'] += ['modal', 'fade']
        node['classes'] += self.options.get('class', [])

        if self.arguments:
            node['classes'] += directives.class_option(self.arguments[0])

        if 'name' not in self.options:
            raise self.warning('A modal must have a "name" '
                               '(to be referenced by).')

        self.state.nested_parse(self.content, self.content_offset, node)
        self.add_name(node)

        return [node]
Ejemplo n.º 35
0
 def run(self):
     if not self.content:
         return []
     args = self.arguments
     if args:
         try:
             classes = directives.class_option(args[0])
         except ValueError:
             raise self.error(
                 'Invalid class attribute value for "%s" directive: "%s".' %
                 (self.name, args[0]))
     else:
         classes = None
     # Warning: An aside:: directive on the title page can badly damage
     # the entire document, as this section will be removed and its
     # contents reinterpreted in that case.
     node = nodes.section()
     self.state.nested_parse(self.content, self.content_offset, node)
     node.aside_section = True  # Hack to convert section to aside.
     if classes:
         node['classes'].extend(classes)
     return [node]
Ejemplo n.º 36
0
def container(name, arguments, options, content, lineno,
              content_offset, block_text, state, state_machine):
    text = '\n'.join(content)
    if not text:
        error = state_machine.reporter.error(
            'The "%s" directive is empty; content required.' % name,
            nodes.literal_block(block_text, block_text), line=lineno)
        return [error]
    try:
        if arguments:
            classes = directives.class_option(arguments[0])
        else:
            classes = []
    except ValueError:
        error = state_machine.reporter.error(
            'Invalid class attribute value for "%s" directive: "%s".'
            % (name, arguments[0]),
            nodes.literal_block(block_text, block_text), line=lineno)
        return [error]
    node = nodes.container(text)
    node['classes'].extend(classes)
    state.nested_parse(content, content_offset, node)
    return [node]
Ejemplo n.º 37
0
 def run(self):
     try:
         class_value = directives.class_option(self.arguments[0])
     except ValueError:
         raise self.error(
             'Invalid class attribute value for "%s" directive: "%s".' %
             (self.name, self.arguments[0]))
     node_list = []
     if self.content:
         container = nodes.Element()
         self.state.nested_parse(self.content, self.content_offset,
                                 container)
         for node in container:
             node['classes'].extend(class_value)
         node_list.extend(container.children)
     else:
         pending = nodes.pending(misc.ClassAttribute, {
             'class': class_value,
             'directive': self.name
         }, self.block_text)
         self.state_machine.document.note_pending(pending)
         node_list.append(pending)
     return node_list
Ejemplo n.º 38
0
    def run(self):
        self.assert_has_content()

        node = list_group_item()
        node['classes'] = ['list-group-item']
        node['classes'] += self.options.get('class', [])
        if self.node_classes is not None:
            node['classes'] += self.node_classes

        node['href'] = self.options.get('href', None)

        if 'target' in self.options:
            node['target'] = self.options.get('target')

        if 'button' in self.options:
            node['button'] = self.options.get('button')

        if self.arguments:
            node['classes'] += directives.class_option(self.arguments[0])

        self.add_name(node)
        self.state.nested_parse(self.content, self.content_offset, node)

        # Unwrap heading nodes and add classes
        headings = node.traverse(inline_heading.heading_role_node)
        for i, heading in enumerate(headings):
            heading['classes'] += ['list-group-item-heading']
            if isinstance(heading.parent, nodes.paragraph):
                heading.parent.replace_self(heading)

        if len(node.children) > 1:
            paragraphs = node.traverse(nodes.paragraph)
            for i, p in enumerate(paragraphs):
                p['classes'] += ['list-group-item-text']

        return [node]
Ejemplo n.º 39
0
        '(specified by "%r" role).' % (name, base_role))
    try:
        (arguments, options, content,
         content_offset) = (state.parse_directive_block(content[1:],
                                                        content_offset,
                                                        base_role,
                                                        option_presets={}))
    except states.MarkupError, detail:
        error = state_machine.reporter.error(
            'Error in "%s" directive:\n%s.' % (name, detail),
            nodes.literal_block(block_text, block_text),
            line=lineno)
        return messages + [error]
    if not options.has_key('class'):
        try:
            options['class'] = directives.class_option(new_role_name)
        except ValueError, detail:
            error = state_machine.reporter.error(
                'Invalid argument for "%s" directive:\n%s.' % (name, detail),
                nodes.literal_block(block_text, block_text),
                line=lineno)
            return messages + [error]
    role = roles.CustomRole(new_role_name, base_role, options, content)
    roles.register_local_role(new_role_name, role)
    return messages


role.content = 1


def default_role(name, arguments, options, content, lineno, content_offset,
Ejemplo n.º 40
0
def class_option_list(argument):
    """convert to list of list of classes"""
    args = _split_argument_list(argument)
    return [directives.class_option(arg) for arg in args]
Ejemplo n.º 41
0
    assert not hasattr(base_role, "arguments"), (
        'Supplemental directive arguments for "%s" directive not supported'
        '(specified by "%r" role).' % (name, base_role)
    )
    try:
        (arguments, options, content, content_offset) = state.parse_directive_block(
            content[1:], content_offset, base_role, option_presets={}
        )
    except states.MarkupError, detail:
        error = state_machine.reporter.error(
            'Error in "%s" directive:\n%s.' % (name, detail), nodes.literal_block(block_text, block_text), line=lineno
        )
        return messages + [error]
    if not options.has_key("class"):
        try:
            options["class"] = directives.class_option(new_role_name)
        except ValueError, detail:
            error = state_machine.reporter.error(
                'Invalid argument for "%s" directive:\n%s.' % (name, detail),
                nodes.literal_block(block_text, block_text),
                line=lineno,
            )
            return messages + [error]
    role = roles.CustomRole(new_role_name, base_role, options, content)
    roles.register_local_role(new_role_name, role)
    return messages


role.content = 1

Ejemplo n.º 42
0
    def run(self):
        if len(self.arguments) > 0:
            try:
                class_value = directives.class_option(self.arguments[0])
            except ValueError:
                raise self.error(
                    'Invalid class attribute value for "%s" directive: "%s".' %
                    (self.name, self.arguments[0]))
        else:
            class_value = None

        if 'attributes' in self.options and self.options[
                'attributes'] is not None:
            try:
                attributes = ast.literal_eval(self.options['attributes'])
            except ValueError:
                raise self.error('Could not parse attribute string: "%s"' %
                                 self.options['attributes'])
                attributes = None
        else:
            attributes = None

        if 'slide-attributes' in self.options and self.options[
                'slide-attributes'] is not None:
            try:
                slide_attributes = ast.literal_eval(
                    self.options['slide-attributes'])
            except ValueError:
                raise self.error(
                    'Could not parse slide-attribute string: "%s"' %
                    self.options['slide-attributes'])
                slide_attributes = None
        else:
            slide_attributes = None

        node_list = []
        if self.content:
            container = nodes.Element()
            self.state.nested_parse(self.content, self.content_offset,
                                    container)
            for node in container:
                if class_value is not None:
                    node['classes'].extend(class_value)
                if attributes is not None:
                    if 'attributes' in node:
                        node['attributes'].update(attributes)
                    else:
                        node['attributes'] = attributes
                if slide_attributes is not None:
                    if 'slide-attributes' in node:
                        node['slide-attributes'].update(slide_attributes)
                    else:
                        node['slide-attributes'] = slide_attributes

            node_list.extend(container.children)
        else:
            if 'attributes' in self.options and self.options[
                    'attributes'] is not None:
                try:
                    attributes = ast.literal_eval(self.options['attributes'])
                except ValueError:
                    raise self.error('Could not parse attribute string: "%s"' %
                                     self.options['attributes'])
                    attributes = None
            else:
                attributes = None
            if 'slide-attributes' in self.options and self.options[
                    'slide-attributes'] is not None:
                try:
                    slide_attributes = ast.literal_eval(
                        self.options['slide-attributes'])
                except ValueError:
                    raise self.error(
                        'Could not parse slide-attribute string: "%s"' %
                        self.options['slide-attributes'])
                    slide_attributes = None
            else:
                slide_attributes = None
            pending = nodes.pending(
                ClassAttribute2, {
                    'class': class_value,
                    'directive': self.name,
                    'attributes': attributes,
                    'slide-attributes': slide_attributes
                }, self.block_text)
            self.state_machine.document.note_pending(pending)
            node_list.append(pending)
        return node_list
Ejemplo n.º 43
0
    def run(self):
        # self.assert_has_content()
        text = '\n'.join(self.content)
        node = nodes.container(text)

        try:
            if self.default_class is not None and self.arguments:
                classes = self.default_class + self.arguments
            elif self.arguments:
                classes = directives.class_option(self.arguments[0])
            else:
                classes = self.default_class
        except ValueError:
            raise self.error(
                'Invalid class attribute value for "{}" directive: "{}".'.format(
                    self.name, self.arguments[0]))

        if classes:
            node['classes'].extend(classes)

        try:
            if 'tagname' in self.options:
                node.tagname = self.options.get('tagname', 'div')
            elif self.default_tagname is not None:
                node.tagname = self.default_tagname
            else:
                node.tagname = 'div'
        except ValueError:
            raise self.error(
                'Invalid tag name for "{}" directive: "{}".'.format(
                    self.name, node.tagname))
        attrs = None
        if 'attributes' in self.options:
            attrs = self.options.get('attributes', '')
        elif self.default_attributes:
            attrs = self.default_attributes
        if attrs is not None:
            tokens = attrs.split('\n')
            try:
                attname, val = utils.extract_name_value(tokens[0])[0]
                if attname == 'id':
                    node['ids'].append(val)
                else:
                    node.attributes.update({attname: val})
            except utils.NameValueError:
                node['name'] = tokens[0]
            for token in tokens[1:]:
                try:
                    attname, val = utils.extract_name_value(token)[0]
                    if attname == 'id':
                        node['ids'].append(val)
                    else:
                        node.attributes.update({attname: val})
                except utils.NameValueError as detail:
                    line = self.state_machine.line
                    msg = self.state_machine.reporter.error(
                          'Error parsing %s tag attribute "%s": %s.'
                          % (node.tagname, token, detail), nodes.literal_block(line, line))
                    return [msg]
        if 'endless' in self.options or self.default_endless:
            node['endless'] = True
        # self.add_name(node)
        if self.content:
            self.state.nested_parse(self.content, self.content_offset, node)
        return [node]
Ejemplo n.º 44
0
 def run(self):
     # self.assert_has_content()
     text = '\n'.join(self.content)
     try:
         if self.default_class and self.arguments:
             classes = self.default_class + self.arguments
         elif self.arguments:
             classes = directives.class_option(self.arguments[0])
         else:
             classes = self.default_class
     except ValueError:
         raise self.error(
             'Invalid class attribute value for "%s" directive: "%s".'
             % (self.name, self.arguments[0]))
     node = nodes.container(text)
     if classes:
         node['classes'].extend(classes)
     try:
         if 'tagname' in self.options:
         # if self.options.has_key('tagname'):
             node.tagname = self.options.get('tagname', 'div')
         elif self.default_tagname:
             node.tagname = self.default_tagname
         else:
             node.tagname = 'div'
     except ValueError:
         raise self.error(
             'Invalid tag name for "%s" directive: "%s".'
             % (self.name, node.tagname))
     attrs = None
     if 'attributes' in self.options:
         attrs = self.options.get('attributes', '')
     elif self.default_attributes:
         attrs = self.default_attributes
     if attrs:
         tokens = attrs.split('\n')
         try:
             attname, val = utils.extract_name_value(tokens[0])[0]
             if attname == 'id':
                 node['ids'].append(val)
             else:
                 node.attributes.update({attname: val})
         except utils.NameValueError:
             node['name'] = tokens[0]
         for token in tokens[1:]:
             try:
                 attname, val = utils.extract_name_value(token)[0]
                 if attname == 'id':
                     node['ids'].append(val)
                 else:
                     node.attributes.update({attname: val})
             except utils.NameValueError as detail:
                 line = self.state_machine.line
                 msg = self.state_machine.reporter.error(
                       'Error parsing %s tag attribute "%s": %s.'
                       % (node.tagname, token, detail), nodes.literal_block(line, line))
                 return [msg]
     if 'endless' in self.options or self.default_endless:
         node['endless'] = True
     self.add_name(node)
     if self.content:
         self.state.nested_parse(self.content, self.content_offset, node)
     return [node]
Ejemplo n.º 45
0
        base_role = roles.generic_custom_role
    assert not hasattr(base_role, 'arguments'), (
        'Supplemental directive arguments for "%s" directive not supported'
        '(specified by "%r" role).' % (name, base_role))
    try:
        (arguments, options, content, content_offset) = (
            state.parse_directive_block(content[1:], content_offset, base_role,
                                        option_presets={}))
    except states.MarkupError, detail:
        error = state_machine.reporter.error(
            'Error in "%s" directive:\n%s.' % (name, detail),
            nodes.literal_block(block_text, block_text), line=lineno)
        return messages + [error]
    if not options.has_key('class'):
        try:
            options['class'] = directives.class_option(new_role_name)
        except ValueError, detail:
            error = state_machine.reporter.error(
                'Invalid argument for "%s" directive:\n%s.'
                % (name, detail),
                nodes.literal_block(block_text, block_text), line=lineno)
            return messages + [error]
    role = roles.CustomRole(new_role_name, base_role, options, content)
    roles.register_local_role(new_role_name, role)
    return messages

role.content = 1

def default_role(name, arguments, options, content, lineno,
                 content_offset, block_text, state, state_machine):
    """Set the default interpreted text role."""