From c892083b00d428c6ccf8cf0611e9be1f5cff79c2 Mon Sep 17 00:00:00 2001 From: shenleban tongying Date: Tue, 19 Nov 2024 21:30:17 -0500 Subject: [PATCH] fix: stardict format's description HTML display (.ifo file) --- src/dict/stardict.cc | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/dict/stardict.cc b/src/dict/stardict.cc index decdacb6..52773cde 100644 --- a/src/dict/stardict.cc +++ b/src/dict/stardict.cc @@ -76,9 +76,11 @@ DEF_EX_STR( exIncorrectOffset, "Incorrect offset encountered in file", Dictionar /// Contents of an ifo file struct Ifo { - string version; string bookname; - uint32_t wordcount, synwordcount, idxfilesize, idxoffsetbits; + uint32_t wordcount = 0; + uint32_t synwordcount = 0; + uint32_t idxfilesize = 0; + uint32_t idxoffsetbits = 0; string sametypesequence, dicttype, description; string copyright, author, email, website, date; @@ -1089,36 +1091,33 @@ QString const & StardictDictionary::getDescription() Ifo ifo( ifoFile ); if ( !ifo.copyright.empty() ) { - QString copyright = QString::fromUtf8( ifo.copyright.c_str() ).replace( "
", "\n", Qt::CaseInsensitive ); - dictionaryDescription += QObject::tr( "Copyright: %1%2" ).arg( copyright ).arg( "\n\n" ); + QString copyright = QString::fromUtf8( ifo.copyright.c_str() ); + dictionaryDescription += QObject::tr( "Copyright: %1%2" ).arg( copyright ).arg( "

" ); } if ( !ifo.author.empty() ) { QString author = QString::fromUtf8( ifo.author.c_str() ); - dictionaryDescription += QObject::tr( "Author: %1%2" ).arg( author ).arg( "\n\n" ); + dictionaryDescription += QObject::tr( "Author: %1%2" ).arg( author ).arg( "

" ); } if ( !ifo.email.empty() ) { QString email = QString::fromUtf8( ifo.email.c_str() ); - dictionaryDescription += QObject::tr( "E-mail: %1%2" ).arg( email ).arg( "\n\n" ); + dictionaryDescription += QObject::tr( "E-mail: %1%2" ).arg( email ).arg( "

" ); } if ( !ifo.website.empty() ) { QString website = QString::fromUtf8( ifo.website.c_str() ); - dictionaryDescription += QObject::tr( "Website: %1%2" ).arg( website ).arg( "\n\n" ); + dictionaryDescription += QObject::tr( "Website: %1%2" ).arg( website ).arg( "

" ); } if ( !ifo.date.empty() ) { QString date = QString::fromUtf8( ifo.date.c_str() ); - dictionaryDescription += QObject::tr( "Date: %1%2" ).arg( date ).arg( "\n\n" ); + dictionaryDescription += QObject::tr( "Date: %1%2" ).arg( date ).arg( "

" ); } if ( !ifo.description.empty() ) { QString desc = QString::fromUtf8( ifo.description.c_str() ); - desc.replace( "\t", "
" ); - desc.replace( "\\n", "
" ); - desc.replace( "
", "
", Qt::CaseInsensitive ); - dictionaryDescription += Html::unescape( desc, Html::HtmlOption::Keep ); + dictionaryDescription += desc; } if ( dictionaryDescription.isEmpty() ) {