Ticket #11489: trac_11489-iframe.reviewer.patch

File trac_11489-iframe.reviewer.patch, 3.8 KB (added by kini, 10 years ago)
  • sage/misc/html.py

    # HG changeset patch
    # Date 1308173676 25200
    # User Keshav Kini <keshav.kini@gmail.com>
    # Parent 879111d2bb0cd7f61dceb232a0d40385393689eb
    trac #11489: make HTML spec-conformant, change the check for URI scheme, fix some formatting
    
    diff --git a/sage/misc/html.py b/sage/misc/html.py
    a b  
    293293                                    + latex(row[column]).replace('\\texttt','\\hbox')
    294294                                    + '</span>')
    295295
    296 
    297 
    298 
    299 
    300296    def iframe(self, url, height=400, width=800):
    301297        """
    302298        Put an existing web page into a worksheet.
    303299
    304300        INPUT:
    305301
    306             - ``url`` -- a url string.  Either with or without "http://".
    307             - ``height`` -- the number of pixels for the page height.
     302            - ``url`` -- a url string, either with or without URI scheme
     303              (defaults to "http").
     304            - ``height`` -- the number of pixels for the page height.
    308305              Defaults to 400.
    309             - ``width`` -- the number of pixels for the page width. 
     306            - ``width`` -- the number of pixels for the page width.
    310307              Defaults to 800.
    311308
    312309        OUTPUT:
    313310
    314             Opens the url in a worksheet.  If the url is a regular web page
    315             it will appear in the worksheet.  This was originally intended
    316             to bring GeoGebra worksheets into Sage, but it can be used for
    317             many other purposes.
    318 
     311            Opens the url in a worksheet. If the url is a regular web page it
     312            will appear in the worksheet. This was originally intended to bring
     313            GeoGebra worksheets into Sage, but it can be used for many other
     314            purposes.
    319315
    320316        EXAMPLES::
    321        
     317
    322318            sage: html.iframe("sagemath.org")
    323             <html><font color='black'><iframe height=400 px width=800 px
     319            <html><font color='black'><iframe height="400" width="800"
    324320            src="http://sagemath.org"></iframe></font></html>
    325 
    326321            sage: html.iframe("http://sagemath.org",30,40)
    327             <html><font color='black'><iframe height=30 px width=40 px
     322            <html><font color='black'><iframe height="30" width="40"
    328323            src="http://sagemath.org"></iframe></font></html>
    329 
    330324            sage: html.iframe("https://sagemath.org",30)
    331             <html><font color='black'><iframe height=30 px width=800 px
     325            <html><font color='black'><iframe height="30" width="800"
    332326            src="https://sagemath.org"></iframe></font></html>
     327            sage: html.iframe("/home/admin/0/data/filename")
     328            <html><font color='black'><iframe height="400" width="800"
     329            src="/home/admin/0/data/filename"></iframe></font></html>
     330            sage: html.iframe('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA'
     331            ... 'AUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBA'
     332            ... 'AO9TXL0Y4OHwAAAABJRU5ErkJggg=="')
     333            <html><font color='black'><iframe height="400" width="800"
     334            src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==""></iframe></font></html>
    333335
    334336        AUTHOR:
    335        
     337
    336338        - Bruce Cohen (2011-06-14)
    337339        """
    338         if not url.startswith("http"):
    339             url="http://"+url
    340         string='<iframe height=%d px width=%d px src="%s"></iframe>'%(height,
    341                                                                        width,
    342                                                                        url)
     340        if ":" not in url and not url.startswith('/'):
     341            url = "http://" + url
     342        string = ( '<iframe height="%d" width="%d" src="%s"></iframe>' %
     343                    (height, width, url) )
    343344        return html(string)
    344345
    345 
    346346html = HTML()