DictD: One more fix for dictionary description

This commit is contained in:
Abs62 2015-02-26 17:37:20 +03:00
parent 67db58b4fe
commit 367aac43bf
3 changed files with 12 additions and 13 deletions

View file

@ -403,11 +403,7 @@ QString const& DictdDictionary::getDescription()
vector< wstring >(), wstring() );
if( req->dataSize() > 0 )
{
dictionaryDescription = Html::unescape( QString::fromUtf8( req->getFullData().data(), req->getFullData().size() ) );
dictionaryDescription.replace( "\r\n", "\n" );
dictionaryDescription.replace( '\r', '\n' );
}
dictionaryDescription = Html::unescape( QString::fromUtf8( req->getFullData().data(), req->getFullData().size() ), true );
else
dictionaryDescription = "NONE";

View file

@ -137,23 +137,26 @@ string escapeForJavaScript( string const & str )
return result;
}
QString unescape( QString const & str )
QString unescape( QString const & str, bool saveFormat )
{
// Does it contain HTML? If it does, we need to strip it
if ( str.contains( '<' ) || str.contains( '&' ) )
{
QString tmp = str;
tmp.replace( QRegExp( "<(?:\\s*(?:div|p(?![alr])|br|li(?![ns])|td|blockquote|/ol))[^>]{0,}>",
Qt::CaseInsensitive, QRegExp::RegExp2 ), " " );
tmp.remove( QRegExp( "<[^>]*>", Qt::CaseSensitive, QRegExp::RegExp2 ) );
if( !saveFormat )
{
tmp.replace( QRegExp( "<(?:\\s*(?:div|p(?![alr])|br|li(?![ns])|td|blockquote|/ol))[^>]{0,}>",
Qt::CaseInsensitive, QRegExp::RegExp2 ), " " );
tmp.remove( QRegExp( "<[^>]*>", Qt::CaseSensitive, QRegExp::RegExp2 ) );
}
return QTextDocumentFragment::fromHtml( tmp.trimmed() ).toPlainText();
}
return str;
}
string unescapeUtf8( const string &str )
string unescapeUtf8( const string &str, bool saveFormat )
{
return string( unescape( QString::fromUtf8( str.c_str(), str.size() ) ).toUtf8().data() );
return string( unescape( QString::fromUtf8( str.c_str(), str.size() ) ).toUtf8().data(), saveFormat );
}
}

View file

@ -23,8 +23,8 @@ string preformat( string const &, bool baseRightToLeft = false );
string escapeForJavaScript( string const & );
// Replace html entities
QString unescape( QString const & str );
string unescapeUtf8( string const & str );
QString unescape( QString const & str, bool saveFormat = false );
string unescapeUtf8( string const & str, bool saveFormat = false );
}