mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
DictD: One more fix for dictionary description
This commit is contained in:
parent
67db58b4fe
commit
367aac43bf
|
@ -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";
|
||||
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue