├── .cupboard
├── .gitignore
├── .npmignore
├── .travis.yml
├── LICENSE.txt
├── README.md
├── bin
└── emailify
├── examples
└── test-1
│ ├── index.html
│ └── index.out.html
├── lib
├── eachCssRule.js
├── index.js
├── jquery-1.5.js
└── test
│ ├── compatibility
│ ├── test-android.js
│ ├── test-apple-mail-4.js
│ ├── test-gmail.js
│ ├── test-hotmail.js
│ ├── test-iphone-ipad.js
│ ├── test-outlook-2003.js
│ ├── test-outlook-2010-2010.js
│ └── test-yahoo-mail.js
│ ├── index.js
│ ├── selectors
│ └── test-selectors.js
│ └── suite.js
├── makefile
├── package.json
├── project.sublime-project
└── project.sublime-workspace
/.cupboard:
--------------------------------------------------------------------------------
1 | [commands]
2 | proj = subl --project project.sublime-project
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | .DS_Store
3 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | .DS_Store
3 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - 0.6
4 | - 0.8
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | MIT License
2 | Copyright (c) 2012 Craig Condon
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
5 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### This library is not actively maintained.
2 |
3 | [](http://travis-ci.org/crcn/emailify)
4 | ### Emailify makes your html documents a bit more email-safe
5 |
6 | This is the node.js version of [premailer](http://premailer.dialect.ca/).
7 |
8 | ### Features
9 |
10 | - Copies ``, and ` ` data to associated elements.
11 | - Strips out comments by default, but you can optionally keep them, this is useful if you intend to use VML to provide background-images.
12 | - HTML compatibility checking for popular email clients. See:
13 | - http://www.campaignmonitor.com/css/
14 | - http://www.campaignmonitor.com/downloads/documents-tools/campaign-monitor-guide-to-css-in-email-sept-2011.pdf
15 | - http://www.email-standards.org/
16 |
17 | ### HTML Example
18 |
19 | Turns this:
20 |
21 | ```html
22 |
23 |
24 |
29 |
30 |
31 | orange header
32 |
33 |
34 | ```
35 |
36 | Into this:
37 |
38 | ```html
39 |
40 |
41 |
42 |
43 | orange header
44 |
45 |
46 | ```
47 |
48 | ### Testing Compatibility Screenshot
49 |
50 | 
51 |
52 | ### Requirements
53 |
54 | - [Node.js](http://nodejs.org/)
55 |
56 | ### Installation
57 |
58 | ```
59 | npm install emailify -g
60 | ```
61 |
62 |
63 | ### Command Line
64 |
65 | #### Usage
66 |
67 | ```
68 | -i [input_html] -o [output_html]
69 |
70 | Options:
71 | -i, --input [required]
72 | -o, --output
73 | -t, --test [default: false]
74 | -c, --comments [default: false]
75 | ```
76 |
77 | To emailify a document, use this command:
78 |
79 | ```bash
80 | emailify -i /my/html/file.html -o /my/html/emailified.html
81 | ```
82 | If you intend to keep comments, do the following:
83 |
84 | ```bash
85 | emailify -c true -i /my/html/file.html -o /my/html/emailified.html
86 | ```
87 |
88 | You can easily test a document for compatibility by adding the `-t` flag:
89 |
90 | ```bash
91 | emailify -i /my/html/file.html -o /my/html/emailified.html -t
92 | ```
93 |
94 | Ommit `-o` if you just want to see what emailify produces:
95 |
96 | ```bash
97 | emailify -i /my/html/file.html
98 | ```
99 |
100 |
101 |
102 |
103 |
104 | ### Node.js API
105 |
106 | #### .parse(content[, options], callback)
107 |
108 | parses html content into email-safe html
109 |
110 | - `content` - the html content
111 | - `options`
112 | - `test` - runs test against code for compatibility
113 |
114 |
115 | ```javascript
116 | var emailify = require('emailify'),
117 | fs = require('fs')
118 |
119 | emailify.parse(fs.readFileSync('/my/email/newsletter.html', 'utf8'), function(err, content) {
120 | //send newsletter
121 | });
122 | ```
123 |
124 | #### .load(file[, options], callback)
125 |
126 |
127 | loads a html file
128 |
129 | ```javascript
130 | var emailify = require('emailify'),
131 | fs = require('fs')
132 |
133 | emailify.load('/my/email/newsletter.html', { test: true }, function(err, content, warnings) {
134 | //send newsletter
135 | });
136 | ```
137 |
138 |
139 |
140 |
141 |
--------------------------------------------------------------------------------
/bin/emailify:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | var argv = require('optimist').
4 | usage('-i [input_html] -o [output_html]').
5 | demand('i').
6 | default('o').
7 | default('t', false).
8 | default('c', false).
9 | alias('i','input').
10 | alias('o','output').
11 | alias('t','test').
12 | alias('c','comments').
13 | argv;
14 |
15 |
16 |
17 | var fs = require('fs'),
18 | emailify = require('../'),
19 | outcome = require('outcome');
20 |
21 | /**
22 | */
23 |
24 | function fixFile(file) {
25 | return file.replace(/^\.\//,process.cwd() + '/').replace(/^\~/,process.env.HOME);
26 |
27 | }
28 |
29 | /**
30 | */
31 |
32 | var on = outcome.error(function(err) {
33 |
34 | console.error(err);
35 |
36 | });
37 |
38 | /**
39 | */
40 |
41 |
42 | emailify.load(fixFile(argv.i), { test: argv.t , comments: argv.c }, on.success(function(content, warnings) {
43 |
44 | if(argv.o) {
45 |
46 | fs.writeFile(fixFile(argv.o), content, on);
47 |
48 | } else
49 | if(!argv.t) {
50 |
51 | console.log(content);
52 | }
53 |
54 | printWarnings(warnings);
55 |
56 | }));
57 |
58 |
59 | /**
60 | */
61 |
62 | function printWarnings(warnings) {
63 |
64 | if(!warnings.length) return;
65 |
66 | var toPrint = [];
67 |
68 | for(var i = warnings.length; i--;) {
69 | var warning = warnings[i];
70 |
71 | toPrint.push({
72 | type: warning.type,
73 | platforms: warning.platforms.join("\n "),
74 | value: warning.value
75 | });
76 | }
77 |
78 |
79 | console.log('\n');
80 | console.log(' Unsupported Clients'.bold);
81 |
82 |
83 | console.log(toPrint);
84 | console.log('\n');
85 | }
86 |
--------------------------------------------------------------------------------
/examples/test-1/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
14 |
15 |
16 | orange header
17 |
18 |
--------------------------------------------------------------------------------
/examples/test-1/index.out.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | orange header
7 |
8 |
--------------------------------------------------------------------------------
/lib/eachCssRule.js:
--------------------------------------------------------------------------------
1 | module.exports = function(topic, callback) {
2 |
3 | topic.$('link, style').each(function(index, element) {
4 |
5 | element.sheet.cssRules.forEach(callback)
6 |
7 | });
8 |
9 | };
--------------------------------------------------------------------------------
/lib/index.js:
--------------------------------------------------------------------------------
1 | var fs = require('fs'),
2 | jsdom = require('jsdom'),
3 | outcome = require('outcome'),
4 | test = require('./test'),
5 | step = require('step'),
6 | eachCssRule = require('./eachCssRule');
7 |
8 | function _copyStyles(window) {
9 |
10 | eachCssRule(window, function(rule) {
11 | try {
12 | window.$(rule.selectorText).each(function(index, element) {
13 |
14 | element.style.cssText += rule.style.cssText;
15 | element.cssText = element.style.cssText;
16 |
17 | });
18 | } catch(e) {
19 |
20 | }
21 |
22 | });
23 |
24 | }
25 |
26 | /**
27 | * parses content into email-safe HTML
28 | */
29 |
30 | function _parse(content, options, callback) {
31 |
32 | if(typeof options == 'function') {
33 |
34 | callback = options;
35 | options.test = false;
36 |
37 | }
38 |
39 |
40 | var on = outcome.error(callback),
41 | warnings,
42 | window;
43 |
44 | step(
45 |
46 | /**
47 | * load it.
48 | */
49 |
50 | function() {
51 |
52 | jsdom.env({
53 | html: content,
54 | scripts: [
55 | __dirname + "/jquery-1.5.js"
56 | ],
57 | done: this
58 | });
59 |
60 | },
61 |
62 |
63 | /**
64 | * set it.
65 | */
66 |
67 | on.success(function(win) {
68 |
69 |
70 | window = win;
71 | _copyStyles(window);
72 | this();
73 |
74 | }),
75 |
76 | /**
77 | * test it.
78 | */
79 |
80 | on.success(function() {
81 |
82 | if(!options.test) {
83 |
84 | return this();
85 |
86 | }
87 |
88 | test(window, {}, this);
89 |
90 | }),
91 |
92 | /**
93 | * clean it.
94 | */
95 |
96 | on.success(function(warn) {
97 |
98 | warnings = warn;
99 |
100 | //strip stuff that cannot be processed
101 | window.$('script, link, style').remove();
102 |
103 | if (!options.comments) {
104 | //strip comments - sometimes gets rendered
105 | window.$('*').contents().each(function(node) {
106 | if(this.nodeType == 8) {
107 | window.$(this).remove();
108 | }
109 | });
110 | }
111 |
112 | this();
113 |
114 | }),
115 |
116 |
117 | /**
118 | * finish it.
119 | */
120 |
121 | function() {
122 |
123 | callback(null, window.document.documentElement.innerHTML, warnings || []);
124 |
125 | }
126 | );
127 |
128 |
129 | }
130 |
131 | /**
132 | */
133 |
134 | function _load(file, options, callback) {
135 |
136 | if(typeof options == 'function') {
137 |
138 | callback = options;
139 | options = {};
140 |
141 | }
142 |
143 | fs.readFile(file, "utf8", outcome.error(callback).success(function(content) {
144 |
145 | _parse(content, options, callback);
146 |
147 | }));
148 |
149 | }
150 |
151 | exports.parse = _parse;
152 | exports.load = _load;
153 |
--------------------------------------------------------------------------------
/lib/test/compatibility/test-android.js:
--------------------------------------------------------------------------------
1 | var assert = require('assert');
2 |
3 | module.exports = {
4 |
5 | 'name':'Android',
6 | 'test': {
7 |
8 | 'style': [
9 |
10 | //TEXT
11 | 'word-wrap',
12 |
13 | //BG
14 | 'background-image',
15 | 'background-position',
16 | 'background-repeat',
17 | 'opacity',
18 |
19 | //BOX
20 | 'box-shadow',
21 |
22 | //POSITION
23 | 'bottom',
24 | 'clip',
25 | 'cursor',
26 | 'display',
27 | 'left',
28 | 'opacity',
29 | 'outline',
30 | 'overflow',
31 | 'position',
32 | 'resize',
33 | 'right',
34 | 'top',
35 | 'visibility',
36 |
37 | //LISTS
38 | 'list-style-image',
39 | 'list-style-position',
40 | 'list-style-type',
41 |
42 | //TABLE
43 | 'border-spacing',
44 | 'caption-side',
45 | 'empty-cells']
46 |
47 | }
48 |
49 | };
--------------------------------------------------------------------------------
/lib/test/compatibility/test-apple-mail-4.js:
--------------------------------------------------------------------------------
1 | var assert = require('assert');
2 |
3 | module.exports = {
4 |
5 | 'name': 'Apple Mail 4',
6 | 'test': {
7 |
8 | 'style': [
9 |
10 | //BOX
11 | 'box-shadow',
12 |
13 | 'caption-side']
14 |
15 | }
16 |
17 | };
--------------------------------------------------------------------------------
/lib/test/compatibility/test-gmail.js:
--------------------------------------------------------------------------------
1 | var assert = require('assert');
2 |
3 | module.exports = {
4 |
5 | 'name': 'GMail',
6 | 'test': {
7 |
8 | 'style': [
9 |
10 |
11 | //TEXT
12 | 'word-wrap',
13 |
14 | //BG
15 | 'background-position',
16 | 'background-repeat',
17 | 'opacity',
18 |
19 | //BOX
20 | 'box-shadow',
21 |
22 | //POSITION
23 | 'bottom',
24 | 'clip',
25 | 'cursor',
26 | 'display',
27 | 'left',
28 | 'opacity',
29 | 'outline',
30 | 'overflow',
31 | 'position',
32 | 'resize',
33 | 'right',
34 | 'top',
35 | 'visibility',
36 |
37 | //LISTS
38 | 'list-style-image',
39 | 'list-style-position',
40 |
41 | //TABLE
42 | 'border-spacing',
43 | 'caption-side',
44 | 'empty-cells']
45 |
46 | }
47 |
48 | };
--------------------------------------------------------------------------------
/lib/test/compatibility/test-hotmail.js:
--------------------------------------------------------------------------------
1 | var assert = require('assert');
2 |
3 | module.exports = {
4 |
5 | 'name': 'Hotmail',
6 | 'test': {
7 |
8 | 'style': [
9 |
10 | //BG
11 | 'background-image',
12 | 'background-position',
13 | 'background-repeat',
14 |
15 | //BOX
16 | 'max-width',
17 | 'max-height',
18 |
19 | //POSITION
20 | 'clip',
21 | 'left',
22 | 'z-index',
23 |
24 | //LISTS
25 | 'list-style-image',
26 | 'list-style-position']
27 |
28 | }
29 |
30 | };
31 |
--------------------------------------------------------------------------------
/lib/test/compatibility/test-iphone-ipad.js:
--------------------------------------------------------------------------------
1 | var assert = require('assert');
2 |
3 | module.exports = {
4 |
5 | 'name': 'Apple iPhone/iPad',
6 | 'test': {
7 |
8 | 'style': [
9 |
10 | //BOX
11 | 'box-shadow',
12 |
13 | //TABLE
14 | 'caption-side']
15 |
16 | }
17 | };
--------------------------------------------------------------------------------
/lib/test/compatibility/test-outlook-2003.js:
--------------------------------------------------------------------------------
1 | var assert = require('assert');
2 |
3 | module.exports = {
4 | 'name': 'Outlook Express 2000/2003',
5 | 'test': {
6 |
7 | 'style': [
8 |
9 | //TEXT
10 | 'text-shadow',
11 | 'white-space',
12 | 'word-wrap',
13 |
14 | //BG
15 | 'opacity',
16 |
17 | //BOX
18 | 'box-shadow',
19 | 'max-width',
20 | 'max-height',
21 |
22 | //POSITION
23 | 'opacity',
24 | 'outline',
25 |
26 | //TABLE
27 | 'border-spacing',
28 | 'caption-side',
29 | 'empty-cells']
30 |
31 | }
32 |
33 | };
--------------------------------------------------------------------------------
/lib/test/compatibility/test-outlook-2010-2010.js:
--------------------------------------------------------------------------------
1 | var assert = require('assert');
2 |
3 | module.exports = {
4 |
5 | 'name': 'Outlook Express 2007/2010',
6 | 'test': {
7 |
8 | 'style': [
9 |
10 |
11 | //TEXT
12 | 'direction',
13 | 'text-overflow',
14 | 'text-shadow',
15 | 'word-spacing',
16 | 'word-wrap',
17 | 'vertical-align',
18 |
19 | //BG
20 | 'background-image',
21 | 'background-position',
22 | 'background-repeat',
23 | 'opacity',
24 |
25 | //BOX
26 | 'box-shadow',
27 | 'height',
28 | 'max-width',
29 | 'max-height',
30 |
31 | //POSITION
32 | 'bottom',
33 | 'clear',
34 | 'clip',
35 | 'cursor',
36 | 'display',
37 | 'float',
38 | 'left',
39 | 'opacity',
40 | 'outline',
41 | 'overflow',
42 | 'position',
43 | 'resize',
44 | 'right',
45 | 'top',
46 | 'visibility',
47 |
48 | //LISTS
49 | 'list-style-image',
50 | 'list-style-position',
51 | 'list-style-type',
52 |
53 | //TABLE
54 | 'border-spacing',
55 | 'caption-side',
56 | 'empty-cells']
57 |
58 | }
59 |
60 | };
--------------------------------------------------------------------------------
/lib/test/compatibility/test-yahoo-mail.js:
--------------------------------------------------------------------------------
1 | var assert = require('assert');
2 |
3 | module.exports = {
4 |
5 | 'name': 'Yahoo! Mail',
6 |
7 | 'test': {
8 |
9 | 'style': [
10 |
11 | //BG
12 | 'background-image',
13 | 'background-position',
14 | 'background-repeat',
15 | 'opacity',
16 |
17 | //BOX
18 | 'box-shadow',
19 |
20 | //POSITION
21 | 'bottom',
22 | 'clip',
23 | 'opacity',
24 | 'outline',
25 | 'overflow',
26 | 'position',
27 | 'resize',
28 | 'right',
29 | 'top',
30 | 'z-index']
31 |
32 | }
33 |
34 | };
--------------------------------------------------------------------------------
/lib/test/index.js:
--------------------------------------------------------------------------------
1 |
2 |
3 | var plugin = require('plugin'),
4 | loader = plugin.loader(),
5 | suite = require('./suite');
6 |
7 | require('colors');
8 |
9 | module.exports = function(window, options, callback) {
10 |
11 | var subject = suite(window);
12 | try {
13 |
14 | loader.
15 | factory(function(plugin) {
16 |
17 | var module;
18 |
19 | if(typeof plugin.plugin == 'function') {
20 |
21 | module = plugin.plugin(window);
22 |
23 | } else {
24 |
25 | module = plugin;
26 |
27 | }
28 |
29 |
30 |
31 | subject.add(module);
32 |
33 | }).
34 | require(__dirname + "/selectors/**/test").
35 | require(__dirname + "/compatibility/**/test").
36 | load(function() {
37 |
38 | subject.run(callback);
39 |
40 | });
41 | }catch(e) {
42 | console.log(e.stack)
43 | }
44 |
45 | };
46 |
47 |
48 |
--------------------------------------------------------------------------------
/lib/test/selectors/test-selectors.js:
--------------------------------------------------------------------------------
1 | var eachCssRule = require('../../eachCssRule'),
2 | assert = require('assert'),
3 | sprintf = require('sprintf').sprintf
4 |
5 | exports.plugin = function(topic) {
6 |
7 | var batch = [];
8 |
9 | eachCssRule(topic, function(rule) {
10 |
11 | batch.push(rule.selectorText);
12 |
13 | });
14 |
15 |
16 | return {
17 |
18 | 'name': 'all clients',
19 | 'test': {
20 | 'selector': batch
21 | }
22 |
23 | };
24 |
25 | };
--------------------------------------------------------------------------------
/lib/test/suite.js:
--------------------------------------------------------------------------------
1 | var assert = require('assert')
2 |
3 | var _testers = {
4 | 'selector': function(topic, selector) {
5 | var len;
6 |
7 | //don't want jquery to break...
8 | try {
9 |
10 | len = topic.$(selector).length
11 |
12 | } catch(e) {
13 |
14 | len = 1;
15 |
16 | }
17 |
18 |
19 | assert.equal(!!len, true);
20 | },
21 | 'style': function(topic, selector) {
22 | assert.equal(topic.$('*[cssText*="' + selector + ':"]').length, 0);
23 | }
24 | }
25 |
26 |
27 | module.exports = function(topic) {
28 |
29 | var _batches = {};
30 |
31 |
32 | var self = {
33 |
34 | add: function(platform) {
35 |
36 | var name = platform.name,
37 | testBatch = platform.test;
38 |
39 | for(var testType in testBatch) {
40 |
41 | var batch = testBatch[testType];
42 |
43 | if(!_batches[testType]) {
44 | _batches[testType] = {};
45 | }
46 |
47 | for(var i = batch.length; i--;) {
48 |
49 | var test = batch[i];
50 |
51 | if(!_batches[testType][test]) {
52 |
53 | _batches[testType][test] = [];
54 |
55 | }
56 |
57 | _batches[testType][test].push(name);
58 | }
59 |
60 | }
61 |
62 | return self;
63 | },
64 |
65 |
66 | run: function(callback) {
67 |
68 | var incompatible = [];
69 |
70 | for(var type in _batches) {
71 |
72 | var tests = _batches[type],
73 | tester = _testers[type];
74 |
75 |
76 | for(var test in tests) {
77 | try {
78 | tester(topic, test);
79 | } catch(e) {
80 |
81 | incompatible.push({
82 | type: type,
83 | value: test,
84 | platforms: tests[test]
85 | });
86 |
87 | }
88 | }
89 | }
90 |
91 | callback(null, incompatible);
92 | }
93 | }
94 |
95 | return self;
96 | }
--------------------------------------------------------------------------------
/makefile:
--------------------------------------------------------------------------------
1 | all: node web test-1
2 |
3 |
4 | node:
5 | mesh merge node
6 |
7 | web:
8 | mesh make web
9 |
10 |
11 | test-1:
12 | emailify -i ./examples/$@/index.html -o ./examples/$@/index.out.html -t
13 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "author": "Craig Condon",
3 | "name": "emailify",
4 | "description": "Make HTML pages email-safe",
5 | "version": "0.0.3",
6 | "repository": {
7 | "type": "git",
8 | "url": "git://github.com/crcn/emailify.git"
9 | },
10 | "main": "./lib/index.js",
11 | "dependencies": {
12 | "outcome": "0.0.x",
13 | "jsdom": "6.3.x",
14 | "optimist": "0.3.x",
15 | "vows": "0.6.x",
16 | "plugin": "0.0.x",
17 | "step": "0.0.x",
18 | "colors": "0.6.x",
19 | "sprintf": "0.1.x"
20 | },
21 | "devDependencies": {},
22 | "bin": {
23 | "emailify": "./bin/emailify"
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/project.sublime-project:
--------------------------------------------------------------------------------
1 | {
2 | "folders":
3 | [
4 | {
5 | "path": "."
6 | }
7 | ],
8 | "build_systems":
9 | [
10 | {
11 | "name":"cbd make",
12 | "cmd":["cbd","make","emailify"]
13 | },
14 | {
15 | "name":"cbd start",
16 | "cmd":["cbd","start","emailify"]
17 | },
18 | {
19 | "name":"cbd make+start",
20 | "cmd":["cbd","make+start","emailify"]
21 | }
22 | ]
23 | }
--------------------------------------------------------------------------------