Example #1
0
 def visit_section(self, node):
     '''Give each section a unique ID -- nice for custom CSS hooks'''
     old_ids = node.get('ids', [])
     node['ids'] = ['s-' + i for i in old_ids]
     node['ids'].extend(old_ids)
     SmartyPantsHTMLTranslator.visit_section(self, node)
     node['ids'] = old_ids
Example #2
0
 def visit_section(self, node):
     '''Give each section a unique ID -- nice for custom CSS hooks'''
     old_ids = node.get('ids', [])
     node['ids'] = ['s-' + i for i in old_ids]
     node['ids'].extend(old_ids)
     SmartyPantsHTMLTranslator.visit_section(self, node)
     node['ids'] = old_ids
 def visit_reference(self, node):
   # In "kill_internal_links" mode, we don't emit the actual links for internal
   # nodes.
   if self.builder.chromesite_kill_internal_links and node.get('internal'):
     pass
   else:
     HTMLTranslator.visit_reference(self, node)
Example #4
0
    def visit_raw(self, node):
        '''replaces script tags for safety in thml raw directives'''
        # instead of copying here the node, we let the superclass do it's job and
        # we replace self.body if it contains "< script " strings

        ishtml = 'html' in node.get('format', '').split()  # copied from docutils.writers._html_base
        mark = len(self.body)
        shouldraise = False
        try:
            SmartyPantsHTMLTranslator.visit_raw(self, node)
        except nodes.SkipNode:
            if ishtml:
                shouldraise = True
            else:
                raise
        if ishtml:
            msg = ("Suspicious script injection removed for security reasons. "
                   "Please modify the document text after \".. raw:: html\"")
            # re.sub('<\\s*script\\b', 'A', a)
            for idx in xrange(mark, len(self.body)):
                if re.search("<\\s*script", self.body[idx]):
                    self.body[idx] = "<span style='color:red'>%s</span>" % msg

        if shouldraise:
            raise nodes.SkipNode  # copied from docutils.writers._html_base
Example #5
0
 def visit_reference(self, node):
   # In "kill_internal_links" mode, we don't emit the actual links for internal
   # nodes.
   if self.builder.kill_internal_links and node.get('internal'):
     pass
   else:
     HTMLTranslator.visit_reference(self, node)
Example #6
0
  def __init__(self, builder, *args, **kwds):
    # HTMLTranslator is an old-style Python class, so 'super' doesn't work: use
    # direct parent invocation.
    HTMLTranslator.__init__(self, builder, *args, **kwds)

    self.within_ignored_h1 = False
    self.within_toc = False
Example #7
0
    def __init__(self, builder, *args, **kwds):
        # HTMLTranslator is an old-style Python class, so 'super' doesn't work: use
        # direct parent invocation.
        HTMLTranslator.__init__(self, builder, *args, **kwds)

        self.within_ignored_h1 = False
        self.within_toc = False
Example #8
0
  def visit_title(self, node):
    if isinstance(node.parent, nodes.section):
      # Steal the id from the parent. This is used in chromesite to handle the
      # auto-generated navbar and permalinks.
      if node.parent.hasattr('ids'):
        node['ids'] = node.parent['ids'][:]

    HTMLTranslator.visit_title(self, node)
  def visit_title(self, node):
    if isinstance(node.parent, nodes.section):
      # Steal the id from the parent. This is used in chromesite to handle the
      # auto-generated navbar and permalinks.
      if node.parent.hasattr('ids'):
        node['ids'] = node.parent['ids'][:]

    HTMLTranslator.visit_title(self, node)
 def visit_topic(self, node):
   if 'contents' in node['classes']:
     # TODO(binji):
     # Detect a TOC: we want to hide these from chromesite, but still keep
     # them in devsite. An easy hack is to add display: none to the element
     # here.
     # When we remove devsite support, we can remove this hack.
     self.within_toc = True
     attrs = {'style': 'display: none'}
     self.body.append(self.starttag(node, 'div', **attrs))
   else:
     HTMLTranslator.visit_topic(self, node)
Example #11
0
 def visit_topic(self, node):
   if 'contents' in node['classes']:
     # TODO(binji):
     # Detect a TOC: we want to hide these from chromesite, but still keep
     # them in devsite. An easy hack is to add display: none to the element
     # here.
     # When we remove devsite support, we can remove this hack.
     self.within_toc = True
     attrs = {'style': 'display: none'}
     self.body.append(self.starttag(node, 'div', **attrs))
   else:
     HTMLTranslator.visit_topic(self, node)
Example #12
0
 def visit_field_body(self, node):
     '''just replace all asterix in authors if present'''
     if self._visiting_author_field__:
         try:
             node.rawsource = node.rawsource.replace('*', '')
             textnode = node.children[0].children[0]
             # replace asterix. Use touni cause Text nodes want unicode:
             textnode.parent.children[0] = nodes.Text(textnode.rawsource.replace(touni('*'),
                                                                                 touni('')))
         except Exception:  # pylint: disable=broad-except
             pass
     SmartyPantsHTMLTranslator.visit_field_body(self, node)
Example #13
0
  def visit_title(self, node):
    # Why this?
    #
    # Sphinx insists on inserting a <h1>Page Title</h1> into the page, but this
    # is not how the devsite wants it. The devsite inserts the page title on
    # its own, the the extra h1 is duplication.
    #
    # Killing the doctree title node in a custom transform doesn't work, because
    # Sphinx explicitly looks for it when writing a document. So instead we rig
    # the HTML produced.
    #
    # When a title node is visited, and this is the h1-to-be, we ignore it and
    # also set a flag that tells visit_Text not to print the actual text of the
    # header.

    # The h1 node is in the section whose parent is the document itself. Other
    # sections have this top-section as their parent.
    if (node.parent and node.parent.parent and
        isinstance(node.parent.parent, nodes.document)):
      # Internal flag. Also, nothing is pushed to the context. Our depart_title
      # doesn't pop anything when this flag is set.
      self.within_ignored_h1 = True
    else:
      HTMLTranslator.visit_title(self, node)
Example #14
0
    def visit_title(self, node):
        # Why this?
        #
        # Sphinx insists on inserting a <h1>Page Title</h1> into the page, but this
        # is not how the devsite wants it. The devsite inserts the page title on
        # its own, the the extra h1 is duplication.
        #
        # Killing the doctree title node in a custom transform doesn't work, because
        # Sphinx explicitly looks for it when writing a document. So instead we rig
        # the HTML produced.
        #
        # When a title node is visited, and this is the h1-to-be, we ignore it and
        # also set a flag that tells visit_Text not to print the actual text of the
        # header.

        # The h1 node is in the section whose parent is the document itself. Other
        # sections have this top-section as their parent.
        if (node.parent and node.parent.parent
                and isinstance(node.parent.parent, nodes.document)):
            # Internal flag. Also, nothing is pushed to the context. Our depart_title
            # doesn't pop anything when this flag is set.
            self.within_ignored_h1 = True
        else:
            HTMLTranslator.visit_title(self, node)
Example #15
0
 def depart_reference(self, node):
   if self.builder.kill_internal_links and node.get('internal'):
     pass
   else:
     HTMLTranslator.depart_reference(self, node)
Example #16
0
 def visit_section(self, node):
     old_ids = node.get("ids", [])
     node["ids"] = ["s-" + i for i in old_ids]
     node["ids"].extend(old_ids)
     SmartyPantsHTMLTranslator.visit_section(self, node)
     node["ids"] = old_ids
Example #17
0
 def visit_field_name(self, node):
     '''just mark an internal attribute if we are processing authors'''
     self._visiting_author_field__ = node.rawsource.lower().strip() in ('author', 'authors')
     SmartyPantsHTMLTranslator.visit_field_name(self, node)
Example #18
0
 def depart_literal_block(self, node):
     SmartyPantsHTMLTranslator.depart_literal_block(self, node)
     self.no_smarty -= 1
Example #19
0
 def depart_topic(self, node):
   if self.within_toc:
     self.body.append('\n</div>')
   else:
     HTMLTranslator.visit_topic(self, node)
Example #20
0
 def visit_paragraph(self, node):
     # Don't generate <p>s within the table of contents
     if not self.within_toc:
         HTMLTranslator.visit_paragraph(self, node)
Example #21
0
 def depart_paragraph(self, node):
     if not self.within_toc:
         HTMLTranslator.depart_paragraph(self, node)
Example #22
0
 def depart_title(self, node):
   if not self.within_ignored_h1:
     HTMLTranslator.depart_title(self, node)
   self.within_ignored_h1 = False
Example #23
0
 def visit_Text(self, node):
   if not self.within_ignored_h1:
     HTMLTranslator.visit_Text(self, node)
Example #24
0
 def depart_title(self, node):
     if not self.within_ignored_h1:
         HTMLTranslator.depart_title(self, node)
     self.within_ignored_h1 = False
Example #25
0
 def visit_section(self, node):
     old_ids = node.get("ids", [])
     node["ids"] = ["s-" + i for i in old_ids]
     node["ids"].extend(old_ids)
     SmartyPantsHTMLTranslator.visit_section(self, node)
     node["ids"] = old_ids
Example #26
0
 def visit_Text(self, node):
     if not self.within_ignored_h1:
         HTMLTranslator.visit_Text(self, node)
 def visit_image(self, node):
   # Paths to images in .rst sources should be absolute. This visitor does the
   # required transformation for the path to be correct in the final HTML.
   # if self.builder.chromesite_production_mode:
   node['uri'] = self.builder.get_production_url(node['uri'])
   HTMLTranslator.visit_image(self, node)
Example #28
0
File: conf.py Project: i386x/doit
 def __init__(self, *args, **kwargs):
     SmartyPantsHTMLTranslator.__init__(self, *args, **kwargs)
 def depart_reference(self, node):
   if self.builder.chromesite_kill_internal_links and node.get('internal'):
     pass
   else:
     HTMLTranslator.depart_reference(self, node)
Example #30
0
 def visit_paragraph(self, node):
   # Don't generate <p>s within the table of contents
   if not self.within_toc:
     HTMLTranslator.visit_paragraph(self, node)
 def depart_topic(self, node):
   if self.within_toc:
     self.body.append('\n</div>')
   else:
     HTMLTranslator.visit_topic(self, node)
Example #32
0
 def depart_paragraph(self, node):
   if not self.within_toc:
     HTMLTranslator.depart_paragraph(self, node)
Example #33
0
 def visit_literal_block(self, node):
     self.no_smarty += 1
     SmartyPantsHTMLTranslator.visit_literal_block(self, node)
Example #34
0
 def visit_image(self, node):
   # Paths to images in .rst sources should be absolute. This visitor does the
   # required transformation for the path to be correct in the final HTML.
   if self.builder.devsite_production_mode:
     node['uri'] = self.builder.get_production_url(node['uri'])
   HTMLTranslator.visit_image(self, node)
Example #35
0
 def visit_section(self, node):
     old_ids = node.get('ids', [])
     node['ids'] = ['s-' + i for i in old_ids]
     node['ids'].extend(old_ids)
     SmartyPantsHTMLTranslator.visit_section(self, node)
     node['ids'] = old_ids
Example #36
0
 def __init__(self, *args, **kwds):
     SmartyPantsHTMLTranslator.__init__(self, *args, **kwds)  # old style class...
     # set custom attributes:
     self._visiting_author_field__ = False