Skip to content

Commit 5386203

Browse files
committed
fix(mailer): <b> and <strong> on icloud web and thunderbird
1 parent 169dbdf commit 5386203

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

src/assets/emails/genericTemplate.html

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
color: #fff !important;
5454
font-weight: 700 !important;
5555
}
56-
td strong {
56+
td strong,
57+
td b {
5758
font-weight: 700 !important;
5859
color: #9D6FF3 !important;
5960
}
@@ -113,14 +114,10 @@
113114
}
114115
}
115116

116-
td.primary a,
117-
td.secondary a,
118-
td.primary span,
119-
td.secondary span,
120-
u+.email-body td.primary a,
121-
u+.email-body td.secondary a,
122-
u+.email-body td.primary span,
123-
u+.email-body td.secondary span {
117+
td.button a,
118+
td.button span,
119+
u+.email-body td.button a,
120+
u+.email-body td.button span {
124121
text-decoration: none !important;
125122
}
126123

src/mailer.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,20 @@ export class CreateEmail {
113113
});
114114
}
115115

116+
// wrap <b> and <strong> in a <span> element, to fix color on thunderbird and weight on icloud mail web
117+
const bRegex = /<b ?>.*?<\/b>|<strong ?>.*?<\/strong>/g;
118+
119+
if (!plainText) {
120+
c.text = c.text.replace(bRegex, el => `<span style="color:#fff;font-weight:bold;">${el}</span>`);
121+
}
122+
116123
// replace [links](https://example.com) with html anchor tags or a plaintext representation
117124
const linkRegex = /\[(?<linkText>.*?)\]\((?<linkAddress>.*?)\)/g;
118125

119-
if (linkRegex.test(c.text)) {
120-
if (plainText) {
121-
c.text = c.text.replace(linkRegex, '$<linkText> ($<linkAddress>)');
122-
} else {
123-
c.text = c.text.replace(linkRegex, '<a href="$<linkAddress>" style="text-decoration:underline;font-weight:700;color:#fff;"><u>$<linkText></u></a>');
124-
}
126+
if (plainText) {
127+
c.text = c.text.replace(linkRegex, '$<linkText> ($<linkAddress>)');
128+
} else {
129+
c.text = c.text.replace(linkRegex, '<a href="$<linkAddress>" style="text-decoration:underline;font-weight:700;color:#fff;"><u>$<linkText></u></a>');
125130
}
126131
}
127132

@@ -159,7 +164,7 @@ export class CreateEmail {
159164
} else {
160165
el = `<span style="color:#fff;" width="100%">${el}</span>`;
161166
}
162-
innerHTML += `\n<tr><td ${c.primary ? 'class="primary" bgcolor="#673db6"' : 'class="secondary" bgcolor="#373C65"'} style="font-weight:700;border-radius:10px;padding:12px" align="center">${el}</td></tr>`;
167+
innerHTML += `\n<tr><td ${c.primary ? 'class="primary button" bgcolor="#673db6"' : 'class="secondary button" bgcolor="#373C65"'} style="font-weight:700;border-radius:10px;padding:12px" align="center">${el}</td></tr>`;
163168
break;
164169
}
165170
});

0 commit comments

Comments
 (0)