mjmlhelper 2.0.9 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/mjmlhelper.js +27 -2
  2. package/package.json +1 -1
package/mjmlhelper.js CHANGED
@@ -84,7 +84,26 @@ class mjmlhelper {
84
84
  data = data.substring(0, pos) + ' body.cred_modal:before { display: none !important; } ' + data.substring(pos);
85
85
  // fix font size 0 problem (https://github.com/vielhuber/mjmlhelper/issues/1)
86
86
  data = data.substring(0, pos) + ' .mce-content-body { font-size: 13px; } ' + data.substring(pos);
87
-
87
+ // fix problem where img sizes get overwritten
88
+ data = data.substring(0, pos) + ' .preserve-cr-full-size { width:100% !important; height:auto !important; } ' + data.substring(pos);
89
+ positions = this.findAllPositions('<img', data);
90
+ shift = 0;
91
+ positions.forEach(positions__value => {
92
+ let begin = positions__value + shift,
93
+ end = data.indexOf('>', begin) + '>'.length,
94
+ tag = data.substring(begin, end);
95
+ if( tag.indexOf('width:100%') > -1 ) {
96
+ if( tag.indexOf('class="') > -1 ) {
97
+ data = data.substring(0, begin) + tag.replace('class="', 'class="preserve-cr-full-size ') + data.substring(end);
98
+ shift += 'class="preserve-cr-full-size '.length - 'class="'.length;
99
+ }
100
+ else {
101
+ data = data.substring(0, begin) + tag.replace('<img ', '<img class="preserve-cr-full-size" ') + data.substring(end);
102
+ shift += '<img class="preserve-cr-full-size" '.length - '<img '.length;
103
+ }
104
+ }
105
+ });
106
+
88
107
  // placeholders
89
108
  data = this.replaceAll(data, '%UNSUBSCRIBE%', '{UNSUBSCRIBE}');
90
109
  data = this.replaceAll(data, '%WEBVERSION%', '{ONLINE_VERSION}');
@@ -110,7 +129,7 @@ class mjmlhelper {
110
129
  positions = this.findAllPositions(' mj-outlook-group-fix', data).concat(
111
130
  this.findAllPositions('mj-hero-content', data).concat(
112
131
  []));
113
- positions.sort();
132
+ positions.sort((a, b) => { return a-b; });
114
133
  shift = 0;
115
134
  positions.forEach(positions__value => {
116
135
  let begin = data.indexOf('>', positions__value + shift) + '>'.length,
@@ -144,6 +163,12 @@ class mjmlhelper {
144
163
  style_tag = '<style type="text/css">',
145
164
  pos = data.indexOf(style_tag) + style_tag.length;
146
165
 
166
+ // mailchimp has problems with external fonts: when embedding google fonts, we get the error
167
+ // "An error occurred parsing your template CSS: Cannot find a CSS file at: https://fonts.googleapis.com/css?family=Tinos:400"
168
+ // see: https://github.com/sendwithus/templates/issues/21
169
+ // we strip out all occurences of @import (<link href="https://fonts.googleapis.com/..."> is still left behind)
170
+ data = data.replace(/@import url\(https:\/\/fonts.googleapis.com.*\);/g, '');
171
+
147
172
  // when replacing images in mailchimp, style="width:" is set to a fixed size. we prevent this with
148
173
  data = data.substring(0, pos) + ' img { max-width:100%; height:auto !important; } ' + data.substring(pos);
149
174
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mjmlhelper",
3
- "version": "2.0.9",
3
+ "version": "2.1.2",
4
4
  "description": "",
5
5
  "main": "mjmlhelper.js",
6
6
  "dependencies": {