Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tables from MediaWiki to GitHub Flavored Markdown (GFM) #1996

Closed
peterjc opened this issue Mar 6, 2015 · 12 comments
Closed

Tables from MediaWiki to GitHub Flavored Markdown (GFM) #1996

peterjc opened this issue Mar 6, 2015 · 12 comments

Comments

@peterjc
Copy link

peterjc commented Mar 6, 2015

Minimal table examples based on official MediaWiki documentation at http://www.mediawiki.org/wiki/Help:Tables

$ cat table.mediawiki
Very simple table, one cell per line of MediaWiki markup:

{|
|Orange
|Apple
|-
|Bread
|Pie
|-
|Butter
|Ice cream 
|}

Small table, one row per line of MediaWiki markup:

{|
|  Orange    ||   Apple   ||   more
|-
|   Bread    ||   Pie     ||   more
|-
|   Butter   || Ice cream ||  and more
|}

The end.

Conversions with pandoc 1.13.2 (on Mac OS), here's the default markdown output (which I am not using):

$ pandoc -f mediawiki -t markdown table.mediawiki
Very simple table, one cell per line of MediaWiki markup:

  -------- -----------
  Orange   Apple
  Bread    Pie
  Butter   Ice cream
  -------- -----------

Small table, one row per line of MediaWiki markup:

  -------- ----------- ----------
  Orange   Apple       more
  Bread    Pie         more
  Butter   Ice cream   and more
  -------- ----------- ----------

The end.

Here's the GFM which I do want to use (and tables are one of the key differences Google introduced):

$ pandoc -f mediawiki -t markdown_github table.mediawiki -o table.md
$ cat table.md
Very simple table, one cell per line of MediaWiki markup:

|--------|-----------|
| Orange | Apple     |
| Bread  | Pie       |
| Butter | Ice cream |

Small table, one row per line of MediaWiki markup:

|--------|-----------|----------|
| Orange | Apple     | more     |
| Bread  | Pie       | more     |
| Butter | Ice cream | and more |

The end.

MediaWiki format table renders fine on GitHub:
https://github.com/peterjc/peterjc.github.io/blob/table_problem/table.mediawiki

The pandoc GFM Markdown output does not render properly on GitHub:
https://github.com/peterjc/peterjc.github.io/blob/table_problem/table.md

The GFM documentation on tables is limited https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#tables but all the examples I have seen appear to use (require?) a header row.

We can 'fix' the table by moving the dash line down one, making the first row into a header, e.g.

| Orange | Apple     |
|--------|-----------|
| Bread  | Pie       |
| Butter | Ice cream |

This 'works' but is visually not quite what the user may expect:

Orange Apple
Bread Pie
Butter Ice cream

In practice, most real tables do have a header row so this is usable.

Another hack may be to include a blank header row, e.g.

|        |           |
|--------|-----------|
| Orange | Apple     |
| Bread  | Pie       |
| Butter | Ice cream |

which gives:

Orange Apple
Bread Pie
Butter Ice cream

Here are those two work arounds as rendered directly on GitHub (rather than here on a GitHub issue which can sometimes be slightly different):

https://github.com/peterjc/peterjc.github.io/blob/table_problem/table_header.md

@jgm
Copy link
Owner

jgm commented Mar 6, 2015

Summary of the issue: pipe tables without headers are not rendered
correctly (either on github or in PHP Markdown Extra). The best
workaround seems to be rendering a pipe table with a header containing
blank cells. This should be a relatively easy fix.

@lierdakil
Copy link
Contributor

Note that kramdown supports pipe tables without header row. Personally, I'd prefer to have an extension option for this, if at all possible.

@jgm
Copy link
Owner

jgm commented Mar 25, 2015

+++ Nikolay Yakimov [Mar 25 15 05:09 ]:

Note that [kramdown][1] [supports][2] pipe tables without header row.

Argh! The fragmentation is killing me.

Personally, I'd prefer to have an extension option for this, if at all possible.

I'm open to this. Ext_headerless_pipe_tables?

@lierdakil
Copy link
Contributor

I'm open to this. Ext_headerless_pipe_tables?

Ext_headerless_pipe_tables sounds entirely reasonable. I could probably create a PR for this in a couple days, if you want some help -- it should be a relatively simple change.

@mietek
Copy link

mietek commented Jun 21, 2015

Note: If you have been using headerless pipe tables, this change may cause existing tables to break.

It would be nice to have Ext_headerless_pipe_tables to cover for this breaking change.

@sjackman
Copy link

Note that Pandoc is a little picky about the blank header. It's okay with the first but not the second.

|        |
|--------|----------
| Orange | Apple
| Bread  | Pie
| Butter | Ice cream
       |
-------|----------
Orange | Apple
Bread  | Pie
Butter | Ice cream

@sjackman
Copy link

Let's test GitHub issues:

|        |
|--------|----------
| Orange | Apple
| Bread  | Pie
| Butter | Ice cream
Orange
Bread
Butter

Pandoc is okay with this one, GitHub issues is not.


       |
-------|----------
Orange | Apple
Bread  | Pie
Butter | Ice cream
Orange
Bread
Butter

Neither Pandoc nor GitHub issues likes this one.

@sjackman
Copy link

Both are fine. Can Pandoc be fixed up to agree with GitHub issues?

Weird. The second column has been dropped. So strange.

@sjackman
Copy link

Let's try another.

       |           |
-------|-----------|
Orange | Apple     |
Bread  | Pie       |
Butter | Ice cream |
Orange Apple
Bread Pie
Butter Ice cream

GitHub is okay with this one, but Pandoc is not.

@sjackman
Copy link

The moral of the story appears to be: do not leave out either the leading or trailing column of pipes.

@jgm
Copy link
Owner

jgm commented Mar 10, 2016

When you try to actually specify the syntax for pipe tables, allowing that the initial and final bar are optional, it's surprisingly tricky. (And, unsurprisingly, no two implementations seem to agree.)

@iljabek
Copy link

iljabek commented Sep 27, 2018

@sjackman , sorry to bump the topic,
was the option "Ext_headerless_pipe_tables" implemented?

I'm converting a stash of tables and don't have an opportunity to modify all headers by hand.
is there a way e.g. to handle the headers flexibly in e.g. a lua script?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants