Skip to content

Commit

Permalink
fix: collapse function does not work expectedly.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
xiaoyifang committed Apr 21, 2022
1 parent 43b2006 commit f6c588e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
20 changes: 19 additions & 1 deletion article_maker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ void ArticleRequest::bodyFinished()
}
}

int size = QTextDocumentFragment::fromHtml( text ).toPlainText().length();
int size = htmlTextSize( text );
if( size > articleSizeLimit )
collapse = true;
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion article_maker.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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 & );

Expand Down

0 comments on commit f6c588e

Please sign in to comment.