Skip to content

Adding Support for GFM Tables - #74

Merged
chjj merged 4 commits into
markedjs:masterfrom
kitsonk:gfm_tables
Jan 3, 2013
Merged

chjj merged 4 commits into
markedjs:masterfrom
kitsonk:gfm_tables

Conversation

@kitsonk

@kitsonk kitsonk commented Sep 3, 2012

Copy link
Copy Markdown
Contributor

Here is a modified pull request that only adds support for tables that are supported (but undocumented) as part of GFM. It is implemented in the same fashion as other GFM features. It appears to be fully compatible with the Sundown library (which is the markdown parser GFM is based on), though it is strictly based on the PHP Markdown Extra who appears to have introduced the "standard".

The following:

Header 1 | Header 2
-------- | --------
Cell 1   | Cell 2
Cell 3   | Cell 4

Will render as:

Header 1 Header 2
Cell 1 Cell 2
Cell 3 Cell 4

@arikon

arikon commented Oct 9, 2012

Copy link
Copy Markdown

Any chances that it will be merged?

@bbailes

bbailes commented Oct 10, 2012

Copy link
Copy Markdown

+1 for merging this into master!

@fengmk2

fengmk2 commented Nov 12, 2012

Copy link
Copy Markdown

+1 We need this!

@davidsteinberger

Copy link
Copy Markdown

+1

2 similar comments
@jcla1

jcla1 commented Nov 17, 2012

Copy link
Copy Markdown

+1

@leeoniya

Copy link
Copy Markdown

+1

@aleafs

aleafs commented Nov 18, 2012

Copy link
Copy Markdown

++1

@chjj

chjj commented Nov 18, 2012

Copy link
Copy Markdown
Member

Will look at this later.

@harrisj

harrisj commented Jan 2, 2013

Copy link
Copy Markdown

So, is this happening? I'd love it too

@chjj
chjj merged commit 832d05c into markedjs:master Jan 3, 2013
@chjj

chjj commented Jan 3, 2013

Copy link
Copy Markdown
Member

So, I spent a little while fixing/optimizing/refactoring @kitsonk's implementation a little bit. I'm going to consider this feature experimental for a little while. You can disable it with the tables option. @kitsonk, thank you for the PR.

@chjj chjj mentioned this pull request Jan 3, 2013
@harrisj

harrisj commented Jan 3, 2013

Copy link
Copy Markdown

Awesome. Thank you!

On Jan 3, 2013, at 7:29 AM, "Christopher Jeffrey" <notifications@github.commailto:notifications@github.com> wrote:

So, I spent a little while fixing/optimizing/refactoring @kitsonkhttps://github.com/kitsonk's implementation a little bit. I'm going to consider this feature experimental for a little while. You can disable it with the tables option. @kitsonkhttps://github.com/kitsonk, thank you for the PR.

—
Reply to this email directly or view it on GitHubhttps://github.com//pull/74#issuecomment-11842143.

@chjj

chjj commented Jan 4, 2013

Copy link
Copy Markdown
Member

Just a quick test.

testing

paragraph

one two
3 4

testing

testing

paragraph
| one | two |
| ----- | ----- |
| 3    |   4   |

testing

@chjj

chjj commented Jan 4, 2013

Copy link
Copy Markdown
Member

Once more.

testing

one two
3 4

testing

And one other:

paragraph

var foo = 1;

test

#one two
3 4

strike strike

code: foo
code: ```

@xiaohulu

xiaohulu commented Mar 5, 2013

Copy link
Copy Markdown

how to escape | in gfm table?

@kitsonk

kitsonk commented Mar 5, 2013

Copy link
Copy Markdown
Contributor Author

Best thing to do use use the HTML entity: &#124;

@xiaohulu

xiaohulu commented Mar 5, 2013

Copy link
Copy Markdown
| one | two |
| ----- | ----- |
| 1    |   2 `a|a`   |
| 1    |   2 `a&#124;a`   |

How to escape | in a|a

@kitsonk

kitsonk commented Mar 5, 2013

Copy link
Copy Markdown
Contributor Author

That appears to be an issue with the sundown parser that GitHub uses as well, so technically it is feature parity:

| one | two |
|-----|-----|
| 1 | 2 `a&#124;a` |
| 1 | a&#124;a |
| 1 | `a|a` |

Renders as:

one two
1 2 a&#124;a
1 a|a
1 `a

@kitsonk

kitsonk commented Mar 5, 2013

Copy link
Copy Markdown
Contributor Author

Just realised, there is a way around this:

| one |
|-----|
| <code>a&#124;a</code> |

Will render as:

one
a|a

In both marked and sundown.

@hahmed

hahmed commented May 1, 2013

Copy link
Copy Markdown

Is there any way to actually set the width of a table column?

@kitsonk

kitsonk commented May 1, 2013

Copy link
Copy Markdown
Contributor Author

Via CSS... :nth-child and other pseudo-selectors address this.

@hahmed

hahmed commented May 1, 2013

Copy link
Copy Markdown

@kitsonk I mean through markdown so some tables will be rendered bigger or smaller depending on width % set?

I am basically thinking how good this will be for writing documents that have tables in them.

@kitsonk

kitsonk commented May 1, 2013

Copy link
Copy Markdown
Contributor Author

It isn't part of the standard it is based on, and for good reason. Hard coding presentation in the markup doesn't allow flexibility when it renders. The only potential imrpovement would be to allow the specification of a class for a table, but again, none of the standards out there specify that, so I suspect @chjj wouldn't be interested in adding it, though there are some other issues here that talk about allowing some form of customisation of the output.

You can always use <table> if you need more flexibility.

@bdougie

bdougie commented Jul 28, 2015

Copy link
Copy Markdown

Anyone else having trouble getting tables to render using marked?

var singleColTest = "| one ||-----|  | <code>a&#124;a</code> |"

app.get('/', function (req, res) {
    // res.send('Hello World!');
    res.send(marked(singleColTest));
});

returns this

| one 
|-----|
| <code>a&#124;a</code> |

ghost pushed a commit to zergeborg/marked that referenced this pull request May 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.