Better HTML email monospace font-size normalization

The default styles of some browsers reduce the font-size of elements
with monospace fonts. Previously, this was normalized by setting the
font-size of monospaced elements in HTML emails. However, this approach
does not always result in consistent font sizes because the normal font
size is not known in general (without artificially fixing it). Instead,
abstract creation of PRE blocks into a callable private template and set
the font-family in a way that is not matched by the default styles.

Bug: Issue 4817
Change-Id: I4243a202eda471edaf420d9dc1186c4ed8484c9d
This commit is contained in:
Wyatt Allen
2016-10-26 14:54:44 -07:00
parent a2cca5be9f
commit 076363c1fd
11 changed files with 40 additions and 32 deletions

View File

@@ -58,6 +58,7 @@ public class MailSoyTofuProvider implements Provider<SoyTofu> {
"MergedHtml.soy",
"NewChange.soy",
"NewChangeHtml.soy",
"Private.soy",
"RegisterNewEmail.soy",
"ReplacePatchSet.soy",
"ReplacePatchSetHtml.soy",
@@ -65,7 +66,6 @@ public class MailSoyTofuProvider implements Provider<SoyTofu> {
"RestoredHtml.soy",
"Reverted.soy",
"RevertedHtml.soy",
"ViewChangeButton.soy",
};
private final SitePaths site;

View File

@@ -35,6 +35,6 @@
{/if}
{if $coverLetter}
<pre style="font-size:12px">{$coverLetter}</pre>
{call .Pre}{param content: $coverLetter /}{/call}
{/if}
{/template}

View File

@@ -54,7 +54,7 @@
{/if}
{if $coverLetter}
<pre style="font-size:12px">{$coverLetter}</pre>
{call .Pre}{param content: $coverLetter /}{/call}
{/if}
<ul style="{$ulStyle}">
@@ -89,18 +89,20 @@
</a>{sp}
{/if}
{if length($comment.lines) == 1}
<code style="font-size:12px">{$comment.lines[0]}</code>
<code style="font-family:monospace,monospace">
{$comment.lines[0]}
</code>
{/if}
</p>
{if length($comment.lines) > 1}
<p>
<blockquote style="{$blockquoteStyle}">
<pre style="font-size:12px">
{call .Pre}{param content kind="html"}
{foreach $line in $comment.lines}
{$line}{\n}
{/foreach}
</pre>
{/param}{/call}
</blockquote>
</p>
{/if}

View File

@@ -39,6 +39,6 @@
{/if}
{if $coverLetter}
<pre style="font-size:12px">{$coverLetter}</pre>
{call .Pre}{param content: $coverLetter /}{/call}
{/if}
{/template}

View File

@@ -35,6 +35,6 @@
{/if}
{if $coverLetter}
<pre style="font-size:12px">{$coverLetter}</pre>
{call .Pre}{param content: $coverLetter /}{/call}
{/if}
{/template}

View File

@@ -32,17 +32,11 @@
</p>
{/if}
<pre style="font-size:12px">
{$email.changeDetail}
</pre>
{call .Pre}{param content: $email.changeDetail /}{/call}
<pre style="font-size:12px">
{$email.approvals}
</pre>
{call .Pre}{param content: $email.approvals /}{/call}
{if $email.includeDiff}
<pre style="font-size:12px">
{$email.unifiedDiff}
</pre>
{call .Pre}{param content: $email.unifiedDiff /}{/call}
{/if}
{/template}

View File

@@ -46,20 +46,16 @@
</p>
{/if}
<pre style="font-size:12px">
{$email.changeDetail}
</pre>
{call .Pre}{param content: $email.changeDetail /}{/call}
{if $email.sshHost}
<pre style="font-size:12px">
{call .Pre}{param content kind="html"}
git pull ssh:{print '//'}{$email.sshHost}/{$projectName}
{sp}{$patchSet.refName}
</pre>
{/param}{/call}
{/if}
{if $email.includeDiff}
<pre style="font-size:12px">
{$email.unifiedDiff}
</pre>
{call .Pre}{param content: $email.unifiedDiff /}{/call}
{/if}
{/template}

View File

@@ -16,6 +16,10 @@
{namespace com.google.gerrit.server.mail.template}
/*
* Private templates that cannot be overridden.
*/
/**
* Private template to generate "View Change" buttons.
* @param email
@@ -32,3 +36,17 @@
{/let}
<a style="{$visitButtonStyle}" href="{$email.changeUrl}">View Change</a>
{/template}
/**
* Private template to render PRE block with consistent font-sizing.
* @param content
*/
{template .Pre private="true" autoescape="strict" kind="html"}
{let $preStyle kind="css"}
font-family: monospace,monospace; // Use this to avoid browsers scaling down
// monospace text.
white-space: pre-wrap;
{/let}
<pre style="{$preStyle}">{$content}</pre>
{/template}

View File

@@ -36,14 +36,12 @@
</p>
{/if}
<pre style="font-size:12px">
{$email.changeDetail}
</pre>
{call .Pre}{param content: $email.changeDetail /}{/call}
{if $email.sshHost}
<pre style="font-size:12px">
{call .Pre}{param content kind="html"}
git pull ssh:{print '//'}{$email.sshHost}/{$projectName}{sp}
{$patchSet.refName}
</pre>
{/param}{/call}
{/if}
{/template}

View File

@@ -35,6 +35,6 @@
{/if}
{if $coverLetter}
<pre style="font-size:12px">{$coverLetter}</pre>
{call .Pre}{param content: $coverLetter /}{/call}
{/if}
{/template}

View File

@@ -35,6 +35,6 @@
{/if}
{if $coverLetter}
<pre style="font-size:12px">{$coverLetter}</pre>
{call .Pre}{param content: $coverLetter /}{/call}
{/if}
{/template}