$(function() {
$('#btnGenerateHtmlMail').click(function(ev) {
var $report = $('#report');
convertCssToInlineStyle($report);
var reportHtml = $report.html();
reportHtml = reportHtml
/* remove class attribute */
.replace(/class=('|").*?\1/g, "")
/* remove id attribute */
.replace(/id=('|").*?\1/g, "")
/* remove tab, enter and whitespace */
.replace(/\s\s+/g, ' ');
// --> chamada ao metódo de @ctgPi
var buffer = document.createElement('div');
buffer.innerHTML = reportHtml;
cleanHTMLForEMail(buffer);
$('#result').text(buffer.innerHTML);
});
});
// metódo da solução do @ctgPi (http://pt.stackoverflow.com/a/68936/2998)
var attributeWhiteList = ['style']; // atributos que você quer deixar
var elementWhiteList = ['#text', 'TABLE', 'THEAD', 'TBODY', 'TFOOT', 'TR', 'TH', 'TD', 'P', 'B', 'DIV']; // elementos que você quer deixar
function cleanHTMLForEMail(node) {
if (node.nodeName === '#text') {
// aqui você editar node.textContent pra tirar espaço em branco
return node;
}
// listar atributos
var attributeNames = [];
for (var i = 0; i < node.attributes.length; i++) {
attributeNames.push(node.attributes[i].name);
}
// tirar todos os atributos fora da whitelist
for (var i = 0; i < attributeNames.length; i++) {
if (attributeWhiteList.indexOf(attributeNames[i]) === -1) {
node.removeAttribute(attributeNames[i]);
}
}
// listar filhos
var children = [];
for (var i = 0; i < node.childNodes.length; i++) {
children.push(node.childNodes[i]);
}
// tirar todos os filhos fora da whitelist
// e limpar os que estão dentro
for (var i = 0; i < children.length; i++) {
if (elementWhiteList.indexOf(children[i].nodeName) === -1) {
node.removeChild(children[i]);
} else if...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.