Skip to content
This repository was archived by the owner on Jan 14, 2022. It is now read-only.

Commit 5cac30c

Browse files
Merge pull request #4 from gpredictive/master
Fix unintended empty leading column
2 parents 7ee605e + 7bb573b commit 5cac30c

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

lib/markdown-tables.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def self.plain_text(md_table)
4343
md_table !~ // && raise('Invalid input')
4444

4545
# Split the table into lines to get the labels, rows, and alignments.
46-
lines = md_table.split("\n")
46+
lines = md_table.split("\n").map { |l| l.gsub(/^\||\|$/, '') }
4747
alignments = lines[1].split('|')
4848
# labels or rows might have some empty values but alignments
4949
# is guaranteed to be of the right width.

test/unittest.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,19 @@ def test_make_table
113113

114114
def test_plain_text
115115
assert_equal(
116-
MarkdownTables.plain_text("a|b|c\n:-:|:-:|:-:\n1|2|3\n4|5|6\n7|8|9"),
116+
MarkdownTables.plain_text("|a|b|c|\n|:-:|:-:|:-:|\n|1|2|3|\n|4|5|6|\n|7|8|9|"),
117117
"|===|===|===|\n| a | b | c |\n|===|===|===|\n| 1 | 2 | 3 |\n|---|---|---|\n| 4 | 5 | 6 |\n|---|---|---|\n| 7 | 8 | 9 |\n|===|===|===|",
118118
)
119119
assert_equal(
120-
MarkdownTables.plain_text("aaaaa|bbbbb|ccccc\n-:|:-:|:-\n1|2|3\n4|5|6\n7|8|9"),
120+
MarkdownTables.plain_text("|aaaaa|bbbbb|ccccc|\n|-:|:-:|:-|\n|1|2|3|\n|4|5|6|\n|7|8|9|"),
121121
"|=======|=======|=======|\n| aaaaa | bbbbb | ccccc |\n|=======|=======|=======|\n| 1 | 2 | 3 |\n|-------|-------|-------|\n| 4 | 5 | 6 |\n|-------|-------|-------|\n| 7 | 8 | 9 |\n|=======|=======|=======|",
122122
)
123123
assert_equal(
124-
MarkdownTables.plain_text("a|b|c\n:-:|:-:|:-:\n1|4|7\n||8\n|6|"),
124+
MarkdownTables.plain_text("|a|b|c|\n|:-:|:-:|:-:|\n|1|4|7|\n|||8|\n||6||"),
125125
"|===|===|===|\n| a | b | c |\n|===|===|===|\n| 1 | 4 | 7 |\n|---|---|---|\n| | | 8 |\n|---|---|---|\n| | 6 | |\n|===|===|===|",
126126
)
127127
assert_equal(
128-
MarkdownTables.plain_text("||\n:-:|:-:|:-:\n||\n||\n||"),
128+
MarkdownTables.plain_text("||||\n|:-:|:-:|:-:|\n||||\n||||\n||||"),
129129
"|===|===|===|\n| | | |\n|===|===|===|\n| | | |\n|---|---|---|\n| | | |\n|---|---|---|\n| | | |\n|===|===|===|"
130130
)
131131
end

0 commit comments

Comments
 (0)