Differential D15864 Diff 38216 src/applications/differential/render/DifferentialChangesetOneUpMailRenderer.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/render/DifferentialChangesetOneUpMailRenderer.php
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | public function renderTextChange( | ||||
$range_start, | $range_start, | ||||
$range_len, | $range_len, | ||||
$rows) { | $rows) { | ||||
$primitives = $this->buildPrimitives($range_start, $range_len); | $primitives = $this->buildPrimitives($range_start, $range_len); | ||||
return $this->renderPrimitives($primitives, $rows); | return $this->renderPrimitives($primitives, $rows); | ||||
} | } | ||||
protected function renderPrimitives(array $primitives, $rows) { | protected function renderPrimitives(array $primitives, $rows) { | ||||
epriestley: Here's a comment after some whitespace. | |||||
$out = array(); | $out = array(); | ||||
foreach ($primitives as $k => $p) { | foreach ($primitives as $k => $p) { | ||||
$type = $p['type']; | $type = $p['type']; | ||||
switch ($type) { | switch ($type) { | ||||
case 'old': | case 'old': | ||||
case 'new': | case 'new': | ||||
case 'old-file': | case 'old-file': | ||||
case 'new-file': | case 'new-file': | ||||
$is_old = ($type == 'old' || $type == 'old-file'); | $is_old = ($type == 'old' || $type == 'old-file'); | ||||
if ($is_old) { | if ($is_old) { | ||||
if ($p['htype']) { | if ($p['htype']) { | ||||
$style = 'background: #ffd0d0;'; | $style = 'background: #ffd0d0;'; | ||||
} else { | } else { | ||||
$style = null; | $style = null; | ||||
} | } | ||||
} else { | } else { | ||||
if ($p['htype']) { | if ($p['htype']) { | ||||
$style = 'background: #d0ffd0;'; | $style = 'background: #d0ffd0;'; | ||||
} else { | } else { | ||||
$style = null; | $style = null; | ||||
} | } | ||||
} | } | ||||
$out[] = array( | |||||
'style' => $style, | |||||
'render' => $p['render'], | |||||
'text' => (string)$p['render'], | |||||
); | |||||
break; | |||||
default: | |||||
break; | |||||
} | |||||
} | |||||
// Remove all leading and trailing empty lines, since these just look kind | |||||
// of weird in mail. | |||||
foreach ($out as $key => $line) { | |||||
if (!strlen(trim($line['text']))) { | |||||
unset($out[$key]); | |||||
} else { | |||||
break; | |||||
} | |||||
} | |||||
$keys = array_reverse(array_keys($out)); | |||||
foreach ($keys as $key) { | |||||
$line = $out[$key]; | |||||
if (!strlen(trim($line['text']))) { | |||||
unset($out[$key]); | |||||
} else { | |||||
break; | |||||
} | |||||
} | |||||
// If the user has commented on an empty line in the middle of a bunch of | |||||
// other empty lines, emit an explicit marker instead of just rendering | |||||
// nothing. | |||||
if (!$out) { | |||||
$out[] = array( | |||||
'style' => 'color: #888888;', | |||||
'render' => pht('(Empty.)'), | |||||
); | |||||
} | |||||
$render = array(); | |||||
foreach ($out as $line) { | |||||
$style = $line['style']; | |||||
$style = "padding: 0 8px; margin: 0 4px; {$style}"; | $style = "padding: 0 8px; margin: 0 4px; {$style}"; | ||||
$out[] = phutil_tag( | $render[] = phutil_tag( | ||||
'div', | 'div', | ||||
array( | array( | ||||
'style' => $style, | 'style' => $style, | ||||
), | ), | ||||
$p['render']); | $line['render']); | ||||
break; | |||||
default: | |||||
break; | |||||
} | |||||
} | } | ||||
$style_map = id(new PhabricatorDefaultSyntaxStyle()) | $style_map = id(new PhabricatorDefaultSyntaxStyle()) | ||||
->getRemarkupStyleMap(); | ->getRemarkupStyleMap(); | ||||
epriestleyAuthorUnsubmitted Not Done Inline ActionsHere's a comment on some whitespace. epriestley: Here's a comment //on// some whitespace. | |||||
$styled_body = id(new PhutilPygmentizeParser()) | $styled_body = id(new PhutilPygmentizeParser()) | ||||
->setMap($style_map) | ->setMap($style_map) | ||||
->parse((string)hsprintf('%s', $out)); | ->parse((string)hsprintf('%s', $render)); | ||||
return phutil_safe_html($styled_body); | return phutil_safe_html($styled_body); | ||||
} | } | ||||
} | } |
Here's a comment after some whitespace.