HTML Back End
The following options are available when the HTML back end is used. Those can be passed as keywords when calling the function pretty_table
:
allow_html_in_cells::Bool
: By default, special characters like<
,>
,"
, etc. are replaced in HTML back end to generate valid code. However, this algorithm blocks the usage of HTML code inside of the cells. If this keyword istrue
, the escape algorithm will not be applied, allowing HTML code inside all the cells. In this case, the user must ensure that the output code is valid. If only few cells have HTML code, wrap them in aHtmlCell
object instead. (Default =false
)continuation_row_alignment::Symbol
: A symbol that defines the alignment of the cells in the continuation row. This row is printed if the table is vertically cropped. (Default =:r
)highlighters::Union{HtmlHighlighter, Tuple}
: An instance ofHtmlHighlighter
or a tuple with a list of HTML highlighters (see the section HTML Highlighters).linebreaks::Bool
: Iftrue
,\\n
will be replaced by<br>
. (Default =false
)maximum_columns_width::String
: A string with the maximum width of each columns. This string must contain a size that is valid in HTML. If it is not empty, each cell will have the following style:"max-width": <value of maximum_column_width>
"overflow": "hidden"
"text-overflow": "ellipsis"
"white-space": "nowrap"
standalone::Bool
: Iftrue
, a complete HTML page will be generated. Otherwise, only the content between the tags<table>
and</table>
will be printed (with the tags included). (Default =false
)vcrop_mode::Symbol
: This variable defines the vertical crop behavior. If it is:bottom
, the data, if required, will be cropped in the bottom. On the other hand, if it is:middle
, the data will be cropped in the middle if necessary. (Default =:bottom
)table_div_class::String
: The class name for the tablediv
. It is only used ifwrap_table_in_div
istrue
. (Default = "")table_class::String
: The class name for the table. (Default = "")table_style::Dict{String, String}
: A dictionary containing the CSS properties and their values to be added to the tablestyle
. (Default =Dict{String, String}()
)tf::HtmlTableFormat
: An instance of the structureHtmlTableFormat
that defines the general format of the HTML table.top_left_str::String
: String to be printed at the left position of the top bar. (Default = "")top_left_str_decoration::HtmlDecoration
: Decoration used to print the top-left string (seetop_left_str
). (Default =HtmlDecoration()
)top_right_str::String
: String to be printed at the right position of the top bar. Notice that this string will be replaced with the omitted cell summary if it must be displayed. (Default = "")top_right_str_decoration::HtmlDecoration
: Decoration used to print the top-right string (seetop_right_str
). (Default =HtmlDecoration()
)wrap_table_in_div::Bool
: Iftrue
, the table will be wrapped in adiv
. (Default:false
)
HTML Highlighters
A set of highlighters can be passed as a Tuple
to the highlighters
keyword. Each highlighter is an instance of the structure HtmlHighlighter
. It contains the following two public fields:
f::Function
: Function with the signaturef(data, i, j)
in which should returntrue
if the element(i,j)
indata
must be highlighted, orfalse
otherwise.fd::Function
: Function with the signaturef(h, data, i, j)
in whichh
is the highlighter. This function must return theHtmlDecoration
to be applied to the cell that must be highlighted.
The function f
has the following signature:
f(data, i, j)
in which data
is a reference to the data that is being printed, and i
and j
are the element coordinates that are being tested. If this function returns true
, the highlight style will be applied to the (i, j)
element. Otherwise, the default style will be used.
If the function f
returns true, the function fd(h, data, i, j)
will be called and must return an element of type HtmlDecoration
that contains the decoration to be applied to the cell.
A HTML highlighter can be constructed using two helpers:
HtmlHighlighter(f::Function, decoration::HtmlDecoration)
HtmlHighlighter(f::Function, fd::Function)
The first will apply a fixed decoration to the highlighted cell specified in decoration
whereas the second let the user select the desired decoration by specifying the function fd
.
If only a single highlighter is wanted, it can be passed directly to the keyword highlighter
without being inside a Tuple
.
If multiple highlighters are valid for the element (i, j)
, the applied style will be equal to the first match considering the order in the tuple highlighters
.
If the highlighters are used together with Formatters, the change in the format will not affect the parameter data
passed to the highlighter function f
. It will always receive the original, unformatted value.
There are a set of pre-defined highlighters (with names hl_*
) to make the usage simpler. They are defined in the file ./src/backends/html/predefined_highlighters.jl
.
julia> t = 0:1:20
0:1:20
julia> data = hcat(t, ones(length(t)) * 1, 1 * t, 0.5 .* t.^2)
21×4 Matrix{Float64}: 0.0 1.0 0.0 0.0 1.0 1.0 1.0 0.5 2.0 1.0 2.0 2.0 3.0 1.0 3.0 4.5 4.0 1.0 4.0 8.0 5.0 1.0 5.0 12.5 6.0 1.0 6.0 18.0 7.0 1.0 7.0 24.5 8.0 1.0 8.0 32.0 9.0 1.0 9.0 40.5 ⋮ 12.0 1.0 12.0 72.0 13.0 1.0 13.0 84.5 14.0 1.0 14.0 98.0 15.0 1.0 15.0 112.5 16.0 1.0 16.0 128.0 17.0 1.0 17.0 144.5 18.0 1.0 18.0 162.0 19.0 1.0 19.0 180.5 20.0 1.0 20.0 200.0
julia> header = ( ["Time", "Acceleration", "Velocity", "Distance"], [ "[s]", "[m/s²]", "[m/s]", "[m]"] )
(["Time", "Acceleration", "Velocity", "Distance"], ["[s]", "[m/s²]", "[m/s]", "[m]"])
julia> hl_v = HtmlHighlighter( (data, i, j) -> (j == 3) && data[i, 3] > 9, HtmlDecoration(color = "blue", font_weight = "bold") )
HtmlHighlighter(Main.var"#1#2"(), PrettyTables.var"#15#17"(), HtmlDecoration("blue", "", "", "", "bold", "", Dict{String, String}()))
julia> hl_p = HtmlHighlighter( (data, i, j) -> (j == 4) && data[i, 4] > 10, HtmlDecoration(color = "red") )
HtmlHighlighter(Main.var"#3#4"(), PrettyTables.var"#15#17"(), HtmlDecoration("red", "", "", "", "", "", Dict{String, String}()))
julia> hl_e = HtmlHighlighter( (data, i, j) -> data[i, 1] == 10, HtmlDecoration(background = "black", color = "white") )
HtmlHighlighter(Main.var"#5#6"(), PrettyTables.var"#15#17"(), HtmlDecoration("white", "black", "", "", "", "", Dict{String, String}()))
julia> pretty_table( data; backend = Val(:html), header = header, highlighters = (hl_e, hl_p, hl_v), standalone = true )