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
:
cell_alignment
: A dictionary of type(i,j) => a
that overrides that alignment of the cell(i,j)
toa
regardless of the columns alignment selected.a
must be a symbol like specified in the sectionAlignment
.formatter
: See the section Formatter.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
)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 highlighter
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 highlighter, 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, 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.
Notice that 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 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.
If only a single highlighter is wanted, then it can be passed directly to the keyword highlighter
without being inside a Tuple
.
A default HTML highlighter HTMLHighlighter
is available. It can be constructed using the following functions:
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 the highlighters are used together with Formatter, then the change in the format will not affect that 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))