def starttag(self, node, tagname, suffix='\n', **attributes):
        attr_dicts = [attributes]
        if isinstance(node, nodes.Node):
            attr_dicts.append(node.attributes)
        if isinstance(node, dict):
            attr_dicts.append(node)
        # Munge each attribute dictionary.  Unfortunately, we need to
        # iterate through attributes one at a time because some
        # versions of docutils don't case-normalize attributes.
        for attr_dict in attr_dicts:
            for (key, val) in attr_dict.items():
                # Prefix all CSS classes with "rst-"; and prefix all
                # names with "rst-" to avoid conflicts.
                if key.lower() in ('class', 'id', 'name'):
                    attr_dict[key] = 'rst-%s' % val
                elif key.lower() in ('classes', 'ids', 'names'):
                    attr_dict[key] = ['rst-%s' % cls for cls in val]
                elif key.lower() == 'href':
                    if attr_dict[key][:1] == '#':
                        attr_dict[key] = '#rst-%s' % attr_dict[key][1:]
                    else:
                        pass
        # For headings, use class="heading"
        if re.match(r'^h\d+$', tagname):
            attributes['class'] = ' '.join([attributes.get('class', ''), 'heading']).strip()

        return HTMLTranslator.starttag(self, node, tagname, suffix, **attributes)
Example #2
0
    def starttag(self, node, tagname, suffix='\n', **attributes):
        """
        This modified version of starttag makes a few changes to HTML
        tags, to prevent them from conflicting with epydoc.  In particular:
          - existing class attributes are prefixed with C{'rst-'}
          - existing names are prefixed with C{'rst-'}
          - hrefs starting with C{'#'} are prefixed with C{'rst-'}
          - hrefs not starting with C{'#'} are given target='_top'
          - all headings (C{<hM{n}>}) are given the css class C{'heading'}
        """
        # Prefix all CSS classes with "rst-"
        if attributes.has_key('class'):
            attributes['class'] = 'rst-%s' % attributes['class']

        # Prefix all names with "rst-", to avoid conflicts
        if attributes.has_key('id'):
            attributes['id'] = 'rst-%s' % attributes['id']
        if attributes.has_key('name'):
            attributes['name'] = 'rst-%s' % attributes['name']
        if attributes.has_key('href'):
            if attributes['href'][:1] == '#':
                attributes['href'] = '#rst-%s' % attributes['href'][1:]
            else:
                attributes['target'] = '_top'

        # For headings, use class="heading"
        if re.match(r'^h\d+$', tagname):
            attributes['class'] = 'heading'

        return HTMLTranslator.starttag(self, node, tagname, suffix,
                                       **attributes)
Example #3
0
    def starttag(self, node, tagname, suffix='\n', **attributes):
        attr_dicts = [attributes]
        if isinstance(node, nodes.Node):
            attr_dicts.append(node.attributes)
        if isinstance(node, dict):
            attr_dicts.append(node)
        # Munge each attribute dictionary.  Unfortunately, we need to
        # iterate through attributes one at a time because some
        # versions of docutils don't case-normalize attributes.
        for attr_dict in attr_dicts:
            for (key, val) in attr_dict.items():
                # Prefix all CSS classes with "rst-"; and prefix all
                # names with "rst-" to avoid conflicts.
                if key.lower() in ('class', 'id', 'name'):
                    attr_dict[key] = 'rst-%s' % val
                elif key.lower() in ('classes', 'ids', 'names'):
                    attr_dict[key] = ['rst-%s' % cls for cls in val]
                elif key.lower() == 'href':
                    if attr_dict[key][:1] == '#':
                        attr_dict[key] = '#rst-%s' % attr_dict[key][1:]
                    else:
                        pass
        # For headings, use class="heading"
        if re.match(r'^h\d+$', tagname):
            attributes['class'] = ' '.join(
                [attributes.get('class', ''), 'heading']).strip()

        return HTMLTranslator.starttag(self, node, tagname, suffix,
                                       **attributes)
    def starttag(self, node, tagname, suffix='\n', **attributes):
        attr_dicts = [attributes]
        if isinstance(node, nodes.Node):
            attr_dicts.append(node.attributes)
        if isinstance(node, dict):
            attr_dicts.append(node)
        # Munge each attribute dictionary.  Unfortunately, we need to
        # iterate through attributes one at a time because some
        # versions of docutils don't case-normalize attributes.
        for attr_dict in attr_dicts:
            # For some reason additional classes in bullet list make it render poorly.
            # Such lists are used to render multiple return values in Numpy docstrings by Napoleon.
            if tagname == 'ul' and isinstance(node.parent, field_body):
                attr_dict.pop('class', None)
                attr_dict.pop('classes', None)
                continue

            for (key, val) in attr_dict.items():
                # Prefix all CSS classes with "rst-"; and prefix all
                # names with "rst-" to avoid conflicts.
                if key.lower() in ('class', 'id', 'name'):
                    attr_dict[key] = 'rst-%s' % val
                elif key.lower() in ('classes', 'ids', 'names'):
                    attr_dict[key] = ['rst-%s' % cls for cls in val]
                elif key.lower() == 'href':
                    if attr_dict[key][:1] == '#':
                        attr_dict[key] = '#rst-%s' % attr_dict[key][1:]

        if tagname == 'th' and isinstance(node, field_name):
            attributes['valign'] = 'top'

        # For headings, use class="heading"
        if re.match(r'^h\d+$', tagname):
            attributes['class'] = ' '.join([attributes.get('class', ''), 'heading']).strip()
        return HTMLTranslator.starttag(self, node, tagname, suffix, **attributes)
Example #5
0
    def starttag(self, node, tagname, suffix='\n', **attributes):
        """
        This modified version of starttag makes a few changes to HTML
        tags, to prevent them from conflicting with epydoc.  In particular:
          - existing class attributes are prefixed with C{'rst-'}
          - existing names are prefixed with C{'rst-'}
          - hrefs starting with C{'#'} are prefixed with C{'rst-'}
          - hrefs not starting with C{'#'} are given target='_top'
          - all headings (C{<hM{n}>}) are given the css class C{'heading'}
        """
        # Prefix all CSS classes with "rst-"
        if attributes.has_key('class'):
            attributes['class'] = 'rst-%s' % attributes['class']

        # Prefix all names with "rst-", to avoid conflicts
        if attributes.has_key('id'):
            attributes['id'] = 'rst-%s' % attributes['id']
        if attributes.has_key('name'):
            attributes['name'] = 'rst-%s' % attributes['name']
        if attributes.has_key('href'):
            if attributes['href'][:1]=='#':
                attributes['href'] = '#rst-%s' % attributes['href'][1:]
            else:
                attributes['target'] = '_top'

        # For headings, use class="heading"
        if re.match(r'^h\d+$', tagname):
            attributes['class'] = 'heading'
        
        return HTMLTranslator.starttag(self, node, tagname, suffix,
                                       **attributes)
    def starttag(self, node, tagname, suffix="\n", **attributes):
        attr_dicts = [attributes]
        if isinstance(node, nodes.Node):
            attr_dicts.append(node.attributes)
        if isinstance(node, dict):
            attr_dicts.append(node)
        # Munge each attribute dictionary.  Unfortunately, we need to
        # iterate through attributes one at a time because some
        # versions of docutils don't case-normalize attributes.
        for attr_dict in attr_dicts:
            for (key, val) in attr_dict.items():
                # Prefix all CSS classes with "rst-"; and prefix all
                # names with "rst-" to avoid conflicts.
                if key.lower() in ("class", "id", "name"):
                    attr_dict[key] = "rst-%s" % val
                elif key.lower() in ("classes", "ids", "names"):
                    attr_dict[key] = ["rst-%s" % cls for cls in val]
                elif key.lower() == "href":
                    if attr_dict[key][:1] == "#":
                        attr_dict[key] = "#rst-%s" % attr_dict[key][1:]
                    else:
                        pass
        # For headings, use class="heading"
        if re.match(r"^h\d+$", tagname):
            attributes["class"] = " ".join([attributes.get("class", ""), "heading"]).strip()

        return HTMLTranslator.starttag(self, node, tagname, suffix, **attributes)
Example #7
0
def starttag_data(self, node, tagname, suffix='\n', empty=False, **attributes):
    attributes.update(
        (k, v) for k, v in node.attributes.iteritems()
        if k.startswith('data-')
    )
    # oh dear
    return DocutilsTranslator.starttag(
        self, node, tagname, suffix=suffix, empty=empty, **attributes)
def starttag_data(self, node, tagname, suffix='\n', empty=False, **attributes):
    attributes.update(
        (k, v) for k, v in node.attributes.iteritems()
        if k.startswith('data-')
    )
    # oh dear
    return DocutilsTranslator.starttag(
        self, node, tagname, suffix=suffix, empty=empty, **attributes)
Example #9
0
    def starttag(self, node, tagname, suffix='\n', **attributes):
        """
        This modified version of starttag makes a few changes to HTML
        tags, to prevent them from conflicting with epydoc.  In particular:
          - existing class attributes are prefixed with C{'rst-'}
          - existing names are prefixed with C{'rst-'}
          - hrefs starting with C{'#'} are prefixed with C{'rst-'}
          - hrefs not starting with C{'#'} are given target='_top'
          - all headings (C{<hM{n}>}) are given the css class C{'heading'}
        """
        # Get the list of all attribute dictionaries we need to munge.
        attr_dicts = [attributes]
        if isinstance(node, docutils.nodes.Node):
            attr_dicts.append(node.attributes)
        if isinstance(node, dict):
            attr_dicts.append(node)
        # Munge each attribute dictionary.  Unfortunately, we need to
        # iterate through attributes one at a time because some
        # versions of docutils don't case-normalize attributes.
        for attr_dict in attr_dicts:
            for (key, val) in attr_dict.items():
                # Prefix all CSS classes with "rst-"; and prefix all
                # names with "rst-" to avoid conflicts.
                if key.lower() in ('class', 'id', 'name'):
                    attr_dict[key] = 'rst-%s' % val
                elif key.lower() in ('classes', 'ids', 'names'):
                    attr_dict[key] = ['rst-%s' % cls for cls in val]
                elif key.lower() == 'href':
                    if attr_dict[key][:1] == '#':
                        attr_dict[key] = '#rst-%s' % attr_dict[key][1:]
                    else:
                        # If it's an external link, open it in a new
                        # page.
                        attr_dict['target'] = '_top'

        # For headings, use class="heading"
        if re.match(r'^h\d+$', tagname):
            attributes['class'] = ' '.join(
                [attributes.get('class', ''), 'heading']).strip()

        return HTMLTranslator.starttag(self, node, tagname, suffix,
                                       **attributes)
Example #10
0
    def starttag(self, node, tagname, suffix='\n', **attributes):
        """
        This modified version of starttag makes a few changes to HTML
        tags, to prevent them from conflicting with epydoc.  In particular:
          - existing class attributes are prefixed with C{'rst-'}
          - existing names are prefixed with C{'rst-'}
          - hrefs starting with C{'#'} are prefixed with C{'rst-'}
          - hrefs not starting with C{'#'} are given target='_top'
          - all headings (C{<hM{n}>}) are given the css class C{'heading'}
        """
        # Get the list of all attribute dictionaries we need to munge.
        attr_dicts = [attributes]
        if isinstance(node, docutils.nodes.Node):
            attr_dicts.append(node.attributes)
        if isinstance(node, dict):
            attr_dicts.append(node)
        # Munge each attribute dictionary.  Unfortunately, we need to
        # iterate through attributes one at a time because some
        # versions of docutils don't case-normalize attributes.
        for attr_dict in attr_dicts:
            for (key, val) in attr_dict.items():
                # Prefix all CSS classes with "rst-"; and prefix all
                # names with "rst-" to avoid conflicts.
                if key.lower() in ('class', 'id', 'name'):
                    attr_dict[key] = 'rst-%s' % val
                elif key.lower() in ('classes', 'ids', 'names'):
                    attr_dict[key] = ['rst-%s' % cls for cls in val]
                elif key.lower() == 'href':
                    if attr_dict[key][:1]=='#':
                        attr_dict[key] = '#rst-%s' % attr_dict[key][1:]
                    else:
                        # If it's an external link, open it in a new
                        # page.
                        attr_dict['target'] = '_top'

        # For headings, use class="heading"
        if re.match(r'^h\d+$', tagname):
            attributes['class'] = ' '.join([attributes.get('class',''),
                                            'heading']).strip()
        
        return HTMLTranslator.starttag(self, node, tagname, suffix,
                                       **attributes)
    def starttag(self, node, tagname, suffix='\n', **attributes):
        attr_dicts = [attributes]
        if isinstance(node, nodes.Node):
            attr_dicts.append(node.attributes)
        if isinstance(node, dict):
            attr_dicts.append(node)
        # Munge each attribute dictionary.  Unfortunately, we need to
        # iterate through attributes one at a time because some
        # versions of docutils don't case-normalize attributes.
        for attr_dict in attr_dicts:
            # For some reason additional classes in bullet list make it render poorly.
            # Such lists are used to render multiple return values in Numpy docstrings by Napoleon.
            if tagname == 'ul' and isinstance(node.parent, field_body):
                attr_dict.pop('class', None)
                attr_dict.pop('classes', None)
                continue

            for (key, val) in attr_dict.items():
                # Prefix all CSS classes with "rst-"; and prefix all
                # names with "rst-" to avoid conflicts.
                if key.lower() in ('class', 'id', 'name'):
                    attr_dict[key] = 'rst-%s' % val
                elif key.lower() in ('classes', 'ids', 'names'):
                    attr_dict[key] = ['rst-%s' % cls for cls in val]
                elif key.lower() == 'href':
                    if attr_dict[key][:1] == '#':
                        attr_dict[key] = '#rst-%s' % attr_dict[key][1:]

        if tagname == 'th' and isinstance(node, field_name):
            attributes['valign'] = 'top'

        # Render rubric start as HTML header
        if tagname == 'p' and isinstance(node, rubric):
            tagname = 'h1'

        # For headings, use class="heading"
        if re.match(r'^h\d+$', tagname):
            attributes['class'] = ' '.join([attributes.get('class', ''), 'heading']).strip()
        return HTMLTranslator.starttag(self, node, tagname, suffix, **attributes)
Example #12
0
    def starttag(self, node, tagname, suffix="\n", **attributes):
        attr_dicts = [attributes]
        if isinstance(node, nodes.Node):
            attr_dicts.append(node.attributes)
        if isinstance(node, dict):
            attr_dicts.append(node)
        # Munge each attribute dictionary.  Unfortunately, we need to
        # iterate through attributes one at a time because some
        # versions of docutils don't case-normalize attributes.
        for attr_dict in attr_dicts:
            # For some reason additional classes in bullet list make it render poorly.
            # Such lists are used to render multiple return values in Numpy docstrings by Napoleon.
            if tagname == "ul" and isinstance(node.parent, field_body):
                attr_dict.pop("class", None)
                attr_dict.pop("classes", None)
                continue

            for (key, val) in attr_dict.items():
                # Prefix all CSS classes with "rst-"; and prefix all
                # names with "rst-" to avoid conflicts.
                if key.lower() in ("class", "id", "name"):
                    attr_dict[key] = "rst-%s" % val
                elif key.lower() in ("classes", "ids", "names"):
                    attr_dict[key] = ["rst-%s" % cls for cls in val]
                elif key.lower() == "href":
                    if attr_dict[key][:1] == "#":
                        attr_dict[key] = "#rst-%s" % attr_dict[key][1:]

        if tagname == "th" and isinstance(node, field_name):
            attributes["valign"] = "top"

        # Render rubric start as HTML header
        if tagname == "p" and isinstance(node, rubric):
            tagname = "h1"

        # For headings, use class="heading"
        if re.match(r"^h\d+$", tagname):
            attributes["class"] = " ".join([attributes.get("class", ""), "heading"]).strip()
        return HTMLTranslator.starttag(self, node, tagname, suffix, **attributes)