Skip to content

Commit

Permalink
Merge pull request #433 from malmaud/html_output
Browse files Browse the repository at this point in the history
Output to HTML added via writemime
  • Loading branch information
johnmyleswhite committed Dec 6, 2013
2 parents bbcb7dd + 39c19e2 commit 22c9c98
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,42 @@ function writetable(filename::String,
return
end

##############################################################################
#
# HTML output
#
##############################################################################
function html_escape(cell::String)
cell = replace(cell, "&", "&")
cell = replace(cell, "<", "&lt;")
cell = replace(cell, ">", "&gt;")
return cell
end

function Base.writemime(io::IO,
::MIME"text/html",
df::DataFrame)
n = size(df, 1)
column_names = colnames(df)
write(io, "<table>")
write(io, "<tr>")
write(io, "<th></th>")
for column_name in column_names
write(io, "<th>$column_name</th>")
end
write(io, "</tr>")
for row in 1:n
write(io, "<tr>")
write(io, "<th>$row</th>")
for column_name in column_names
cell = string(df[row, column_name])
write(io, "<td>$(html_escape(cell))</td>")
end
write(io, "</tr>")
end
write(io, "</table>")
end

##############################################################################
#
# Binary serialization
Expand Down

0 comments on commit 22c9c98

Please sign in to comment.