Skip to content

Commit abdde65

Browse files
committed
Support for line feed in data
The markdown result get broken when the line feed was included in the data. So we can output valid maridown data by converting into br tag by nl2br from line feed.
1 parent 4f5bc50 commit abdde65

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/CopyAsMarkdown/CopyAsMarkdown.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ protected function _createDataRows(array $rows)
8181
if (!empty($str)) {
8282
$str .= "|";
8383
}
84-
$str .= $val;
84+
$str .= str_replace(array("\n", "\r"), '', nl2br($val));
8585
}
8686
$result[] = $str;
8787
}
8888
return implode("\n", $result);
8989
}
90-
}
90+
}

tests/lib/CopyAsMarkdown/CopyAsMarkdownTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ public function testCreateDataRows()
3333
array('d', 'e', 'f'),
3434
)));
3535
}
36+
37+
public function testCreateDataRows_ReturnLineFeedRemovedData_WhenHasLineFeedInData()
38+
{
39+
$expected = 'a|b1<br />b2<br />b3|c';
40+
$this->assertEquals($expected, $this->copyAsMarkdown->createDataRows(array(
41+
array('a', 'b1
42+
b2
43+
b3', 'c'),
44+
)));
45+
}
3646
}
3747

3848
class CopyAsMarkdownExtended extends CopyAsMarkdown

0 commit comments

Comments
 (0)