Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 3
0
 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)
Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 9
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)
Exemplo n.º 10
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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 15
0
 def depart_reference(self, node):
   if self.builder.kill_internal_links and node.get('internal'):
     pass
   else:
     HTMLTranslator.depart_reference(self, node)
Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 18
0
 def depart_literal_block(self, node):
     SmartyPantsHTMLTranslator.depart_literal_block(self, node)
     self.no_smarty -= 1
Exemplo n.º 19
0
 def depart_topic(self, node):
   if self.within_toc:
     self.body.append('\n</div>')
   else:
     HTMLTranslator.visit_topic(self, node)
Exemplo n.º 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)
Exemplo n.º 21
0
 def depart_paragraph(self, node):
     if not self.within_toc:
         HTMLTranslator.depart_paragraph(self, node)
Exemplo n.º 22
0
 def depart_title(self, node):
   if not self.within_ignored_h1:
     HTMLTranslator.depart_title(self, node)
   self.within_ignored_h1 = False
Exemplo n.º 23
0
 def visit_Text(self, node):
   if not self.within_ignored_h1:
     HTMLTranslator.visit_Text(self, node)
Exemplo n.º 24
0
 def depart_title(self, node):
     if not self.within_ignored_h1:
         HTMLTranslator.depart_title(self, node)
     self.within_ignored_h1 = False
Exemplo n.º 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
Exemplo n.º 26
0
 def visit_Text(self, node):
     if not self.within_ignored_h1:
         HTMLTranslator.visit_Text(self, node)
Exemplo n.º 27
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.chromesite_production_mode:
   node['uri'] = self.builder.get_production_url(node['uri'])
   HTMLTranslator.visit_image(self, node)
Exemplo n.º 28
0
Arquivo: conf.py Projeto: i386x/doit
 def __init__(self, *args, **kwargs):
     SmartyPantsHTMLTranslator.__init__(self, *args, **kwargs)
Exemplo n.º 29
0
 def depart_reference(self, node):
   if self.builder.chromesite_kill_internal_links and node.get('internal'):
     pass
   else:
     HTMLTranslator.depart_reference(self, node)
Exemplo n.º 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)
Exemplo n.º 31
0
 def depart_topic(self, node):
   if self.within_toc:
     self.body.append('\n</div>')
   else:
     HTMLTranslator.visit_topic(self, node)
Exemplo n.º 32
0
 def depart_paragraph(self, node):
   if not self.within_toc:
     HTMLTranslator.depart_paragraph(self, node)
Exemplo n.º 33
0
 def visit_literal_block(self, node):
     self.no_smarty += 1
     SmartyPantsHTMLTranslator.visit_literal_block(self, node)
Exemplo n.º 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)
Exemplo n.º 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
Exemplo n.º 36
0
 def __init__(self, *args, **kwds):
     SmartyPantsHTMLTranslator.__init__(self, *args, **kwds)  # old style class...
     # set custom attributes:
     self._visiting_author_field__ = False