Markdown tables

Is anyone sitting on or thinking of building an implementation to parse arrays (e.g. Matrix, DataFrame, AbstractArray, etc.) into markdown tables (specifically one of the four table formats described in pandoc’s documentation: simple_tables, multiline_tables, grid_tables, and pipe_tables)?

This has been discussed to some extent elsewhere (show-is-too-low-level, best-tool-for-printing-tables, pretty-printing-of-tables, and ann-regressiontables-jl), it seems like something a lot of people need, and I’m sure it’s been partly and separately re/implemented in various un/registered packages.

Here’s my puny baaaaare bones first effort: https://github.com/yakir12/MDtables.jl (now with GridedTables as well)

Should we have a package for printing markdown tables of T <: AbstractArrays?

1 Like

Has Weave already dealt with this? I couldn’t really tell but there’s this:

https://github.com/mpastell/Weave.jl/issues/125

And DataFrames already does some basic table formatting?

But a pandoc tables package for the REPL/weave/whatever else with would be good. Something like pander in R but it may as well be useful everywhere.

AxisArrays etc. methods could add row and column labels…

1 Like

I agree with everything you said. IMHO, It’s one of those things that are mildly needed in many different cases and would benefit from a centralized single solution.

Right, so I added grid_tables as well, and I wanted to be able to have multi-line cells, but I see now that this isn’t utterly trivial (for me). Will keep hacking at it at some point, but if anyone wants to pick up the ball, be my guest!

1 Like

Can you spec this out a little bit?

Are you just asking for people to print any 2-D array to html in some table format?

// then the hard part comes in adapting anything to a 2-D array?


edit: or is there some lpad’ing and texty stuff you want done to it too?

I’m working it now. I agree, there’s hardly anything there now…

My ultimate use-case is:

  1. Produce some numbers, url links, and strings from some input.
  2. Populate a String array with those.
  3. Some of these strings in that table will have '\n' newlines in them (to make the final cells a little less wide).
  4. Convert this array to a markdown table.
  5. Insert it to a larger markdown template document (using Mustache.jl).
  6. Use pandoc to convert it all to: html (webpage), html (email), and pdf.

So I don’t care what the markdown code ends up looking like. For instance I actually don’t care about the distinction of how simple_tables, multiline_tables, grid_tables, and pipe_tables all look differently in markdown. That’s because the end pandoced result looks the same no matter what. I do care about the distinction that grid_tables for instance can take multiline cells.

My implementation looks very different than what’s online right now…

Are you going to be happy with the end result? The newline hack sounds like it’s going to be touchy.

Why not just do HTML all the way down and use CSS to get you to the goal line? (i.e. max-width, flex, etc.)

1 Like

I am crappy in that domain (HTML, CSS). But what do you mean, pandoc the html to pdf? In any case, I feel I’m doing good by finally building a markdown printer for arrays…

1 Like

Wasn’t attacking! Just trying to spitball. Think it’s cool there’ll be a tool for this :slight_smile:

Lord, didn’t think you were :slight_smile:
Please spit away! I was so happy to see anyone even responding to this…

I don’t know if this is a valid option for you, but my advice based on experience is stay away from anything but very simple tables in markdown. They are easily broken, and sometimes don’t display the same way everywhere when they should. My advice would be to stick to LaTeX if possible which pandoc will convert much more reliably.

2 Likes

So you mean, populate a LaTeX (which I am comfortable) template and then convert it with pandoc to everything else?

Latex does sound like a good option.


If you went the html route though, this is how you can make a table.

For the simplest table that would work on a very old browser:

For a bootstrap table (which classes are available in jupyter):

// the second option is what is used in: Best tool for printing tables in Jupyter notebook? - #8 by djsegal

( beyond this, i guess i don’t really understand the use-case :confused: )


edit: you could for example, then, prevent cells from being wider than 160px or something

// see the max-width style attribute

Thanks for the links. The use-case is: I have clients that I want send an invoice, quote, or receipt to. I need to populate those with data I save in simple txt files. The whole pipe-line from a test file with their name, the expenses, etc to an automated email+pdf attachment+stripe website (for them to pay with a credit card) requires me to build about 3-4 tables.
My “bottleneck” format where everything needed to go through is/was markdown. I guess I should switch that up to LaTeX… Feel free to PM me if you want to know more.

Yes, I think that would be much safer than having markdown as the “primary” source. Relying on markdown would just be asking for trouble if there are tables.

1 Like

When I read the name “Markdown tables”, my brain short-circuited and I assumed you were aiming at solving the following problem:

Pretty-printing simple 2D data with row and column headers to the REPL or a text file (i.e. assuming a monospaced typeface), with a few simple customization options concerning lines (where to put lines & which Unicode characters to use for them) and cell alignment (e.g. left, right, center, decimal point).

But now I get the impression that your package is for outputing nice-looking tables in proportional typefaces, using smart layout engines like LaTeX or HTML/CSS to “just do the right thing” for whatever output format or size you need. Is this roughly correct?

Now that I am no longer confusing Markdown text input with its output rendering, can someone point me to some packages that address the “simple monospaced table” use case? (And sorry for hijacking the thread to ask this!)

Just gonna throw it out there:

// for example: tetris.jl loads differently if you’re in the REPL

I like the markdown idea better than html/latex… using markdown means you can print it in the REPL and convert it to anything else as well as well. It will be useful everywhere, packages that extend arrays and dataframes can use it in show().

But multiline could be hard!

Might be some useful code in here if your comfortable with haskell:

https://github.com/baig/pandoc-csv2table

or python:
https://github.com/ickc/pantable

1 Like

Latexify can do this with the md function

to get something copy and pasteable, you can just do show(md(df))

1 Like