コード例 #1
0
ファイル: py_editor.py プロジェクト: teonbrooks/Eelbrain
    def OnCopySelectionToShell(self, event):
        if not self.editor:
            return

        self.SelectFragment()
        txt = self.editor.window.GetSelectedText()
        txt = ''.join(txt.split('\r'))  # remove carriage returns
        txt = fmtxt.unindent(txt)  # remove leading whitespaces

        lines = txt.splitlines()
        n = len(lines)
        if n == 0:
            return
        elif n > 1:
            for i in xrange(1, n):
                lines[i] = '... ' + lines[i]

        txt = os.linesep.join(lines)

        self.shell.InsertStrToShell(txt)
        self.shell.Raise()
コード例 #2
0
ファイル: help.py プロジェクト: teonbrooks/Eelbrain
def rst2html(rst):
    """
    reStructuredText to HTML parsing following:
    http://stackoverflow.com/questions/6654519
    """
    # remove leading whitespaces; make an exception for the first line, 
    # since several functions start their docstring on the first line
    rst = fmtxt.unindent(rst, True)
    
    try:
        html = docutils.core.publish_parts(rst, writer_name='html')['body']
        if "ERROR/3" in html:
            raise RuntimeError("rst2html unresolved cross-ref")
        logging.debug("rst2html success")
#            html = os.linesep.join((html['stylesheet'], html['body']))
#            html = html['whole']  
#            html = '<span style="color: rgb(0, 0, 255);">RST2HTML:</span><br>' + html
    except:
        html = HtmlTemplate % rst
        logging.debug("rst2html failed")
#            html = '<span style="color: rgb(255, 0, 0);">RST2HTML FAILED:</span><br>' + html
    return html