fix: collapse function does not work expectedly.

the website dictionaries do not collapse as it will always treated as 0 .
the normal dictionaries html size is not correct calculated due to a qt bug https://bugreports.qt.io/browse/QTBUG-102757
This commit is contained in:
xiaoyifang 2022-04-20 20:53:57 +08:00
parent 43b2006d72
commit f6c588ee7e
2 changed files with 20 additions and 2 deletions

View file

@ -596,7 +596,7 @@ void ArticleRequest::bodyFinished()
}
}
int size = QTextDocumentFragment::fromHtml( text ).toPlainText().length();
int size = htmlTextSize( text );
if( size > articleSizeLimit )
collapse = true;
}
@ -750,6 +750,24 @@ void ArticleRequest::bodyFinished()
}
}
int ArticleRequest::htmlTextSize( QString html )
{
// website dictionary.
if( html.contains( QRegularExpression( "<iframe\\s*[^>]*>", QRegularExpression::CaseInsensitiveOption ) ) )
{
//arbitary number;
return 1000;
}
//https://bugreports.qt.io/browse/QTBUG-102757
QString stripStyleSheet =
html.remove( QRegularExpression( "<link\\s*[^>]*>", QRegularExpression::CaseInsensitiveOption ) )
.remove( QRegularExpression( "<script[\\s\\S]*?>[\\s\\S]*?<\\/script>", QRegularExpression::CaseInsensitiveOption|QRegularExpression::MultilineOption ) );
int size = QTextDocumentFragment::fromHtml( stripStyleSheet ).toPlainText().length();
return size;
}
void ArticleRequest::stemmedSearchFinished()
{
// Got stemmed matching results

View file

@ -148,7 +148,7 @@ private slots:
void individualWordFinished();
private:
int htmlTextSize( QString html );
/// Appends the given string to 'data', with locking its mutex.
void appendToData( std::string const & );