Markdown tables

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.


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:

or python:

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

OK, my good people…
I’ve rewritten the whole thing (here). It now supports all three types of pandoc tables (simple_tables, multiline_tables, and grid_tables but not pipe_tables), and therefore cells with multiple lines as well. I didn’t bother with alignment.
Why is this half-:horse:ed? Because @ExpandingMan was right:
Even if I populate my table with the actual values I want in the resulting document, and the resulting table contains actual data instead of differently sized tags (for Mustache.jl to replace), I get hit by including a link. So the actual link is typically much wider than how it gets rendered in the resulting document (where it turns into a hyperlink). So the table still doesn’t look close to how I want it. So I will be abandoning this markdown method and listen to wiser people than me…

But, for what it’s worth, the code is out there, fork it!

julia> using MDtables

julia> a = [string(round(rand(), rand(1:6))) for i in 1:3, j in 1:5]
3×5 Array{String,2}:
 "0.9"    "0.69741"  "0.1"    "0.55514"   "0.9299"
 "0.32"   "0.354"    "0.759"  "0.4579"    "0.4"   
 "0.873"  "0.2069"   "0.1"    "0.292993"  "0.86"  

julia> a[1,2] = "row 1\nrow 2"
"row 1\nrow 2"

julia> open("", "w") do o
       print(o, print(GridTable, a))

results in this:

|0.86284 |row 1 |0.044129|0.946186|0.3     |
|        |row 2 |        |        |        |
|0.235   |0.249 |0.295207|0.081   |0.764316|
|0.418278|0.8516|0.82    |0.38    |0.27575 |

@Ronis_BR permanently solved this. See

I’ve therefore archived GitHub - yakir12/MDtables.jl

1 Like

Just wanted to mention a few package in the R ecosystem which I find really good with no good alternative even in the python ecosystem:

Other packages for Reproducible Research:

The above is probably amongst one of the few reasons I am still using R.