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 is true, 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 a HtmlCell 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 of HtmlHighlighter or a tuple with a list of HTML highlighters (see the section HTML Highlighters).
  • linebreaks::Bool: If true, \\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"
    If it is empty, no additional style is applied. (Default = "")
  • standalone::Bool: If true, 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 table div. It is only used if wrap_table_in_div is true. (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 table style. (Default = Dict{String, String}())
  • tf::HtmlTableFormat: An instance of the structure HtmlTableFormat 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 (see top_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 (see top_right_str). (Default = HtmlDecoration())
  • wrap_table_in_div::Bool: If true, the table will be wrapped in a div. (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 signature f(data, i, j) in which should return true if the element (i,j) in data must be highlighted, or false otherwise.
  • fd::Function: Function with the signature f(h, data, i, j) in which h is the highlighter. This function must return the HtmlDecoration 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.

Info

If only a single highlighter is wanted, it can be passed directly to the keyword highlighter without being inside a Tuple.

Note

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.

Note

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:200: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 )

HTML Table Formats

The following table formats are available when using the HTML back end:

tf_html_default (Default)

tf_html_dark

tf_html_minimalist

tf_html_matrix

Info

In this case, the table format html_matrix was printed with the option show_header = false.

tf_html_simple