(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.
reducePrettyTable : TableStyle -> Markdown.Scaffolded.Block (Basics.Int -> TableInfo String) -> Basics.Int -> TableInfo String
Convert a block of markdown back to markdown text.
See the 'Formatting Markdown Tables' test in the example/
folder:
finishReduction
).finishReduction : List (Basics.Int -> TableInfo String) -> String
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.finishReduction
{ renderCell : String -> ColumnInfo -> String
, renderDelimiter : List ColumnInfo -> String
, renderRow : List String -> String
}
The 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.defaultStyle : TableStyle
A sensible default for pretty-printing tables.
It will:
compactStyle : TableStyle
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.
{ render : Dict Basics.Int ColumnInfo -> view
, info : Dict Basics.Int ColumnInfo
}
The main datatype that drives pretty-printing.
This allows the pretty-printing to work in a two-step process:
ColumnInfo
{ size : Basics.Int
, alignment : Maybe Markdown.Block.Alignment
}
All additional column information needed to support pretty-printing.
resolve : TableInfo view -> view
Resolve the two-step process that a TableInfo
encodes by running the steps.
pure : view -> TableInfo view
Make anything a TableInfo
without adding column information.
map : (a -> b) -> TableInfo a -> TableInfo b
Transform the value that would be generated in the first step of the TableInfo
process by applying a function.
map2 : (a -> b -> c) -> TableInfo a -> TableInfo b -> TableInfo c
Combine two TableInfo
values using given function.
This does two things:
TableInfo
s render to in their first step using the functionfold : List (TableInfo a) -> TableInfo (List a)
Combine all column information inside a TableInfo
from a whole list.
combineColumnInfo : ColumnInfo -> ColumnInfo -> ColumnInfo
A helper function for combining two column infos form two cells of the same column.