From a2445df24b27562148c29c10b175489013d67d73 Mon Sep 17 00:00:00 2001 From: Carsten Dietzel Date: Mon, 17 Dec 2018 10:44:10 +0000 Subject: [PATCH 1/2] Trim line breaks Remove line breaks from parsed lines since they will be added by the markdown writer --- src/Parser/MarkdownParser.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Parser/MarkdownParser.php b/src/Parser/MarkdownParser.php index d535a66..315f11f 100644 --- a/src/Parser/MarkdownParser.php +++ b/src/Parser/MarkdownParser.php @@ -68,7 +68,10 @@ public function getDocumentedDependencies( continue; } - $currentDependency->getAdditionalContent()->add($line); + // Trim line breaks, because they will be added by the writer + $trimmedLine = trim($line, "\n\r"); + + $currentDependency->getAdditionalContent()->add($trimmedLine); } $this->cleanupAdditionalContent($dependencies); From fddaa4092ecf77ea2ba3693097fa3feef2582272 Mon Sep 17 00:00:00 2001 From: Carsten Dietzel Date: Mon, 17 Dec 2018 10:46:05 +0000 Subject: [PATCH 2/2] Enhance markdown parser tests Making sure, consecutive empty lines will be removed (no new feature, just new test) --- tests/Parser/MarkdownParserTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/Parser/MarkdownParserTest.php b/tests/Parser/MarkdownParserTest.php index 9516137..ec08947 100644 --- a/tests/Parser/MarkdownParserTest.php +++ b/tests/Parser/MarkdownParserTest.php @@ -49,6 +49,11 @@ public function testItParsesDependenciesFileCorrectlyWithoutFilter() $this->assertNotNull($package); $this->assertCount(3, $package->getAdditionalContent()->getAll()); $this->assertEquals(['', 'test 1 ', 'test 2'], array_values($package->getAdditionalContent()->getAll())); + + $package = $packageList->get('Composer', 'symfony/yaml'); + $this->assertNotNull($package); + $this->assertCount(4, $package->getAdditionalContent()->getAll()); + $this->assertEquals(['', 'Will leave only one', '', 'consecutive empty line'], array_values($package->getAdditionalContent()->getAll())); } public function getValidDependenciesFileData(): string @@ -84,6 +89,12 @@ public function getValidDependenciesFileData(): string ##### symfony/yaml `v4.1.3` [link](https://packagist.org/packages/symfony/yaml) > Symfony Yaml Component +Will leave only one + + + +consecutive empty line + ##### zendframework/zend-servicemanager `3.3.2` [link](https://packagist.org/packages/zendframework/zend-servicemanager) > Factory-Driven Dependency Injection Container