mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-02-24 23:08:08 +08:00
Improved cleanHtml() and cleanCSS() handling
This commit is contained in:
parent
1506a158f4
commit
3b7deb1328
1 changed files with 22 additions and 19 deletions
|
@ -14,6 +14,14 @@ const
|
||||||
"'": '''
|
"'": '''
|
||||||
},
|
},
|
||||||
|
|
||||||
|
disallowedTags = [
|
||||||
|
'svg','script','title','link','base','meta',
|
||||||
|
'input','output','select','button','textarea',
|
||||||
|
'bgsound','keygen','source','object','embed','applet','iframe','frame','frameset','video','audio','area','map'
|
||||||
|
// not supported by <template> element
|
||||||
|
// ,'html','head','body'
|
||||||
|
].join(','),
|
||||||
|
|
||||||
blockquoteSwitcher = () => {
|
blockquoteSwitcher = () => {
|
||||||
SettingsUserStore.collapseBlockquotes() &&
|
SettingsUserStore.collapseBlockquotes() &&
|
||||||
// tpl.content.querySelectorAll('blockquote').forEach(node => {
|
// tpl.content.querySelectorAll('blockquote').forEach(node => {
|
||||||
|
@ -90,6 +98,12 @@ const
|
||||||
return url;
|
return url;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
cleanCSS = source =>
|
||||||
|
source.trim().replace(/-(ms|webkit)-[^;]+(;|$)/g, '')
|
||||||
|
// Drop Microsoft Office style properties
|
||||||
|
// .replace(/mso-[^:;]+:[^;]+/gi, '')
|
||||||
|
,
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Parses given css string, and returns css object
|
Parses given css string, and returns css object
|
||||||
keys as selectors and values are css rules
|
keys as selectors and values are css rules
|
||||||
|
@ -161,7 +175,7 @@ const
|
||||||
// we have standard css
|
// we have standard css
|
||||||
css.push({
|
css.push({
|
||||||
selector: selector,
|
selector: selector,
|
||||||
rules: arr[6]
|
rules: cleanCSS(arr[6])
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -239,13 +253,6 @@ export const
|
||||||
// td
|
// td
|
||||||
'colspan', 'rowspan', 'headers'
|
'colspan', 'rowspan', 'headers'
|
||||||
],
|
],
|
||||||
disallowedTags = [
|
|
||||||
'SCRIPT','TITLE','LINK','BASE','META',
|
|
||||||
'INPUT','OUTPUT','SELECT','BUTTON','TEXTAREA',
|
|
||||||
'BGSOUND','KEYGEN','SOURCE','OBJECT','EMBED','APPLET','IFRAME','FRAME','FRAMESET','VIDEO','AUDIO','AREA','MAP'
|
|
||||||
// Not supported by <template> element
|
|
||||||
// ,'HTML','HEAD','BODY'
|
|
||||||
],
|
|
||||||
nonEmptyTags = [
|
nonEmptyTags = [
|
||||||
'A','B','EM','I','SPAN','STRONG'
|
'A','B','EM','I','SPAN','STRONG'
|
||||||
];
|
];
|
||||||
|
@ -279,14 +286,12 @@ export const
|
||||||
nodeIterator.referenceNode.remove();
|
nodeIterator.referenceNode.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/the-djmaze/snappymail/issues/972
|
tpl.content.querySelectorAll(
|
||||||
tpl.content.querySelectorAll('SVG').forEach(oElement => oElement.remove());
|
disallowedTags
|
||||||
|
+ (0 < bqLevel ? ',' + (new Array(1 + bqLevel).fill('blockquote').join(' ')) : '')
|
||||||
|
).forEach(oElement => oElement.remove());
|
||||||
|
|
||||||
if (0 < bqLevel) {
|
[...tpl.content.querySelectorAll('*')].forEach(oElement => {
|
||||||
tpl.content.querySelectorAll(new Array(1 + bqLevel).fill('blockquote').join(' ')).forEach(node => node.remove());
|
|
||||||
}
|
|
||||||
|
|
||||||
tpl.content.querySelectorAll('*').forEach(oElement => {
|
|
||||||
const name = oElement.tagName,
|
const name = oElement.tagName,
|
||||||
oStyle = oElement.style;
|
oStyle = oElement.style;
|
||||||
|
|
||||||
|
@ -306,8 +311,7 @@ export const
|
||||||
}
|
}
|
||||||
|
|
||||||
// \MailSo\Base\HtmlUtils::ClearTags()
|
// \MailSo\Base\HtmlUtils::ClearTags()
|
||||||
if (disallowedTags.includes(name)
|
if ('none' == oStyle.display
|
||||||
|| 'none' == oStyle.display
|
|
||||||
|| 'hidden' == oStyle.visibility
|
|| 'hidden' == oStyle.visibility
|
||||||
// || (oStyle.lineHeight && 1 > parseFloat(oStyle.lineHeight)
|
// || (oStyle.lineHeight && 1 > parseFloat(oStyle.lineHeight)
|
||||||
// || (oStyle.maxHeight && 1 > parseFloat(oStyle.maxHeight)
|
// || (oStyle.maxHeight && 1 > parseFloat(oStyle.maxHeight)
|
||||||
|
@ -543,8 +547,7 @@ export const
|
||||||
oStyle.removeProperty('color');
|
oStyle.removeProperty('color');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Drop Microsoft Office style properties
|
oStyle.cssText = cleanCSS(oStyle.cssText);
|
||||||
// oStyle.cssText = oStyle.cssText.replace(/mso-[^:;]+:[^;]+/gi, '');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug && aAttrsForRemove.length) {
|
if (debug && aAttrsForRemove.length) {
|
||||||
|
|
Loading…
Reference in a new issue