(Tables defined by the github flavoured markdown (GFM) spec).
Elm-markdown supports GFM tables. The function reducePretty
in the Markdown.Scaffolded module doesn't support pretty
printing these.
This module includes the function reducePrettyTable, which
supports pretty-printing markdown tables.
Due to this being slightly complicated, this functionality was moved into this module together with its helpers.
Transform the result of reducePrettyTable after being put through
Markdown.render to a string.
Use it like this:
markdownBlocks
|> Markdown.render
(Scaffolded.toRenderer
{ renderHtml = Markdown.Html.oneOf []
, renderMarkdown = Tables.reducePrettyTable style
}
)
|> Result.map Tables.finishReductionThe style to render tables to. There are two values for this provided for your convenience (defaultStyle, compactStyle), so check those out before creating a value of your own.
In case you still want to, you need to provide:
renderCell: A function that renders a cell content and applies appropriate padding
using the given ColumnInfo.
renderDelimiter: A function that renders the horizontal line between the table header
and table body. Remember that to write valid markdown, you need to include a pipe (|)
for each delimiter between columns.
renderRow: A function for combining multiple cells in a row. Remember that to write
valid markdown, you'll need to include a pipe (|) between each cell.
A sensible default for pretty-printing tables.
It will:
Make all cells in a column have uniform width
Left/Center/Right-align cell contents (left by default)
Add a border (|) to the left and right side of your table
This style will try to produce valid markdown tables without padding or additional
borders (unlike defaultStyle).
However, it's not the minimal amount of characters needed to get a parsing table.
The main datatype that drives pretty-printing.
This allows the pretty-printing to work in a two-step process:
Collect all the pretty-printed cells and their information ColumnInfo
Use the maximum cell sizes as column sizes to add padding around cells
All additional column information needed to support pretty-printing.
Resolve the two-step process that a TableInfo encodes by running the steps.
Make anything a TableInfo without adding column information.
Transform the value that would be generated in the first step of the TableInfo
process by applying a function.
Combine two TableInfo values using given function.
This does two things:
It combines what the TableInfos render to in their first step using the function
It merges the collected column information from both
Combine all column information inside a TableInfo from a whole list.
A helper function for combining two column infos form two cells of the same column.
Convert a block of markdown back to markdown text.
See the 'Formatting Markdown Tables' test in the
example/folder:It will show you how pretty-printed tables will look like
It shows you how to transform the result of this function to a string (See
finishReduction).