mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
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:
parent
43b2006d72
commit
f6c588ee7e
|
@ -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
|
||||
|
|
|
@ -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 & );
|
||||
|
||||
|
|
Loading…
Reference in a new issue