diff --git a/index.js b/index.js index 77ea6b8..23592e0 100644 --- a/index.js +++ b/index.js @@ -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, diff --git a/lib/inline-css.js b/lib/inline-css.js index 259bbd7..d478929 100644 --- a/lib/inline-css.js +++ b/lib/inline-css.js @@ -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'); @@ -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, $); } diff --git a/lib/setCenterAttrs.js b/lib/setCenterAttrs.js new file mode 100644 index 0000000..b55defd --- /dev/null +++ b/lib/setCenterAttrs.js @@ -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 = $('