Differential D20393 Diff 48698 src/markup/engine/remarkup/blockrule/PhutilRemarkupQuotesBlockRule.php
Changeset View
Changeset View
Standalone View
Standalone View
src/markup/engine/remarkup/blockrule/PhutilRemarkupQuotesBlockRule.php
<?php | <?php | ||||
final class PhutilRemarkupQuotesBlockRule extends PhutilRemarkupBlockRule { | final class PhutilRemarkupQuotesBlockRule | ||||
extends PhutilRemarkupQuotedBlockRule { | |||||
public function getMatchingLineCount(array $lines, $cursor) { | public function getMatchingLineCount(array $lines, $cursor) { | ||||
$pos = $cursor; | $pos = $cursor; | ||||
if (preg_match('/^>/', $lines[$pos])) { | if (preg_match('/^>/', $lines[$pos])) { | ||||
do { | do { | ||||
++$pos; | ++$pos; | ||||
} while (isset($lines[$pos]) && preg_match('/^>/', $lines[$pos])); | } while (isset($lines[$pos]) && preg_match('/^>/', $lines[$pos])); | ||||
} | } | ||||
return ($pos - $cursor); | return ($pos - $cursor); | ||||
} | } | ||||
public function supportsChildBlocks() { | |||||
return true; | |||||
} | |||||
public function extractChildText($text) { | public function extractChildText($text) { | ||||
$text = phutil_split_lines($text, true); | return array('', $this->normalizeQuotedBody($text)); | ||||
foreach ($text as $key => $line) { | |||||
$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)); | |||||
} | } | ||||
public function markupText($text, $children) { | public function markupText($text, $children) { | ||||
if ($this->getEngine()->isTextMode()) { | if ($this->getEngine()->isTextMode()) { | ||||
$lines = rtrim($children, "\n"); | return $this->getQuotedText($children); | ||||
$lines = phutil_split_lines($lines); | |||||
foreach ($lines as $key => $line) { | |||||
if (isset($line[0]) && ($line[0] == '>')) { | |||||
$line = '>'.$line; | |||||
} else { | |||||
$line = '> '.$line; | |||||
} | |||||
$lines[$key] = $line; | |||||
} | |||||
return implode('', $lines); | |||||
} | } | ||||
$attributes = array(); | $attributes = array(); | ||||
if ($this->getEngine()->isHTMLMailMode()) { | if ($this->getEngine()->isHTMLMailMode()) { | ||||
$style = array( | $style = array( | ||||
'border-left: 3px solid #a7b5bf;', | 'border-left: 3px solid #a7b5bf;', | ||||
'color: #464c5c;', | 'color: #464c5c;', | ||||
'font-style: italic;', | 'font-style: italic;', | ||||
Show All 15 Lines |