Ticket #11489: trac_11489-iframe.reviewer.reviewer.patch

File trac_11489-iframe.reviewer.reviewer.patch, 3.0 KB (added by ryan, 10 years ago)

only apply this patch

  • sage/misc/html.py

    # HG changeset patch
    # User Bruce Cohen <math.cohen@gmail.com>
    # Date 1308156704 25200
    # Node ID 044a52a07b9bca694e501101aafb6941df4be77f
    # Parent  155db6f2482dbf65f7d96d9ba989fcba25646b61
    #11489: Made docstring a rawstring. Merged two patches to single patch
    trac 11489 adding html.iframe method
    * * *
    trac #11489: make HTML spec-conformant, change the check for URI scheme, fix some formatting
    
    diff -r 155db6f2482d -r 044a52a07b9b sage/misc/html.py
    a b  
    293293                                    + latex(row[column]).replace('\\texttt','\\hbox')
    294294                                    + '</span>')
    295295
     296    def iframe(self, url, height=400, width=800):
     297        r"""
     298        Put an existing web page into a worksheet.
     299
     300        INPUT:
     301
     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.
     305              Defaults to 400.
     306            - ``width`` -- the number of pixels for the page width.
     307              Defaults to 800.
     308
     309        OUTPUT:
     310
     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.
     315
     316        EXAMPLES::
     317
     318            sage: html.iframe("sagemath.org")
     319            <html><font color='black'><iframe height="400" width="800"
     320            src="http://sagemath.org"></iframe></font></html>
     321            sage: html.iframe("http://sagemath.org",30,40)
     322            <html><font color='black'><iframe height="30" width="40"
     323            src="http://sagemath.org"></iframe></font></html>
     324            sage: html.iframe("https://sagemath.org",30)
     325            <html><font color='black'><iframe height="30" width="800"
     326            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>
     335
     336        AUTHOR:
     337
     338        - Bruce Cohen (2011-06-14)
     339        """
     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) )
     344        return html(string)
     345
    296346html = HTML()