HTML back-end
The following options are available when the HTML backend is used. Those can be passed as keywords when calling the function pretty_table
:
highlighters
: An instance ofHTMLHighlighter
or a tuple with a list of HTML highlighters (see the sectionHTML highlighters
).linebreaks
: Iftrue
, then\\n
will be replaced by<br>
. (Default =false
)noheader
: Iftrue
, then the header will not be printed. Notice that all keywords and parameters related to the header and sub-headers will be ignored. (Default =false
)nosubheader
: Iftrue
, then the sub-header will not be printed, i.e. the header will contain only one line. Notice that this option has no effect ifnoheader = true
. (Default =false
)show_row_number
: Iftrue
, then a new column will be printed showing the row number. (Default =false
)standalone
: Iftrue
, then 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 =true
)tf
: An instance of the structureHTMLTableFormat
that defines the general format of the HTML table.
HTML highlighters
A set of highlighters can be passed as a Tuple
to the highlighters
keyword. Each highlighter is an instance of a structure that is a subtype of AbstractHTMLHighlighter
. It also must also contain at least the following two fields to comply with the API:
f
: Function with the signaturef(data,i,j)
in which should returntrue
if the element(i,j)
indata
must be highlighted, orfalse
otherwise.fd
: 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
, then the highlight style will be applied to the (i,j)
element. Otherwise, the default style will be used.
If the function f
returns true, then 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, then it can be passed directly to the keyword highlighter
without being inside a Tuple
.
If multiple highlighters are valid for the element (i,j)
, then 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, then 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;
julia> data = hcat(t, ones(length(t))*1, 1*t, 0.5.*t.^2);
julia> header = ["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"));
julia> hl_p = HTMLHighlighter( (data,i,j)->(j == 4) && data[i,4] > 10, HTMLDecoration(color = "red"));
julia> hl_e = HTMLHighlighter( (data,i,j)->data[i,1] == 10, HTMLDecoration(background = "black", color = "white"))
julia> pretty_table(data, header, backend = :html, highlighters = (hl_e, hl_p, hl_v))