Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ module.exports = function (html, options) {
preserveMediaQueries: false,
removeHtmlSelectors: false,
applyWidthAttributes: false,
applyHeightAttributes: false,
applyCenterAttributes: false,
applyTableAttributes: false,
xmlMode: false,
decodeEntities: false,
Expand Down
10 changes: 10 additions & 0 deletions lib/inline-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ var parseCSS = require('css-rules'),
handleRule = require('./handleRule'),
flatten = require('flatten'),
setStyleAttrs = require('./setStyleAttrs'),
setHeightAttrs = require('./setHeightAttrs'),
setWidthAttrs = require('./setWidthAttrs'),
setCenterAttrs = require('./setCenterAttrs'),
removeClassId = require('./removeClassId'),
setTableAttrs = require('./setTableAttrs'),
pick = require('object.pick');
Expand Down Expand Up @@ -60,6 +62,14 @@ module.exports = function (html, css, options) {
setWidthAttrs(el, $);
}

if (opts.applyHeightAttributes) {
setHeightAttrs(el, $);
}

if (opts.applyCenterAttributes) {
setCenterAttrs(el, $);
}

if (opts.removeHtmlSelectors) {
removeClassId(el, $);
}
Expand Down
32 changes: 32 additions & 0 deletions lib/setCenterAttrs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';

var centerElements = [ 'img' ];
var centerContainers = [ 'table' ];

module.exports = function (el, $) {
var i,
wrapper;

if (centerElements.indexOf(el.name) > -1) {
for (i in el.styleProps) {
if (el.styleProps[i].prop === 'margin' && el.styleProps[i].value.match(/auto/)) {
// create wrapper container
wrapper = $('<center>' + $(el).toString() + '</center>');

$(el).replaceWith(wrapper);

return;
}
}
}

if (centerContainers.indexOf(el.name) > -1) {
for (i in el.styleProps) {
if (el.styleProps[i].prop === 'margin' && el.styleProps[i].value.match(/auto/)) {
$(el).attr('align', 'center');

return;
}
}
}
};
19 changes: 19 additions & 0 deletions lib/setHeightAttrs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

var heightElements = [ 'table', 'td', 'img' ];

module.exports = function (el, $) {
var i,
pxHeight;

if (heightElements.indexOf(el.name) > -1) {
for (i in el.styleProps) {
if (el.styleProps[i].prop === 'height' && el.styleProps[i].value.match(/px/)) {
pxHeight = el.styleProps[i].value.replace('px', '');

$(el).attr('height', pxHeight);
return;
}
}
}
};