mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-01-02 21:12:02 +08:00
Resolve #246
This commit is contained in:
parent
2edd55f01f
commit
f2054fde0f
1 changed files with 19 additions and 9 deletions
|
@ -110,16 +110,15 @@ export const
|
||||||
'HEAD','STYLE','SVG','SCRIPT','TITLE','LINK','BASE','META',
|
'HEAD','STYLE','SVG','SCRIPT','TITLE','LINK','BASE','META',
|
||||||
'INPUT','OUTPUT','SELECT','BUTTON','TEXTAREA',
|
'INPUT','OUTPUT','SELECT','BUTTON','TEXTAREA',
|
||||||
'BGSOUND','KEYGEN','SOURCE','OBJECT','EMBED','APPLET','IFRAME','FRAME','FRAMESET','VIDEO','AUDIO','AREA','MAP'
|
'BGSOUND','KEYGEN','SOURCE','OBJECT','EMBED','APPLET','IFRAME','FRAME','FRAMESET','VIDEO','AUDIO','AREA','MAP'
|
||||||
|
],
|
||||||
|
inlineTags = [
|
||||||
|
'A','B','EM','I','SPAN','STRONG','O:P'
|
||||||
];
|
];
|
||||||
|
|
||||||
tpl.innerHTML = html
|
tpl.innerHTML = html
|
||||||
.replace(/(<pre[^>]*>)([\s\S]*?)(<\/pre>)/gi, aMatches => {
|
.replace(/(<pre[^>]*>)([\s\S]*?)(<\/pre>)/gi, aMatches => {
|
||||||
return (aMatches[1] + aMatches[2].trim() + aMatches[3].trim()).replace(/\r?\n/g, '<br>');
|
return (aMatches[1] + aMatches[2].trim() + aMatches[3].trim()).replace(/\r?\n/g, '<br>');
|
||||||
})
|
})
|
||||||
// GetDomFromText
|
|
||||||
.replace('<o:p></o:p>', '')
|
|
||||||
.replace('<o:p>', '<span>')
|
|
||||||
.replace('</o:p>', '</span>')
|
|
||||||
// \MailSo\Base\HtmlUtils::ClearFastTags
|
// \MailSo\Base\HtmlUtils::ClearFastTags
|
||||||
.replace(/<!doctype[^>]*>/i, '')
|
.replace(/<!doctype[^>]*>/i, '')
|
||||||
.replace(/<\?xml [^>]*\?>/i, '')
|
.replace(/<\?xml [^>]*\?>/i, '')
|
||||||
|
@ -149,12 +148,13 @@ export const
|
||||||
// || (oStyle.maxHeight && 1 > parseFloat(oStyle.maxHeight)
|
// || (oStyle.maxHeight && 1 > parseFloat(oStyle.maxHeight)
|
||||||
// || (oStyle.maxWidth && 1 > parseFloat(oStyle.maxWidth)
|
// || (oStyle.maxWidth && 1 > parseFloat(oStyle.maxWidth)
|
||||||
// || ('0' === oStyle.opacity
|
// || ('0' === oStyle.opacity
|
||||||
|
|| (inlineTags.includes(name) && '' == oElement.textContent.trim())
|
||||||
) {
|
) {
|
||||||
oElement.remove();
|
oElement.remove();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// if (['CENTER','FORM'].includes(name)) {
|
// if (['CENTER','FORM'].includes(name)) {
|
||||||
if ('FORM' === name) {
|
if ('FORM' === name || 'O:P' === name) {
|
||||||
replaceWithChildren(oElement);
|
replaceWithChildren(oElement);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -374,8 +374,11 @@ export const
|
||||||
// Convert child blockquote first
|
// Convert child blockquote first
|
||||||
blockquotes(bq);
|
blockquotes(bq);
|
||||||
// Convert blockquote
|
// Convert blockquote
|
||||||
bq.innerHTML = '\n' + ('\n' + bq.innerHTML.replace(/\n{3,}/gm, '\n\n').trim() + '\n').replace(/^/gm, '> ');
|
// bq.innerHTML = '\n' + ('\n' + bq.innerHTML.replace(/\n{3,}/gm, '\n\n').trim() + '\n').replace(/^/gm, '> ');
|
||||||
replaceWithChildren(bq);
|
// replaceWithChildren(bq);
|
||||||
|
bq.replaceWith(
|
||||||
|
'\n' + ('\n' + bq.textContent.replace(/\n{3,}/g, '\n\n').trim() + '\n').replace(/^/gm, '> ')
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -408,7 +411,11 @@ export const
|
||||||
// paragraphs
|
// paragraphs
|
||||||
forEach('p', node => {
|
forEach('p', node => {
|
||||||
node.prepend('\n\n');
|
node.prepend('\n\n');
|
||||||
node.after('\n\n');
|
if ('' == node.textContent.trim()) {
|
||||||
|
node.remove();
|
||||||
|
} else {
|
||||||
|
node.after('\n\n');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// proper indenting and numbering of (un)ordered lists
|
// proper indenting and numbering of (un)ordered lists
|
||||||
|
@ -429,7 +436,10 @@ export const
|
||||||
});
|
});
|
||||||
|
|
||||||
// Convert anchors
|
// Convert anchors
|
||||||
forEach('a', a => a.replaceWith(a.textContent + ' ' + a.href));
|
forEach('a', a => {
|
||||||
|
let txt = a.textContent, href = a.href;
|
||||||
|
return a.replaceWith((txt.trim() == href ? txt : txt + ' ' + href + ' '));
|
||||||
|
});
|
||||||
|
|
||||||
// Bold
|
// Bold
|
||||||
forEach('b,strong', b => b.replaceWith(`**${b.textContent}**`));
|
forEach('b,strong', b => b.replaceWith(`**${b.textContent}**`));
|
||||||
|
|
Loading…
Reference in a new issue