mirror of
https://github.com/the-djmaze/snappymail.git
synced 2024-09-20 07:35:55 +08:00
Fix html parsing
This commit is contained in:
parent
962391e2a0
commit
a30fc911f6
|
@ -5,7 +5,7 @@ import _ from '_';
|
|||
import ko from 'ko';
|
||||
|
||||
import {Magics} from 'Common/Enums';
|
||||
import {settingsSaveHelperSimpleFunction, trim, log} from 'Common/Utils';
|
||||
import {settingsSaveHelperSimpleFunction, trim} from 'Common/Utils';
|
||||
import {i18n, trigger as translatorTrigger} from 'Common/Translator';
|
||||
|
||||
import Remote from 'Remote/Admin/Ajax';
|
||||
|
|
|
@ -622,7 +622,7 @@ gulp.task('default', function(callback) {
|
|||
});
|
||||
|
||||
// watch
|
||||
gulp.task('watch', ['css:watch', 'js:validate:watch'], function() {
|
||||
gulp.task('watch', ['css:main', 'js:validate'], function() {
|
||||
cfg.watch = true;
|
||||
livereload.listen();
|
||||
gulp.watch(cfg.paths.less.main.watch, {interval: cfg.watchInterval}, ['css:main']);
|
||||
|
@ -631,7 +631,6 @@ gulp.task('watch', ['css:watch', 'js:validate:watch'], function() {
|
|||
|
||||
// aliases
|
||||
gulp.task('build', ['rainloop']);
|
||||
gulp.task('watch', ['css:watch', 'js:validate:watch']);
|
||||
|
||||
gulp.task('d', ['default']);
|
||||
gulp.task('w', ['watch']);
|
||||
|
|
|
@ -75,7 +75,7 @@ class HtmlUtils
|
|||
@$oDom->loadHTML('<'.'?xml version="1.0" encoding="utf-8"?'.'>'.
|
||||
'<html '.$sHtmlAttrs.'><head>'.
|
||||
'<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>'.
|
||||
'<body '.$sBodyAttrs.'><div data-wrp="rainloop">'.$sText.'</div></body></html>');
|
||||
'<body '.$sBodyAttrs.'><div data-wrp="rainloop">'.\MailSo\Base\Utils::Utf8Clear($sText).'</div></body></html>');
|
||||
|
||||
@$oDom->normalizeDocument();
|
||||
|
||||
|
@ -196,12 +196,7 @@ class HtmlUtils
|
|||
else
|
||||
{
|
||||
$sResult = self::domToString($oDiv, $oDom);
|
||||
if (0 === strpos($sResult, '<div>') && '</div>' === substr($sResult, -6))
|
||||
{
|
||||
$sResult = substr($sResult, 5);
|
||||
$sResult = substr($sResult, 0, -6);
|
||||
$sResult = \trim($sResult);
|
||||
}
|
||||
$sResult = \MailSo\Base\HtmlUtils::UnWrapTag($sResult);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -217,7 +212,37 @@ class HtmlUtils
|
|||
|
||||
/**
|
||||
* @param string $sHtml
|
||||
* @param string $sHtmlAttrs = '
|
||||
* @param string $sTag = 'div'
|
||||
* @param string $iUnwrapCount = 10
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function UnWrapTag($sHtml, $sTag = 'div', $iUnwrapCount = 5)
|
||||
{
|
||||
$iUnwrapCount = 0 < $iUnwrapCount ? $iUnwrapCount : 1;
|
||||
$iUnwrapCount = 10 < $iUnwrapCount ? 10 : $iUnwrapCount;
|
||||
|
||||
$sTag = $sTag ? $sTag : 'div';
|
||||
$iTagLen = \strlen($sTag);
|
||||
|
||||
while (0 < $iUnwrapCount)
|
||||
{
|
||||
$sHtml = \trim($sHtml);
|
||||
if (0 === \strpos($sHtml, '<'.$sTag.'>') && '</'.$sTag.'>' === \substr($sHtml, -3 - $iTagLen))
|
||||
{
|
||||
$sHtml = \substr(\substr($sHtml, 2 + $iTagLen), 0, -3 - $iTagLen);
|
||||
$sHtml = \trim($sHtml);
|
||||
}
|
||||
|
||||
$iUnwrapCount--;
|
||||
}
|
||||
|
||||
return $sHtml;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sHtml
|
||||
* @param string $sHtmlAttrs = ''
|
||||
* @param string $sBodyAttrs = ''
|
||||
*
|
||||
* @return string
|
||||
|
@ -247,14 +272,23 @@ class HtmlUtils
|
|||
// $sHtml = 0 < $iPos ? \substr($sHtml, $iPos) : $sHtml;
|
||||
// }
|
||||
|
||||
$sHtml = \preg_replace('/<head([^>]*)>/si', '', $sHtml);
|
||||
$sHtml = \preg_replace('/<body([^>]*)>/si', '', $sHtml);
|
||||
$sHtml = \preg_replace('/<\/body>/i', '', $sHtml);
|
||||
$sHtml = \preg_replace('/<html([^>]*)>/i', '', $sHtml);
|
||||
$sHtml = \preg_replace('/<\/html>/i', '', $sHtml);
|
||||
|
||||
$sHtmlAttrs = \preg_replace('/xmlns:[a-z]="[^"]*"/i', '', $sHtmlAttrs);
|
||||
$sHtmlAttrs = \preg_replace('/xmlns:[a-z]=\'[^\']*\'/i', '', $sHtmlAttrs);
|
||||
$sHtmlAttrs = \preg_replace('/xmlns="[^"]*"/i', '', $sHtmlAttrs);
|
||||
$sHtmlAttrs = \preg_replace('/xmlns=\'[^\']*\'/i', '', $sHtmlAttrs);
|
||||
$sBodyAttrs = \preg_replace('/xmlns:[a-z]="[^"]*"/i', '', $sBodyAttrs);
|
||||
$sBodyAttrs = \preg_replace('/xmlns:[a-z]=\'[^\']*\'/i', '', $sBodyAttrs);
|
||||
|
||||
$sHtmlAttrs = trim($sHtmlAttrs);
|
||||
$sBodyAttrs = trim($sBodyAttrs);
|
||||
|
||||
$sHtml = \MailSo\Base\HtmlUtils::UnWrapTag($sHtml);
|
||||
|
||||
return $sHtml;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue