mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-01-07 15:27:43 +08:00
Speedup cleanHtml() parser
This commit is contained in:
parent
a1441c9f22
commit
7aa5142047
1 changed files with 9 additions and 9 deletions
|
@ -103,6 +103,7 @@ export const
|
|||
* @returns {string}
|
||||
*/
|
||||
cleanHtml = (html, oAttachments) => {
|
||||
let aColor;
|
||||
const
|
||||
debug = false, // Config()->Get('debug', 'enable', false);
|
||||
detectHiddenImages = true, // !!SettingsGet('try_to_detect_hidden_images'),
|
||||
|
@ -121,11 +122,7 @@ export const
|
|||
|
||||
// convert body attributes to CSS
|
||||
tasks = {
|
||||
link: value => {
|
||||
if (/^#[a-fA-Z0-9]{3,6}$/.test(value)) {
|
||||
tpl.content.querySelectorAll('a').forEach(node => node.style.color || (node.style.color = value))
|
||||
}
|
||||
},
|
||||
link: value => aColor = value,
|
||||
text: (value, node) => node.style.color = value,
|
||||
topmargin: (value, node) => node.style.marginTop = pInt(value) + 'px',
|
||||
leftmargin: (value, node) => node.style.marginLeft = pInt(value) + 'px',
|
||||
|
@ -162,9 +159,11 @@ export const
|
|||
'colspan', 'rowspan', 'headers'
|
||||
],
|
||||
disallowedTags = [
|
||||
'HEAD','STYLE','SVG','SCRIPT','TITLE','LINK','BASE','META',
|
||||
'STYLE','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'
|
||||
],
|
||||
nonEmptyTags = [
|
||||
'A','B','EM','I','SPAN','STRONG'
|
||||
|
@ -172,11 +171,11 @@ export const
|
|||
|
||||
tpl.innerHTML = html
|
||||
// .replace(/<pre[^>]*>[\s\S]*?<\/pre>/gi, pre => pre.replace(/\n/g, '\n<br>'))
|
||||
.replace(/<!doctype[^>]*>/gi, '')
|
||||
.replace(/<\?xml[^>]*\?>/gi, '')
|
||||
// Not supported by <template> element
|
||||
// .replace(/<!doctype[^>]*>/gi, '')
|
||||
// .replace(/<\?xml[^>]*\?>/gi, '')
|
||||
.replace(/<(\/?)body(\s[^>]*)?>/gi, '<$1div class="mail-body"$2>')
|
||||
.replace(/<\/?(html|head)[^>]*>/gi, '')
|
||||
// .replace(/<\/?(html|head)[^>]*>/gi, '')
|
||||
// Fix Reddit https://github.com/the-djmaze/snappymail/issues/540
|
||||
.replace(/<span class="preview-text"[\s\S]+?<\/span>/, '')
|
||||
// https://github.com/the-djmaze/snappymail/issues/900
|
||||
|
@ -287,6 +286,7 @@ export const
|
|||
// setAttribute('rel', 'external nofollow noopener noreferrer');
|
||||
}
|
||||
setAttribute('tabindex', '-1');
|
||||
aColor && !oElement.style.color && (oElement.style.color = aColor);
|
||||
}
|
||||
|
||||
// if (['CENTER','FORM'].includes(name)) {
|
||||
|
|
Loading…
Reference in a new issue