diff --git a/src/markup/engine/__tests__/PhutilRemarkupEngineTestCase.php b/src/markup/engine/__tests__/PhutilRemarkupEngineTestCase.php --- a/src/markup/engine/__tests__/PhutilRemarkupEngineTestCase.php +++ b/src/markup/engine/__tests__/PhutilRemarkupEngineTestCase.php @@ -21,6 +21,10 @@ list($input_remarkup, $expected_output, $expected_text) = $parts; + $input_remarkup = $this->unescapeTrailingWhitespace($input_remarkup); + $expected_output = $this->unescapeTrailingWhitespace($expected_output); + $expected_text = $this->unescapeTrailingWhitespace($expected_text); + $engine = $this->buildNewTestEngine(); switch ($file) { @@ -118,4 +122,11 @@ return $engine; } + + private function unescapeTrailingWhitespace($input) { + // Remove up to one "~" at the end of each line so trailing whitespace may + // be written in tests as " ~". + return preg_replace('/~$/m', '', $input); + } + } diff --git a/src/markup/engine/__tests__/remarkup/del.txt b/src/markup/engine/__tests__/remarkup/del.txt --- a/src/markup/engine/__tests__/remarkup/del.txt +++ b/src/markup/engine/__tests__/remarkup/del.txt @@ -1,11 +1,11 @@ -omg~~ wtf~~~~~ bbq~~~ lol~~ -~~deleted text~~ +omg~~ wtf~~~~~ bbq~~~ lol~~~ +~~deleted text~~~ ~~This is a great idea~~~ die forever please -~~~~~~ +~~~~~~~ ~~~~~~~~~~ -

omg~~ wtf~~~~~ bbq~~~ lol~~ +

omg~~ wtf~~~~~ bbq~~~ lol~~~ deleted text This is a great idea~ die forever please ~~~~~~

~~~~~~~~~~ -omg~~ wtf~~~~~ bbq~~~ lol~~ ~~deleted text~~ ~~This is a great idea~~~ die forever please ~~~~~~ +omg~~ wtf~~~~~ bbq~~~ lol~~ ~~deleted text~~ ~~This is a great idea~~~ die forever please ~~~~~~~ diff --git a/src/markup/engine/__tests__/remarkup/link-with-tilde.txt b/src/markup/engine/__tests__/remarkup/link-with-tilde.txt --- a/src/markup/engine/__tests__/remarkup/link-with-tilde.txt +++ b/src/markup/engine/__tests__/remarkup/link-with-tilde.txt @@ -1,5 +1,5 @@ -http://www.example.com/~ +http://www.example.com/~~ ~~~~~~~~~~

http://www.example.com/~

~~~~~~~~~~ -http://www.example.com/~ +http://www.example.com/~~ diff --git a/src/markup/engine/__tests__/remarkup/quoted-indent-block.txt b/src/markup/engine/__tests__/remarkup/quoted-indent-block.txt new file mode 100644 --- /dev/null +++ b/src/markup/engine/__tests__/remarkup/quoted-indent-block.txt @@ -0,0 +1,5 @@ +> xyz +~~~~~~~~~~ +
xyz
+~~~~~~~~~~ +> xyz diff --git a/src/markup/engine/__tests__/remarkup/quoted-lists.txt b/src/markup/engine/__tests__/remarkup/quoted-lists.txt new file mode 100644 --- /dev/null +++ b/src/markup/engine/__tests__/remarkup/quoted-lists.txt @@ -0,0 +1,24 @@ +> # X +> # Y +> +> B +> +> * C +~~~~~~~~~~ +
    +
  1. X
  2. +
  3. Y
  4. +
+ +

B

+ +
+~~~~~~~~~~ +> 1. X +> 2. Y +> ~ +> B +> ~ +> - C diff --git a/src/markup/engine/__tests__/remarkup/quotes.txt b/src/markup/engine/__tests__/remarkup/quotes.txt --- a/src/markup/engine/__tests__/remarkup/quotes.txt +++ b/src/markup/engine/__tests__/remarkup/quotes.txt @@ -3,7 +3,7 @@ > of your inflight food service. ~~~~~~~~~~

Dear Sir, - I am utterly disgusted with the quality - of your inflight food service.

+I am utterly disgusted with the quality +of your inflight food service.

~~~~~~~~~~ > Dear Sir, I am utterly disgusted with the quality of your inflight food service. diff --git a/src/markup/engine/__tests__/remarkup/raw-escape.txt b/src/markup/engine/__tests__/remarkup/raw-escape.txt --- a/src/markup/engine/__tests__/remarkup/raw-escape.txt +++ b/src/markup/engine/__tests__/remarkup/raw-escape.txt @@ -1,4 +1,4 @@ -~1~ +~1~~ ~2Z @@ -10,7 +10,7 @@

~a

~~~~~~~~~~ -~1~ +~1~~ ~2Z diff --git a/src/markup/engine/remarkup/blockrule/PhutilRemarkupQuotesBlockRule.php b/src/markup/engine/remarkup/blockrule/PhutilRemarkupQuotesBlockRule.php --- a/src/markup/engine/remarkup/blockrule/PhutilRemarkupQuotesBlockRule.php +++ b/src/markup/engine/remarkup/blockrule/PhutilRemarkupQuotesBlockRule.php @@ -24,6 +24,47 @@ $text[$key] = substr($line, 1); } + // If every line in the block is empty or begins with at least one leading + // space, strip the initial space off each line. When we quote text, we + // normally add "> " (with a space) to the beginning of each line, which + // can disrupt some other rules. If the block appears to have this space + // in front of each line, remove it. + + $strip_space = true; + foreach ($text as $key => $line) { + $len = strlen($line); + + if (!$len) { + // We'll still strip spaces if there are some completely empty + // lines, they may have just had trailing whitespace trimmed. + continue; + } + + if ($line[0] == ' ' || $line[0] == "\n") { + continue; + } + + // The first character of this line is something other than a space, so + // we can't strip spaces. + $strip_space = false; + break; + } + + if ($strip_space) { + foreach ($text as $key => $line) { + $len = strlen($line); + if (!$len) { + continue; + } + + if ($line[0] !== ' ') { + continue; + } + + $text[$key] = substr($line, 1); + } + } + return array('', implode('', $text)); }