@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+53 -10
+3 -1
src/applications/differential/mail/DifferentialInlineCommentMailView.php
··· 376 376 if ($is_html) { 377 377 $style = array( 378 378 'font: 11px/15px "Menlo", "Consolas", "Monaco", monospace;', 379 + 'white-space: pre-wrap;', 380 + 'clear: both;', 379 381 'padding: 4px 0;', 380 382 'margin: 0;', 381 383 ); 382 384 383 385 $style = implode(' ', $style); 384 386 $patch = phutil_tag( 385 - 'pre', 387 + 'div', 386 388 array( 387 389 'style' => $style, 388 390 ),
+50 -9
src/applications/differential/render/DifferentialChangesetOneUpMailRenderer.php
··· 50 50 51 51 protected function renderPrimitives(array $primitives, $rows) { 52 52 $out = array(); 53 + 53 54 foreach ($primitives as $k => $p) { 54 55 $type = $p['type']; 55 56 switch ($type) { ··· 73 74 } 74 75 } 75 76 76 - $style = "padding: 0 8px; margin: 0 4px; {$style}"; 77 - 78 - $out[] = phutil_tag( 79 - 'div', 80 - array( 81 - 'style' => $style, 82 - ), 83 - $p['render']); 77 + $out[] = array( 78 + 'style' => $style, 79 + 'render' => $p['render'], 80 + 'text' => (string)$p['render'], 81 + ); 84 82 break; 85 83 default: 86 84 break; 87 85 } 88 86 } 89 87 88 + // Remove all leading and trailing empty lines, since these just look kind 89 + // of weird in mail. 90 + foreach ($out as $key => $line) { 91 + if (!strlen(trim($line['text']))) { 92 + unset($out[$key]); 93 + } else { 94 + break; 95 + } 96 + } 97 + 98 + $keys = array_reverse(array_keys($out)); 99 + foreach ($keys as $key) { 100 + $line = $out[$key]; 101 + if (!strlen(trim($line['text']))) { 102 + unset($out[$key]); 103 + } else { 104 + break; 105 + } 106 + } 107 + 108 + // If the user has commented on an empty line in the middle of a bunch of 109 + // other empty lines, emit an explicit marker instead of just rendering 110 + // nothing. 111 + if (!$out) { 112 + $out[] = array( 113 + 'style' => 'color: #888888;', 114 + 'render' => pht('(Empty.)'), 115 + ); 116 + } 117 + 118 + $render = array(); 119 + foreach ($out as $line) { 120 + $style = $line['style']; 121 + $style = "padding: 0 8px; margin: 0 4px; {$style}"; 122 + 123 + $render[] = phutil_tag( 124 + 'div', 125 + array( 126 + 'style' => $style, 127 + ), 128 + $line['render']); 129 + } 130 + 90 131 $style_map = id(new PhabricatorDefaultSyntaxStyle()) 91 132 ->getRemarkupStyleMap(); 92 133 93 134 $styled_body = id(new PhutilPygmentizeParser()) 94 135 ->setMap($style_map) 95 - ->parse((string)hsprintf('%s', $out)); 136 + ->parse((string)hsprintf('%s', $render)); 96 137 97 138 return phutil_safe_html($styled_body); 98 139 }