Skip to content

Embed hyperlinks in io.ascii.write html output?  #4006

Closed

Description

@tumlinson

I need to write out the contents of an astropy table to html, using:

ascii.write(sample, 'sample.html', format='html')

some cells of the table need to contain hyperlinks, which I can construct via string:

                        urlstring = '<a href="file:///linkpath"> linktext </a>'              

the problem is that when the string is written out into HTML, the < and > characters are converted to &lt; and &gt;:

    <td>&lt;a href="file:///linkpath"&gt; linktext &lt;/a&gt;</td>

How can I have those characters printed into the HTML literally, or otherwise embed links in the html outputs of tables?

Apologies if this is a noob question, but that's what I am.

Activity

  1. embray commented on Jul 24, 2015

    @embray
    Member

    Hmm--looks like the HTML writer always escapes the raw strings for HTML related characters. However I could see this as an argument for a "raw" mode to just write strings from a table without escaping. If so, I think this should be enabled on a per-column basis.

    This would require an update to the XMLWriter class to allow data to be written to an element without HTML entity escapes. It would also require an update to the astropy.io.ascii.html.HTML class to accept an optional sequence of columns in which to allow raw HTML, and an update to HTML.write to support that.

    I think also as a security concern, insecure tags like <script> or <iframe> should be disabled even in raw HTML mode, unless explicitly whitelisted (this is why I bumped this up to effort-medium).

  2. pllim commented on Jul 24, 2015

    @pllim
    Member

    Meanwhile, sed can be used to manually fix the <a href=...> and </a> tags. http://www.gnu.org/software/sed/manual/sed.html#The-_0022s_0022-Command

  3. mrobberto commented on Dec 24, 2015

    @mrobberto

    the functionality is present in pandas "to_html" writer. A pandas table "pd" containing html links can be printed to html setting "escape=False"
    pd.to_html('fileout.html',escape=False)
    Unfortunately, pandas writes vanilla html without sorting headers etc., so it would still be nice to get this added to astropy

  4. pllim commented on Dec 24, 2015

    @pllim
    Member
  5. taldcroft commented on Dec 29, 2015

    @taldcroft
    Member

    Definitely 👍 on the idea. I've wanted this myself a few times, so a PR would definitely be welcome.

  6. taldcroft commented on Dec 30, 2015

    @taldcroft
    Member

    See #4423 for code.

  7. algerdnazgul commented on Apr 19, 2016

    @algerdnazgul
    Contributor

    Close?

  8. pllim commented on Apr 19, 2016

    @pllim
    Member

    Yes, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions