diff --git a/NetscapeBookmarkParser.php b/NetscapeBookmarkParser.php index 92829c9..aacf984 100644 --- a/NetscapeBookmarkParser.php +++ b/NetscapeBookmarkParser.php @@ -321,15 +321,15 @@ public static function sanitizeString($bookmarkString) // trim whitespace $sanitized = trim($sanitized); - // trim carriage returns, replace tabs by a single space - $sanitized = str_replace(array("\r", "\t"), array('',' '), $sanitized); + // trim carriage returns + $sanitized = str_replace("\r", '', $sanitized); // convert multiline descriptions to one-line descriptions // line feeds are converted to
$sanitized = preg_replace_callback( '@
(.*?)('.str_replace("\n", '
', trim($match[1])).PHP_EOL. $match[2]; + return '
'.str_replace("\n", '
', trim($match[1])).PHP_EOL. $match[2]; }, $sanitized ); diff --git a/tests/ParseShaarliWithTabsAndSpacesTest.php b/tests/ParseShaarliWithTabsAndSpacesTest.php new file mode 100644 index 0000000..ff990c8 --- /dev/null +++ b/tests/ParseShaarliWithTabsAndSpacesTest.php @@ -0,0 +1,28 @@ +parseFile('tests/input/shaarli_with_tabs_and_spaces.htm'); + + static::assertSame( + trim(file_get_contents('tests/output/shaarli_with_tabs_and_spaces.txt')), + $bkm[0]['note'] + ); + } +} diff --git a/tests/input/shaarli_with_tabs_and_spaces.htm b/tests/input/shaarli_with_tabs_and_spaces.htm new file mode 100644 index 0000000..d0470c1 --- /dev/null +++ b/tests/input/shaarli_with_tabs_and_spaces.htm @@ -0,0 +1,27 @@ + + + +My local links +

Shaarli export of all bookmarks on Sat, 06 Jun 20 17:19:06 +0200

+

+

Note: Code tests +
I will write some formating using spaces: + + * For example, + * lists, + + but also + + sublists + * use spaces. + +Also code: + +``` +foreach ($data['linksToDisplay'] as $key => $bookmark) { + $length = strlen($bookmark['title']) + (342 * strlen($bookmark['description'])) / 836; + if (! empty($bookmark['thumbnail'])) { + $length += 100; // 1 thumbnails roughly takes 100 pixels height. + } +} +```

diff --git a/tests/output/shaarli_with_tabs_and_spaces.txt b/tests/output/shaarli_with_tabs_and_spaces.txt new file mode 100644 index 0000000..bba2272 --- /dev/null +++ b/tests/output/shaarli_with_tabs_and_spaces.txt @@ -0,0 +1,18 @@ +I will write some formating using spaces: + + * For example, + * lists, + + but also + + sublists + * use spaces. + +Also code: + +``` +foreach ($data['linksToDisplay'] as $key => $bookmark) { + $length = strlen($bookmark['title']) + (342 * strlen($bookmark['description'])) / 836; + if (! empty($bookmark['thumbnail'])) { + $length += 100; // 1 thumbnails roughly takes 100 pixels height. + } +} +```