Skip to content

Instantly share code, notes, and snippets.

@aminya
Last active February 4, 2020 20:20
Show Gist options
  • Save aminya/8938bf64b9239dd71f06d214246f0b05 to your computer and use it in GitHub Desktop.
Save aminya/8938bf64b9239dd71f06d214246f0b05 to your computer and use it in GitHub Desktop.
PrettyTable+AcuteML
using AcuteML, PrettyTables
@aml mutable struct PrettyTable "table"
style::String, "~"
body::String,"~"
end
@aml mutable struct Doc "html"
table::PrettyTable, "table"
end
#=
using DataFrames
a = DataFrame(course = ["Artificial Intelligence", "Robotics"], professor = ["Prof. A", "Prof. B"] )
pretty_table(a, backend = :html)
=#
myStyle = """
table, td, th {
border-collapse: collapse;
font-family: sans-serif;
}
td, th {
border-bottom: 0;
padding: 4px
}
tr:nth-child(odd) {
background: #eee;
}
tr:nth-child(even) {
background: #fff;
}
tr.header {
background: navy !important;
color: white;
font-weight: bold;
}
tr.subheader {
background: lightgray !important;
color: black;
}
tr.headerLastRow {
border-bottom: 2px solid black;
}
th.rowNumber, td.rowNumber {
text-align: right;
}
"""
myTable = """
<table>
<tr class = header>
<th style = "text-align: right; ">course</th>
<th style = "text-align: right; ">professor</th>
</tr>
<tr class = "subheader headerLastRow">
<th style = "text-align: right; ">String</th>
<th style = "text-align: right; ">String</th>
</tr>
<tr>
<td style = "text-align: right; ">Artificial Intelligence</td>
<td style = "text-align: right; ">Prof. A</td>
</tr>
<tr>
<td style = "text-align: right; ">Robotics</td>
<td style = "text-align: right; ">Prof. B</td>
</tr>
</table>
"""
PT = PrettyTable(style = myStyle, body = myTable)
D = Doc(table = PT)
pprint(PT)
pprint(D)
D.table.style # accessing style
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment