Skip to content

v3.5.0

Choose a tag to compare

@github-actions github-actions released this 28 Sep 19:47
· 43 commits to master since this release

PrettyTables v3.5.0

Diff since v3.4.8

  • Add the Word back end (backend = :docx), which renders the table as a Word table using WriteDocx.jl. It writes a .docx file when the keyword filename is set (an existing file is only replaced if overwrite = true) and otherwise returns the WriteDocx.Table, so that the table can be embedded in a larger document, also available with pretty_table(WriteDocx.Table, data; kwargs...) and pretty_table(WriteDocx.Document, data; kwargs...). The documents created by the back end use Calibri as the default font, which can be changed with the keyword default_font. The back end supports the sections, the highlighters (DocxHighlighter), the table format (DocxTableFormat and DocxTableBorders), the table style (DocxTableStyle), and the column widths (data_column_widths, minimum_data_column_widths, and maximum_data_column_widths), as well as the backend-agnostic TableFormat and TableStyle. Footnote markers become superscript text runs and each region of a styled string becomes a text run with the attributes of its face. The functions docx_decoration and docx_line_style, the macros @docx__all_horizontal_lines, @docx__all_vertical_lines, @docx__no_horizontal_lines, and @docx__no_vertical_lines, and the function pretty_table_docx_backend are exported.
  • Add the keyword line_breaks to the Typst back end. If true, the line breaks in the cells are rendered as Typst line breaks. Otherwise, they are escaped as in the other back ends, whereas they were emitted as raw line break characters.
  • Add support for StyledStrings.Face as the decoration of the text back end. Every field of TextTableStyle and the decoration of TextHighlighter are now faces, and crayons are still accepted and converted to the equivalent faces. The keyword constructor TextHighlighter(f; kwargs...) accepts the keywords of both Face and Crayon. StyledStrings.jl is now a dependency, it is re-exported, and Face and SimpleColor are exported.
  • Add Highlighter, a highlighter defined by a Face that works with every back end, and the supertype AbstractHighlighter of all the highlighters. The keyword highlighters accepts any vector of AbstractHighlighter.
  • Accept a Face in every keyword of HtmlTableStyle, LatexTableStyle, MarkdownTableStyle, TypstTableStyle, and ExcelTableStyle, which is converted to the decoration of the back end at construction. The conversion functions html_decoration, latex_decoration, markdown_decoration, typst_decoration, and excel_decoration are exported.
  • Render the styled strings of StyledStrings.jl in every back end (Julia 1.11 or newer). The regions of the string are decorated with their faces using the conversion of each back end. The HTML back end now renders them with html_decoration instead of the HTML writer of StyledStrings.jl.
  • Convert styled strings to Excel's rich text format (XLSX.RichTextString), where each region of the string becomes a run with the font attributes of its face. Backgrounds are dropped because Excel does not support per-run fills, and a string whose regions carry no font attributes is still written as plain text.
  • Add the backend-agnostic table format TableFormat and the line design LineStyle, allowing the user to configure the table lines (presence and design) once for every back end. The keyword table_format now accepts TableFormat in every back end: each set field overrides the corresponding field of the back end default format, and every field left as nothing keeps the back end default. The conversion functions latex_line_style, typst_line_style, and excel_line_style are exported.
  • Add the backend-agnostic table style TableStyle, which describes the decoration of each table section with a Face. The keyword style now accepts TableStyle in every back end with the same sparse override semantics as TableFormat: each set field overrides the corresponding field of the back end default style.
  • Allow customizing each table line independently in the text back end. TextTableFormat now has the fields top_line, header_line, merged_header_cell_line, middle_line, bottom_line (accepting the new exported object TextTableLine), left_line, center_line, and right_line (accepting a Char), which sparsely override the characters in borders for a single line. TextTableStyle now has line faces with the same names to style each line independently, falling back to table_border when unset. The line design fields of TableFormat are now fully supported by the text back end: each LineStyle is mapped to Unicode box-drawing characters, the intersections between the lines are selected automatically from the crossing designs, and the line design colors are converted to the line faces of the style.
  • Add the border configuration to the HTML back end. HtmlTableFormat now has the field borders (the new exported object HtmlTableBorders, whose line roles are CSS border shorthand strings) and the same line presence fields as the other back ends, plus three HTML-only ones (horizontal_line_before_column_labels, horizontal_line_after_footnotes, and horizontal_line_at_end) since the HTML back end places the title inside the ruled area and draws the line at the end of the table with a dedicated field. As in the text back end, the footnotes and source notes are outside the ruled area: the line at the end of the table is drawn after the last summary or data row, before them, and the vertical lines at the edges of the table are hidden in their cells. The line after the last row of the ruled area uses the bottom line style, as in the other back ends. The lines are emitted as inline styles in the table elements, so they are applied in any rendering mode instead of only when stand_alone = true. Every line is disabled by default, keeping the default output free of border decoration. The macros @html__all_horizontal_lines, @html__all_vertical_lines, @html__no_horizontal_lines, and @html__no_vertical_lines and the conversion function html_line_style are exported, and the HTML back end now fully supports the backend-agnostic TableFormat.
  • Add the backend-agnostic macros @all_horizontal_lines, @all_vertical_lines, @no_horizontal_lines, and @no_vertical_lines, which return the keyword arguments to show or suppress every line in TableFormat, mirroring the per-backend macro quadruples. TableFormat also gained the presence fields horizontal_line_before_column_labels, horizontal_line_after_footnotes, and horizontal_line_at_end, which are only honored by the HTML back end and silently ignored by the others.
  • Accept a Face, a Crayon, and the keywords of both in the constructors of HtmlHighlighter, LatexHighlighter, MarkdownHighlighter, TypstHighlighter, and ExcelHighlighter, converting the face with the decoration function of the back end, exactly like Highlighter and TextHighlighter. Every table style, including TableStyle, also accepts a Crayon wherever it accepts a Face.
  • Export the native decoration types HtmlPair, TypstPair, and LatexEnvironments, like ExcelPair.
  • Select the back end from a native table style (for example, style = HtmlTableStyle()) when backend = :auto and the table format does not select one. Passing the style or the table format of another back end now throws an ArgumentError with a clear message instead of a MethodError.
  • The HTML back end draws no lines by default: every line presence field of HtmlTableFormat defaults to false (or :none), and the default output has no border decoration (no inline borders, no border-collapse, and no <colgroup> elements), keeping the table appearance fully customizable with CSS. The default css of HtmlTableFormat no longer contains border rules, so a stand-alone table is also rendered without borders unless lines are enabled. The underline of merged column labels moved from the defaults of first_line_merged_column_label and merged_column_label in HtmlTableStyle to the field horizontal_line_at_merged_column_labels of HtmlTableFormat, which is disabled by default like the other lines. A fully ruled table can be obtained with HtmlTableFormat(; @html__all_horizontal_lines, @html__all_vertical_lines).
  • The conversion of TableFormat and TableStyle is a best effort: the Markdown back end only supports horizontal_line_before_summary_rows and ignores the style fields its style type does not have, and the LaTeX back end ignores the line width and color. With backend = :auto, a TableFormat does not select a back end and the text back end is used.
  • Precompile the most common keywords, the predefined formatters, the matrices with elements of type Any, the vectors with missing values, pretty_table(HTML, data), and the String output with a custom style. For example, the time to print the first table with fmt__printf was reduced from about 170 ms to about 24 ms, with a title from about 42 ms to about 21 ms, and with pretty_table(HTML, data) from about 55 ms to about 24 ms. The time to load the package increased by about 2 ms.
  • Compile the text back end only once for all the specifications of the lines at the column labels, data rows, and data columns (:all, :none, or a vector of indices) and for all the combinations of optional sections. For example, the time to print the first table with row labels, summary rows, and hidden column labels was reduced from about 100 ms to about 83 ms, and the compiled package is about 0.5 MB smaller.
  • Compile the preprocessing of the table only once for all the types of the formatters, summary rows, cell alignments, row labels, and column labels. For example, the time to print the first table with a new formatter function was reduced from about 115 ms to about 45 ms, and with symbols as column labels, from about 115 ms to about 30 ms.
  • Load REPL.jl only in Julia 1.11 and 1.12, where it avoids a long precompilation time. In Julia 1.13 or newer, this change reduces the time to load the package by about 50 ms.
  • TextTableStyle is now a mutable structure with constant fields, reducing the time to print the first table with a custom text style from about 160 ms to about 40 ms. The equality and the hash still consider its fields.
  • Avoid the invalidation of the compiled code of the package when other packages define new string types or conversions to String, which forced the text back end to be compiled again. For example, the time to print the first table after loading InlineStrings.jl (a dependency of CSV.jl) was reduced from about 700 ms to about 30 ms.
  • Render the escape sequences of the style of the text back end when the style is created instead of once per cell.
  • Reduce the time to print the first table. Each back end now gathers its keywords in an options structure and compiles its rendering body once, so a set of keywords not seen before (for example, line_breaks = true) costs a few milliseconds instead of 150 to 230 ms in Julia 1.12, and a new highlighter vector type or width keyword type no longer compiles the rendering body again. The keyword constructors of TextTableStyle, TextHighlighter, and Highlighter are compiled once for every set of keywords, and the data accessors are no longer specialized on the table type where it does not pay off.
  • Emit the vertical lines of the HTML back end as the borders of <col> elements and the horizontal lines as the borders of the <tr> elements instead of inline borders in every cell. Since the table borders are collapsed, the rendering is the same, but the output of a large table is about 40% smaller and it is rendered faster. The line under a merged column label stays in the cell.
  • Keep the back end default for every unset aspect of a LineStyle in the HTML, Typst, and Excel back ends. For example, TableFormat(; top_line = LineStyle(; color = :red)) now keeps the default width of the top line instead of resetting it to the thinnest one. The conversion functions html_line_style, typst_line_style, excel_line_style, and latex_line_style accept the keyword default with the default line design.
  • Cover the lines between the column label rows and under the merged column labels in @text__all_horizontal_lines and @text__no_horizontal_lines, like the macros of the other back ends cover their backend-specific fields.
  • Validate the positional constructor of LineStyle exactly like the keyword constructor.
  • Convert the general Highlighter to the native highlighter of the back end once per printed table. Highlighter is now immutable and it can be shared between tasks.
  • The conversion from Crayon to Face is lossy: the attributes blink, conceal, and reset are dropped with a warning shown once per session, the attributes explicitly turned off (for example, bold = false) and the default color of the terminal are omitted because every styled segment starts after a reset, bold has priority over faint when both are set, and the colors of the 256-color palette (except the 16 system colors) are converted to 24-bit colors, which requires a terminal with 24-bit color support.
  • The line character fields of TextTableFormat are placed after the other fields, and TextTableFormat and HtmlTableFormat keep positional constructors with the fields of v3.4.8. Hence, the code that builds those objects positionally keeps working. The decoration converters of the HTML, LaTeX, Typst, and Excel styles also accept any vector, like the constructors of v3.4.8 did.
  • Accept any real number in the keywords data_column_widths, minimum_data_column_widths, and maximum_data_column_widths of the Excel back end, which previously required Float64 values.
  • PrettyTables.jl now requires StringManipulation.jl v0.6.1.
  • Breaking Change: maximum_number_of_columns = 0 now crops the table to zero data columns, printing only the continuation column, exactly like maximum_number_of_rows = 0 does for the rows. Previously, it meant "no limit", which is still the meaning of a negative value (the default).
  • Breaking Change: A dictionary that complies with the Tables.jl API (e.g., a dictionary of column vectors with Symbol or String keys) is now printed as a table, like any other Tables.jl source, instead of a two-column table with its keys and values. The other dictionaries are still printed as keys and values.
  • Validate every alignment symbol, throwing an ArgumentError if it is not :l, :c, :r, or :n (or their uppercase versions). Invalid symbols were silently accepted, misaligning the cells in the text back end. The uppercase symbols now work in every back end, and the text back end renders :n as left alignment.
  • Document the macro @latex_cell_str and the function printable_cell_text of the custom text cell API, whose docstrings were written as raw strings without @doc and, hence, were not registered.
  • Escape the plain text of every cell in the HTML back end when the renderer is :print. A string whose type can be shown as HTML, such as a view into a styled string, was emitted without escaping, allowing the injection of HTML code. Furthermore, the views into styled strings are now rendered as styled strings in every back end.
  • Use the same border for each horizontal line in the HTML, LaTeX, and Typst back ends: top_line for the line before the first row after the title and subtitle, header_line only for the line after the column labels, and middle_line for the lines around the row group labels. The LaTeX back end used header_line for the line after the title and after the row group labels, and the HTML back end used it for the line before the column labels.
  • The HTML back end no longer draws the line after the last data row when horizontal_lines_at_data_rows contains it. As in the other back ends, this line is only drawn if horizontal_line_after_data_rows is true.
  • Escape the row group labels in the Markdown back end. A | in a label added a column to the table.
  • Escape the stubhead label and the row number column label in the Markdown back end, as the column labels.
  • Always crop the custom text cells to the column width. A custom cell in the shrinkable column crossed the column border if the maximum column width was larger than the shrunk width.
  • Erase the last line of the previous table when overwriting the display with a text table that does not end with a new line. The characters of this line that were not overwritten remained in the display.
  • Escape the line breaks in the text of UrlTextCell, which is always rendered in a single line. A line break broke the table row.
  • Consider the continuation column when shrinking the shrinkable column of a text table. The column was not shrunk enough, and the display cropped the continuation column and the right border.
  • Assume the minimum width of the columns (three characters) when limiting the number of rendered columns of a text table to the display width. The limit assumed five characters per column, omitting narrow columns that fit in the display.
  • Keep at least one display line when reserved_display_lines is equal to or larger than the display height in the text back end. The reserved lines were ignored in this case, printing a taller table than when reserving fewer lines.
  • Equalize the widths of the text data columns before cropping the cells to the fixed widths. The cells of the columns widened by equal_data_column_widths remained cropped to their fixed widths.
  • Treat a display width equal to 0 as unlimited when drawing the intersections of the horizontal lines in the text back end, as documented. The intersections were replaced by the line character.
  • Give fixed_data_column_widths precedence over maximum_data_column_widths in the text back end, as documented. The cells of a column with a fixed width were still cropped to its maximum width.
  • Handle the merged column labels when column_label_width_based_on_first_line_only is true in the text back end. The merged labels after the first line widened the columns and were cropped to the width of a single column.
  • Widen the text table to fit the printed row group labels, distributing the additional width among the data columns without a fixed width. If no column can be widened, the label is cropped. A long label crossed the right border of the table.
  • Compute the width of the row group labels in the text back end considering only the vertical lines drawn at the edges of the table, and draw the line at the right edge of the labels only if the other rows have it. The right border of the labels was shifted when the table had no vertical line at the beginning or at the end.
  • Reset the style of the horizontal lines of the text back end that are cropped at the display edge. The style leaked into the rest of the output.
  • Reset the cropping of the custom text cells when they fit in the column. The cropping of a line was applied to the other lines of the cell, and the one of a position was applied to the other positions of the same cell object.
  • Keep the middle cropping of text tables with line breaks if the display does not limit the number of printed rows. It was always replaced by the bottom cropping when the table had to fit in the display.
  • Consider the line of the omitted cell summary when fitting a text table whose data columns are omitted in the display height. It was only considered if data rows were also omitted, making the table one line taller than the display.
  • Count exactly the lines drawn by the text back end when fitting the table in the display height. The table could use more lines than available, e.g., with row group labels after rows with horizontal lines, in the middle cropping, with lines at the merged column labels, or with line breaks, and it could be cropped although it fit, e.g., with a row group label at the first row or with line breaks.
  • Do not draw the line before a row group label at the first row of the text back end when the column labels are hidden. It was drawn right after the top line, which now has no intersections because the label spans the entire table.
  • Use the data row indices to draw the horizontal lines around the row group labels in the middle cropping of the text back end. The lines were drawn after the wrong rows.
  • Fix the line after the continuation row in the middle cropping of the text back end. The line after the data rows was drawn before the data rows printed after the continuation row, and a row group label after the continuation row was preceded by two lines.
  • Escape the sequences --, ---, and ... in the Typst back end, which Typst converted into dashes and an ellipsis.
  • Escape a . or ( right after a component in the Typst back end, such as the footnote superscript or a styled region of a styled string. Typst parsed it as a field access or a function call on the component, breaking the document.
  • Escape the double quotes and backslashes of the Markdown.MD cells in the Typst back end, which are emitted inside string literals.
  • Escape the slashes in the Typst back end, since // and /* started a comment that broke the document, and the markups that Typst recognizes at the beginning of a cell (headings, lists, and term lists).
  • Keep the leading and trailing white spaces of a cell outside the style markers in the Markdown back end. Markdown does not recognize emphasis markers next to a white space, showing them literally.
  • Consider the summary rows in the column widths of the Markdown back end when the table has no data rows.
  • Print the header separator of the Markdown back end before the first row of the table body when the column labels are hidden. It was missing if the table began with the continuation row or the summary rows and printed after the first row group label.
  • Print the omitted cell summary in the Markdown back end when the column labels are the last row of the table.
  • Always escape the pipes in the Markdown back end, including in Markdown.MD cells and when allow_markdown_in_cells is true, unless they are already escaped. A pipe split the table cell.
  • Do not escape the Markdown characters inside code spans in the Markdown back end, which render their content verbatim, except the pipe. The code span delimiter is now longer than any sequence of backticks in the content.
  • Place the footnote references after the style of the cells in the Markdown back end, as in the row numbers. Inside a code span, such as in the default style of the column labels after the first line, the references did not work.
  • Keep the lower column label rows of the columns under a merged cell in the Markdown back end. The entire column label was replaced by the fill that represents the merged cell.
  • Escape | and " as \textbar{} and \textquotedbl{} in the LaTeX back end. Under the default OT1 font encoding, they were typeset as — and ”.
  • Align the source notes with source_note_alignment in the LaTeX back end. They were aligned with footnote_alignment.
  • Always escape the title, subtitle, row group labels, footnotes, and source notes in the HTML back end. As documented, allow_html_in_cells only applies to the table cells, but it also disabled the escaping of those sections.
  • Place the continuation row in the table body of the HTML back end when no data row is printed. It was placed in the table head.
  • Close the table header of the Typst back end after the column labels. When no data row was printed, the continuation row, the omitted cell summary, and the table footer were placed inside it.
  • Keep the insertion order of the CSS properties of the same family (e.g., border and border-bottom) in the HTML back end, so that a shorthand property in the user style overrides the longhand properties set by the back end. The properties were sorted by name, placing the shorthand before its longhands.
  • Keep the line breaks of Markdown.MD cells in the HTML back end, preserving the content of code blocks, and replace them with spaces in the LaTeX and Markdown back ends (or with <br> if line_breaks is true in the Markdown back end). They were removed, joining the words of different lines.
  • Apply only the style of the merged cells to the merged column labels in the HTML and Typst back ends, as in the other back ends. The style of the column labels was also applied, overriding it. The default style of the merged cells is now bold in the first line of the column labels (HTML and Typst) and in the other lines (Typst), keeping the default appearance of the tables.
  • Write the cell content verbatim in the HTML back end. The minification removed the line breaks and the leading spaces of each line of the content, whereas the indentation added spaces to them, corrupting, for example, <pre> elements.
  • Escape the style properties in the HTML back end. A quote in a property, such as a quoted font family, closed the style attribute.
  • Escape the attribute values, such as the column label titles, as HTML attributes in the HTML back end. They were escaped as Julia strings, doubling the backslashes and showing the line breaks as \n.
  • Emit the HTML, LaTeX, or Typst representation of a cell unchanged when the renderer is :show, instead of escaping it.
  • Validate the length of the vectors with one column label style per column in the Typst back end and in the Excel and Word extensions, like the other back ends do. A shorter vector used to throw a BoundsError, whereas the extra styles of a longer vector were silently ignored.
  • Pass the indices of the cell in the data object to every user function (formatters, highlighters, cell alignment functions, and Excel formatters). Previously, they received the 1-based position of the cell in the printed table, making data[i, j] throw or return the wrong value for data with arbitrary axes, such as OffsetArrays, whereas the summary row functions already received the data indices.
  • Fix the outer lines of the Excel back end, which were drawn around the footnotes and the source notes instead of only around the content of the table.
  • Fix the line before the row group labels in the Excel back end, which was drawn even if horizontal_line_before_row_group_label was false.
  • Fix the width of the continuation column in the Excel back end, which used the widths configured for the first hidden data column.

Merged pull requests:

  • Gate HTML StyledStrings issue test on Julia ≥1.11 (#321) (@Copilot)
  • Add Word backend as package extension (#323) (@jkrumbiegel)

Closed issues:

  • Multilevel tables (#175)
  • hcrop_mode (#215)
  • Select/reorder columns from table (#245)
  • When precompiling without a terminal support reset crayon string is blank (#246)
  • Question: how to save subsections of a table (#248)
  • Text format: different row character for header line (#255)
  • crop keyword argument in docs (#272)
  • [Typst] Add support to styled strings (#286)
  • tables as first-class objects (#309)
  • maximum_number_of_rows = -1 doesn't seem to work correctly (#319)
  • Styled Strings in Excel (#322)
  • How to remove bold formatting from LaTeX column and row labels? (#324)