Skip to content

Commit

Permalink
Fix table without body support to remark(3)
Browse files Browse the repository at this point in the history
This adds support for properly detecting the following table in
`gfm: true` mode:

```md
| Alpha | Bravo |
| ----- | ----- |
```
  • Loading branch information
wooorm committed Jan 4, 2016
1 parent 1d36801 commit 9a3bc47
Show file tree
Hide file tree
Showing 4 changed files with 274 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var HORIZONTAL_RULE_MARKER_COUNT = 3;
var MIN_CLOSING_HTML_NEWLINE_COUNT = 2;
var MIN_BREAK_LENGTH = 2;
var MIN_TABLE_COLUMNS = 2;
var MIN_TABLE_ROWS = 3;
var MIN_TABLE_ROWS = 2;

/*
* Error messages.
Expand Down Expand Up @@ -3119,14 +3119,6 @@ function tokenizeTable(eat, value, silent) {
eat(C_NEWLINE);
}

/*
* Eat the alignment row.
*/

if (position === 1) {
eat(alignments + C_NEWLINE);
}

/*
* Eat the row.
*/
Expand Down Expand Up @@ -3222,6 +3214,14 @@ function tokenizeTable(eat, value, silent) {
preamble = false;
index++;
}

/*
* Eat the alignment row.
*/

if (!position) {
eat(C_NEWLINE + alignments);
}
}

return table;
Expand Down
4 changes: 4 additions & 0 deletions test/input/table-no-body.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Foo

| Name | GitHub | Twitter |
| ---- | ------ | ------- |
179 changes: 179 additions & 0 deletions test/tree/table-no-body.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
{
"type": "root",
"children": [
{
"type": "heading",
"depth": 1,
"children": [
{
"type": "text",
"value": "Foo",
"position": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 6
},
"indent": []
}
}
],
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 6
},
"indent": []
}
},
{
"type": "table",
"align": [
null,
null,
null
],
"children": [
{
"type": "tableHeader",
"children": [
{
"type": "tableCell",
"children": [
{
"type": "text",
"value": "Name",
"position": {
"start": {
"line": 3,
"column": 3
},
"end": {
"line": 3,
"column": 7
},
"indent": []
}
}
],
"position": {
"start": {
"line": 3,
"column": 3
},
"end": {
"line": 3,
"column": 7
},
"indent": []
}
},
{
"type": "tableCell",
"children": [
{
"type": "text",
"value": "GitHub",
"position": {
"start": {
"line": 3,
"column": 10
},
"end": {
"line": 3,
"column": 16
},
"indent": []
}
}
],
"position": {
"start": {
"line": 3,
"column": 10
},
"end": {
"line": 3,
"column": 16
},
"indent": []
}
},
{
"type": "tableCell",
"children": [
{
"type": "text",
"value": "Twitter",
"position": {
"start": {
"line": 3,
"column": 19
},
"end": {
"line": 3,
"column": 26
},
"indent": []
}
}
],
"position": {
"start": {
"line": 3,
"column": 19
},
"end": {
"line": 3,
"column": 26
},
"indent": []
}
}
],
"position": {
"start": {
"line": 3,
"column": 1
},
"end": {
"line": 3,
"column": 28
},
"indent": []
}
}
],
"position": {
"start": {
"line": 3,
"column": 1
},
"end": {
"line": 4,
"column": 28
},
"indent": [
1
]
}
}
],
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 5,
"column": 1
}
}
}
82 changes: 82 additions & 0 deletions test/tree/table-no-body.nogfm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"type": "root",
"children": [
{
"type": "heading",
"depth": 1,
"children": [
{
"type": "text",
"value": "Foo",
"position": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 6
},
"indent": []
}
}
],
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 6
},
"indent": []
}
},
{
"type": "paragraph",
"children": [
{
"type": "text",
"value": "| Name | GitHub | Twitter |\n| ---- | ------ | ------- |",
"position": {
"start": {
"line": 3,
"column": 1
},
"end": {
"line": 4,
"column": 28
},
"indent": [
1
]
}
}
],
"position": {
"start": {
"line": 3,
"column": 1
},
"end": {
"line": 4,
"column": 28
},
"indent": [
1
]
}
}
],
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 5,
"column": 1
}
}
}

0 comments on commit 9a3bc47

Please sign in to comment.