1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-19 20:10:55 +01:00

Improve inline mail snippet rendering, possibly fixing Airmail?

Summary:
Ref T10694. General improvements:

  - Remove leading empty lines from context snippets.
  - Remove trailing empty lines from context snippets.
  - If we removed everything, render a note.
  - Try using `style` instead of `<pre>`? My thinking is that maybe Airmail has weird default rules for `<pre>`, since that's the biggest / most obvious thing that's different about this element to me.

Test Plan: Viewed normal comments locally, faked a comment on an empty line in the middle of a lot of other empty lines.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10694

Differential Revision: https://secure.phabricator.com/D15864
This commit is contained in:
epriestley 2016-05-06 11:46:46 -07:00
parent 371051ff37
commit 412fc34557
2 changed files with 53 additions and 10 deletions

View file

@ -376,13 +376,15 @@ final class DifferentialInlineCommentMailView
if ($is_html) { if ($is_html) {
$style = array( $style = array(
'font: 11px/15px "Menlo", "Consolas", "Monaco", monospace;', 'font: 11px/15px "Menlo", "Consolas", "Monaco", monospace;',
'white-space: pre-wrap;',
'clear: both;',
'padding: 4px 0;', 'padding: 4px 0;',
'margin: 0;', 'margin: 0;',
); );
$style = implode(' ', $style); $style = implode(' ', $style);
$patch = phutil_tag( $patch = phutil_tag(
'pre', 'div',
array( array(
'style' => $style, 'style' => $style,
), ),

View file

@ -50,6 +50,7 @@ final class DifferentialChangesetOneUpMailRenderer
protected function renderPrimitives(array $primitives, $rows) { protected function renderPrimitives(array $primitives, $rows) {
$out = array(); $out = array();
foreach ($primitives as $k => $p) { foreach ($primitives as $k => $p) {
$type = $p['type']; $type = $p['type'];
switch ($type) { switch ($type) {
@ -73,26 +74,66 @@ final class DifferentialChangesetOneUpMailRenderer
} }
} }
$style = "padding: 0 8px; margin: 0 4px; {$style}"; $out[] = array(
$out[] = phutil_tag(
'div',
array(
'style' => $style, 'style' => $style,
), 'render' => $p['render'],
$p['render']); 'text' => (string)$p['render'],
);
break; break;
default: default:
break; 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}";
$render[] = phutil_tag(
'div',
array(
'style' => $style,
),
$line['render']);
}
$style_map = id(new PhabricatorDefaultSyntaxStyle()) $style_map = id(new PhabricatorDefaultSyntaxStyle())
->getRemarkupStyleMap(); ->getRemarkupStyleMap();
$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);
} }