From abdde6583bb69074d706d4756626ddf5642beb21 Mon Sep 17 00:00:00 2001 From: Makoto Chiba Date: Sun, 15 May 2016 01:04:51 +0900 Subject: [PATCH 1/2] 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. --- lib/CopyAsMarkdown/CopyAsMarkdown.php | 4 ++-- tests/lib/CopyAsMarkdown/CopyAsMarkdownTest.php | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/CopyAsMarkdown/CopyAsMarkdown.php b/lib/CopyAsMarkdown/CopyAsMarkdown.php index f68cbf9..623f819 100644 --- a/lib/CopyAsMarkdown/CopyAsMarkdown.php +++ b/lib/CopyAsMarkdown/CopyAsMarkdown.php @@ -81,10 +81,10 @@ protected function _createDataRows(array $rows) if (!empty($str)) { $str .= "|"; } - $str .= $val; + $str .= str_replace(array("\n", "\r"), '', nl2br($val)); } $result[] = $str; } return implode("\n", $result); } -} \ No newline at end of file +} diff --git a/tests/lib/CopyAsMarkdown/CopyAsMarkdownTest.php b/tests/lib/CopyAsMarkdown/CopyAsMarkdownTest.php index 52aaa35..7fbbe21 100644 --- a/tests/lib/CopyAsMarkdown/CopyAsMarkdownTest.php +++ b/tests/lib/CopyAsMarkdown/CopyAsMarkdownTest.php @@ -33,6 +33,16 @@ public function testCreateDataRows() array('d', 'e', 'f'), ))); } + + public function testCreateDataRows_ReturnLineFeedRemovedData_WhenHasLineFeedInData() + { + $expected = 'a|b1
b2
b3|c'; + $this->assertEquals($expected, $this->copyAsMarkdown->createDataRows(array( + array('a', 'b1 +b2 +b3', 'c'), + ))); + } } class CopyAsMarkdownExtended extends CopyAsMarkdown From 4d3fe8ccddc0d36a9da5e64b024b973423aa0e5f Mon Sep 17 00:00:00 2001 From: Makoto Chiba Date: Sun, 15 May 2016 01:17:06 +0900 Subject: [PATCH 2/2] Update for plist --- copyAsMarkdown.spBundle/command.plist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/copyAsMarkdown.spBundle/command.plist b/copyAsMarkdown.spBundle/command.plist index fd9313a..4f7d178 100644 --- a/copyAsMarkdown.spBundle/command.plist +++ b/copyAsMarkdown.spBundle/command.plist @@ -88,7 +88,7 @@ class CopyAsMarkdown if (!empty($str)) { $str .= "|"; } - $str .= $val; + $str .= str_replace(array("\n", "\r"), '', nl2br($val)); } $result[] = $str; }