Skip to content

Commit

Permalink
Fix tables without final newline in remark(3)
Browse files Browse the repository at this point in the history
Closes GH-123.
  • Loading branch information
wooorm committed Jan 5, 2016
1 parent 96982a5 commit fd2f281
Show file tree
Hide file tree
Showing 4 changed files with 253 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -3014,6 +3014,10 @@ function tokenizeTable(eat, value, silent) {
lineIndex = value.indexOf(C_NEWLINE, index);
pipeIndex = value.indexOf(C_PIPE, index + 1);

if (lineIndex === -1) {
lineIndex = value.length;
}

if (
pipeIndex === -1 ||
pipeIndex > lineIndex
Expand Down
3 changes: 3 additions & 0 deletions test/input/table-no-end-of-line.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
|foo|bar|
|-|-|
|1|2|
194 changes: 194 additions & 0 deletions test/tree/table-no-end-of-line.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
{
"type": "root",
"children": [
{
"type": "table",
"align": [
null,
null
],
"children": [
{
"type": "tableHeader",
"children": [
{
"type": "tableCell",
"children": [
{
"type": "text",
"value": "foo",
"position": {
"start": {
"line": 1,
"column": 2
},
"end": {
"line": 1,
"column": 5
},
"indent": []
}
}
],
"position": {
"start": {
"line": 1,
"column": 2
},
"end": {
"line": 1,
"column": 5
},
"indent": []
}
},
{
"type": "tableCell",
"children": [
{
"type": "text",
"value": "bar",
"position": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 9
},
"indent": []
}
}
],
"position": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 9
},
"indent": []
}
}
],
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 10
},
"indent": []
}
},
{
"type": "tableRow",
"children": [
{
"type": "tableCell",
"children": [
{
"type": "text",
"value": "1",
"position": {
"start": {
"line": 3,
"column": 2
},
"end": {
"line": 3,
"column": 3
},
"indent": []
}
}
],
"position": {
"start": {
"line": 3,
"column": 2
},
"end": {
"line": 3,
"column": 3
},
"indent": []
}
},
{
"type": "tableCell",
"children": [
{
"type": "text",
"value": "2",
"position": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 5
},
"indent": []
}
}
],
"position": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 5
},
"indent": []
}
}
],
"position": {
"start": {
"line": 3,
"column": 1
},
"end": {
"line": 3,
"column": 6
},
"indent": []
}
}
],
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 3,
"column": 6
},
"indent": [
1,
1
]
}
}
],
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 3,
"column": 6
}
}
}
52 changes: 52 additions & 0 deletions test/tree/table-no-end-of-line.nogfm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"type": "root",
"children": [
{
"type": "paragraph",
"children": [
{
"type": "text",
"value": "|foo|bar|\n|-|-|\n|1|2|",
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 3,
"column": 6
},
"indent": [
1,
1
]
}
}
],
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 3,
"column": 6
},
"indent": [
1,
1
]
}
}
],
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 3,
"column": 6
}
}
}

0 comments on commit fd2f281

Please sign in to comment.