Please can we have markdown tables on dba.se

Several sites have MathJax enabled, so there is obviously some room for site-specific markdown.

Therefore please can we have markdown tables here on dba.se? There is an open feature-request for this on mSO, but whereas it is hardly a key feature for a programming Q&A site, a significant percentage of our questions and answers contain tabular sample data, and real tables will make them neater and easier to read.

All we can do now is use ascii art but this has a number of drawbacks.

If the feature request goes through I'm pretty sure Jake Feasel will be happy to tweak SQL Fiddle to make it produce compatible markdown.

-- edit:

I've discovered that MathJax isn't implemented as a markdown extension after all, it is a script that runs on the page. Apparently the 'Go' board game site had it's own code as well for displaying board positions, but I'm not sure whether that was markdown or a script.

Anyway, this feature-request is specifically for a markdown extension, the script in my answer is just to prove the principle. We'd settle for a Javascript solution if that's the only thing on offer though!

• + NINE THOUSAND – JNK Mar 28 '13 at 14:38
• You .. you broke my scanner. – jcolebrand Mar 28 '13 at 15:10
• I need an adult... – DForck42 Apr 12 '13 at 14:21
• @DForck42 I am an adult. – Chris Forrence Apr 15 '13 at 16:12
• @ChrisForrence i think we've officially hijacked this meta... with dbz abridged... – DForck42 Apr 15 '13 at 21:05
• – kenorb Aug 18 '15 at 18:18
• Enabling MathJax would allow us to create tables. As here. aviation.stackexchange.com/q/22229/3383 – Martin Smith Oct 22 '15 at 7:52
• @Martin true, though the syntax is a bit yuck – Jack Douglas Oct 22 '15 at 13:35

At this point we have no plans to extend Markdown syntax to support tables. The extension itself isn't the hard part. The display of tables in posts would be fairly hard to get right.

There are a few extensions already (like what PHP Markdown does), but the syntax isn't very intuitive, and it's very easy to start breaking page layout with tables, nested tables, and so on.

I think the userscript Jack started working on is a step in the right direction, but it doesn't seem to make tables significantly prettier or easier to read than their raw ASCII versions.

My advice for now is to continue developing your script if you think it's necessary. Get it to the point where many people are using it, and we can see about integrating it into the site itself.

Update (March 2016): we are using CommonMark for topics and examples created in Documentation. The CommonMark parser we have does include table support and we have talked about eventually switching Q&A over to it as well some time after Documentation leaves private beta. However, unfortunately at the moment I don't have anything that even resembles an ETA.

• Thanks for getting back to us Adam. Maybe I'm missing something but I don't understand this "The display of tables in posts would be fairly hard to get right". That's the point of my script, isn't it, to demonstrate an acceptable way of displaying tables. In this case we are suggesting they are only allowed inside code sections and of course the markdown extension would not allow nesting (or do you mean the nesting of this table within the tables used for layout on the main page?—in which case, haven't we demonstrated that it doesn't break the page layout, at least here on meta?) – Jack Douglas May 17 '13 at 14:20
• @JackDouglas I was talking about implementing table support in Markdown in general. We don't want to complicate the syntax or diverge too far from the public Markdown spec. If we're going to do that at all, we can't just stop at a halfbaked table implementation that only suits one site. Your script takes us closer to something usable for DBA.SE specifically, but (and maybe I just don't fully appreciate the issues with the ASCII tables) I'm honestly not seeing much difference from just showing the ASCII table in the first place. – Adam Lear May 18 '13 at 4:11
• If SQL Fiddle can theoretically produce acceptable Markdown (if this were implemented), can't it produce an ASCII table you can just copy and paste into a post? – Adam Lear May 18 '13 at 4:11
• Hi Adam, yes there is quite a bit we can do with Ascii Art, including output from SQLFiddle. It's a bit ugly, but imo worse than that, it is wide. Each vertical takes one char of our limited space, and using hacks like <sub> mess with the lines (having <small> etc would actually be a great improvement). Anyway, I've added prettier tables to my proof of principle above: I'd made no effort to make them look nice before as I was trying to show that they wouldn't mess with the layout. – Jack Douglas May 18 '13 at 7:46
• Of course there is no markdown spec for tables, so any solution inside markdow could be regarded as 'half-baked'. In fact I think enabling tables generally would be a disaster for the layout as Tim mentioned, so the only option is a strictly restricted syntax. I imagined it would only be for dba.se, but reading between the lines, am I right to be hearing that markdown=network and userscript=site-specific? If that is set in stone, I may give up pushing for a markdown solution as a network-wide change is probably a lost cause, I've only ever been asking for a dba.se site-specific change. – Jack Douglas May 18 '13 at 7:50
• Not prettier? Do we watch the same movie? The table above is much better than any ascii-art. – dezso May 18 '13 at 15:45
• Thanks Adam, in the meantime I've accepted your answer, because, well, whatever you say is the answer :) – Jack Douglas May 18 '13 at 19:24
• Thank you! Even without an ETA this is really encouraging :) – Jack Douglas Mar 17 '16 at 18:14
• In addition to @JackDouglas 's comment above I would like to say I'm impressed and appreciative that you remembered this post years later, and cared enough to give us this status update. – Erik Mar 20 '16 at 12:01
• @Erik Alas, I can't take credit for remembering. :) Paul White pinged me in chat and asked if there were any updates. – Adam Lear Mar 20 '16 at 17:37
• @AdamLear "...eventually switching Q&A over to it as well some time after Documentation leaves private beta." Any chance there's an update on this, since Documentation launched publicly last year? <hopeful grin> – AMtwo Apr 12 '17 at 18:28
• @AMtwo Not at the moment, sorry. Switching out the markdown parser is a pretty big undertaking and it's pretty down on the list. – Adam Lear Apr 12 '17 at 18:39
• @AdamLear Is this still a possibility since the closing of Documentation? – LowlyDBA Oct 10 '17 at 19:40
• @LowlyDBA It is, but at roughly the same priority as before - pretty down on the list, definitely not happening this year. – Adam Lear Oct 10 '17 at 20:06
• Thanks for the non-ETA. Sounds kind of promising... – John aka hot2use Jan 15 '18 at 13:27
a table:

|Item    |Value|
|--------|----:|
|Computer|$1600| |Phone |$12|
|Pipe    |   $1|  a wide table: |Item |Value| |--------|----:| |Computer|$1600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000|
|Phone   |  $12| |Pipe |$1|


a table and a wide table:

|Item    |Value|
|--------|----:|
|Computer|$1600| |Phone |$12|
|Pipe    |   $1| |Item |Value| |--------|----:| |Computer|$1600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000|
|Phone   |  $12| |Pipe |$1|


I've added this table as part of a plan to develop a userscript demo-ing the result.

For now, try this on the browser console (tested on Firefox only):

$('div.post-text>pre').each(function(){$(this).children().html($(this).children().html().replace(/(^\|.*\|$\n)+/gm,function(match){ var index = 0; return '<table style="margin: 0.5em; table-layout: fixed; font-size: smaller; background-color: white; box-shadow: 2px 2px 6px #777;">'+match.replace(/^(.*)$/gm,function(match){ var cell='th'; index++; if(index===2){ return ''; } if(index>2){ cell='td'; } return '<tr>'+match.replace(/^\|/,'<'+cell+'>').replace(/\|$/,'</'+cell+'>').replace(/\|/,'</'+cell+'><'+cell+'>')+'<tr>'; })+'</table>'; })); }).find('td,th').css('border','1px solid black').css('padding','2px').each(function(){ $(this).text($(this).text().replace(/^\s+|\s+\$/g, '')); }).filter('th').css('background-color', '#eee')


This is just to prove the principle and I don't expect it to be robust. It's also missing features like justification at the moment.

Here's a screenshot of the output for those who can't run the script:

• Neat! Works in Chrome too. – Mat May 15 '13 at 5:52
• Thanks @Mat, that is good to know – Jack Douglas May 15 '13 at 6:28
• @Mat would you mind checking the new version in Chrome too? – Jack Douglas May 15 '13 at 10:30
• Works fine on Chrome 26.0.1410.64, all four tables look good. – Mat May 15 '13 at 11:07
• Pure magic! tested on Chromium 25.0.1364.160 Ubuntu 12.10 – dezso May 15 '13 at 11:41
• @dezso great, thanks. I'm hoping SE will build this into the Markdown for dba.se rather than adding a script like this to our pages, so this is just to prove it's possible. We'll see! – Jack Douglas May 15 '13 at 12:09
• This is an ability that is sorely needed across every site to which I post. And that includes Stack Overflow, Space, Sci-Fi and Fantasy, Movies.. – Andrew Thompson Mar 22 '14 at 4:14
• @Andrew yes it's useful everywhere for some Q&A, here it's useful for the vast majority though: if we don't get it I'm guessing nobody will :( – Jack Douglas Mar 22 '14 at 7:28

An alternative, not so nice but simpler, would be to have css line-height: 1 set for code blocks (.post-text pre { line-height: 1; }) on dba.se.

Unicode tables like this would then not have broken lines:

values ('Donald Duck')
, ('Micky Mouse');

┌─────────────┐
│   column1   │
├─────────────┤
│ Donald Duck │
│ Micky Mouse │
└─────────────┘


so they would look like this:

The lines of code are squashed together now, but I don't think it looks worse, maybe even an improvement.

• I ran this by Jin and he wasn't on board. Sorry. – Adam Lear Jun 9 '14 at 20:40
• @JackDouglas ... UI coding is hard. we'd rather do things like split meta (that breeding ground of whinging, hatred, and other unsavory behaviors) than enhance usability. – swasheck Jun 9 '14 at 20:44