From c2973100e0de108971b82a23db2e325c5b6aa3ae Mon Sep 17 00:00:00 2001
From: Aidan Woods
Date: Sun, 3 Feb 2019 01:25:01 +0000
Subject: [PATCH] Fix whitespace trimming for soft and hard breaks
---
src/Components/Inlines/HardBreak.php | 3 +--
src/Components/Inlines/SoftBreak.php | 4 ++--
tests/data/line_break.html | 8 +++++++-
tests/data/line_break.md | 11 ++++++++++-
4 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/src/Components/Inlines/HardBreak.php b/src/Components/Inlines/HardBreak.php
index 40e4a11..f2bb819 100644
--- a/src/Components/Inlines/HardBreak.php
+++ b/src/Components/Inlines/HardBreak.php
@@ -41,8 +41,7 @@ final class HardBreak implements Inline
}
if (\substr($context, $offset -1, 1) === '\\') {
- $trimTrailingWhitespace = \rtrim(\substr($context, 0, $offset -1));
- $contentLen = \strlen($trimTrailingWhitespace);
+ $contentLen = $offset -1;
return new self($offset - $contentLen, $contentLen);
}
diff --git a/src/Components/Inlines/SoftBreak.php b/src/Components/Inlines/SoftBreak.php
index ac710f5..1def586 100644
--- a/src/Components/Inlines/SoftBreak.php
+++ b/src/Components/Inlines/SoftBreak.php
@@ -39,8 +39,8 @@ final class SoftBreak implements Inline
$context = $Excerpt->context();
$offset = $Excerpt->offset();
- $trimTrailingWhitespaceBefore = \rtrim(\substr($context, 0, $offset));
- $trimLeadingWhitespaceAfter = \ltrim(\substr($context, $offset + 1));
+ $trimTrailingWhitespaceBefore = \rtrim(\substr($context, 0, $offset), ' ');
+ $trimLeadingWhitespaceAfter = \ltrim(\substr($context, $offset + 1), ' ');
$contentLenBefore = \strlen($trimTrailingWhitespaceBefore);
$contentLenAfter = \strlen($trimLeadingWhitespaceAfter);
diff --git a/tests/data/line_break.html b/tests/data/line_break.html
index 5f37d85..a6de5f2 100644
--- a/tests/data/line_break.html
+++ b/tests/data/line_break.html
@@ -1,2 +1,8 @@
line
-line
\ No newline at end of file
+line
+foo \
+bar
+foo
+bar
+foo
+bar
\ No newline at end of file
diff --git a/tests/data/line_break.md b/tests/data/line_break.md
index 04dff43..da02d33 100644
--- a/tests/data/line_break.md
+++ b/tests/data/line_break.md
@@ -1,2 +1,11 @@
line
-line
\ No newline at end of file
+line
+
+foo \\
+bar
+
+foo \
+bar
+
+foo
+bar
\ No newline at end of file