diff --git a/aard.cc b/aard.cc index 5b64fa7f..ef2c7510 100644 --- a/aard.cc +++ b/aard.cc @@ -522,11 +522,7 @@ void AardDictionary::loadArticle( quint32 address, articleText = QObject::tr( "Article decoding error" ).toStdString(); // See Issue #271: A mechanism to clean-up invalid HTML cards. - string cleaner = """""""""""" - """""""""""" - "" - "" - ""; + const string cleaner = Utils::Html::getHtmlCleaner(); string prefix( "
"; + result += R"( + + )"; } // Add a css stylesheet @@ -99,10 +101,13 @@ std::string ArticleMaker::makeHtmlHeader( QString const & word, // Turn on/off expanding of article optional parts if( expandOptionalParts ) { - result += "\n"; - result += "\n"; + result += R"( + )"; } } @@ -128,17 +133,18 @@ std::string ArticleMaker::makeHtmlHeader( QString const & word, if ( icon.size() ) result += R"(\n"; - result += ""; + result += QString::fromUtf8( R"( + +)" ).arg( tr( "Expand article" ), tr( "Collapse article" ) ) + .toStdString(); + result+= R"()"; if( GlobalBroadcaster::instance()->getPreference()->darkReaderMode ) @@ -643,31 +649,37 @@ void ArticleRequest::bodyFinished() string jsVal = Html::escapeForJavaScript( dictId ); - head += string( "
"; + head += QString::fromUtf8( + R"(
)" ) + .arg( closePrevSpan ? "" : " gdactivearticle" , + collapse ? " gdcollapsedarticle" : "" , + gdFrom.c_str() , + jsVal.c_str() ) + .toStdString(); closePrevSpan = true; - head += string( R"(
)" + - Html::escape( tr( "From " ).toUtf8().data() ) + "" + - Html::escape( activeDict->getName().c_str() ) + "" - + R"(" + "
"; + head += QString::fromUtf8( + R"(
+ + %4 + %5 + +
)" ) + .arg( dictId.c_str(), + collapse ? R"(style="cursor:pointer;")" : "", + collapse ? tr( "Expand article" ) : QString(), + Html::escape( tr( "From " ).toStdString() ).c_str(), + Html::escape( activeDict->getName() ).c_str(), + collapse ? "gdexpandicon" : "gdcollapseicon", + collapse ? "" : tr( "Collapse article" ) - head += "
"; + ) + .toStdString(); + + head += R"(
)"; // If the user has enabled Anki integration in settings, // Show a (+) button that lets the user add a new Anki card. @@ -680,14 +692,13 @@ void ArticleRequest::bodyFinished() head += link.arg( Html::escape( dictId ).c_str(), tr( "Make a new Anki note" ) ).toStdString(); } - head += "
getLangFrom() ).toLatin1().data(); - head += "\" lang=\""; - head += LangCoder::intToCode2( activeDict->getLangTo() ).toLatin1().data(); - head += "\""; - head += " style=\"display:"; - head += collapse ? "none" : "inline"; - head += string( "\" id=\"gdarticlefrom-" ) + Html::escape( dictId ) + "\">"; + head += QString::fromUtf8( + R"(
)" ) + .arg( LangCoder::intToCode2( activeDict->getLangFrom() ), + LangCoder::intToCode2( activeDict->getLangTo() ), + collapse ? "none" : "inline", + dictId.c_str() ) + .toStdString(); if( errorString.size() ) { head += "
" diff --git a/bgl.cc b/bgl.cc index 4c50c147..b51f753b 100644 --- a/bgl.cc +++ b/bgl.cc @@ -848,10 +848,7 @@ void BglArticleRequest::run() multimap< wstring, pair< string, string > >::const_iterator i; - string cleaner = """""""""""" - """""""""""" - "" - ""; + string cleaner = Utils::Html::getHtmlCleaner(); for( i = mainArticles.begin(); i != mainArticles.end(); ++i ) { if (dict.isFromLanguageRTL() ) // RTL support diff --git a/mdx.cc b/mdx.cc index 03cae762..233c193c 100644 --- a/mdx.cc +++ b/mdx.cc @@ -664,11 +664,7 @@ void MdxArticleRequest::run() } // See Issue #271: A mechanism to clean-up invalid HTML cards. - string cleaner = """""""""""" - """""""""""" - "" - "" - ""; + string cleaner = Utils::Html::getHtmlCleaner(); articleText += "
" + articleBody + cleaner + "
\n"; } diff --git a/slob.cc b/slob.cc index 3f46ba27..3df4a370 100644 --- a/slob.cc +++ b/slob.cc @@ -801,11 +801,7 @@ void SlobDictionary::loadArticle( quint32 address, articleText = QObject::tr( "Article decoding error" ).toStdString(); // See Issue #271: A mechanism to clean-up invalid HTML cards. - string cleaner = """""""""""" - """""""""""" - "" - "" - ""; + string cleaner = Utils::Html::getHtmlCleaner(); string prefix( "
>::const_iterator i; - string cleaner = """""""""""" - """""""""""" - "" - ""; + string cleaner = Utils::Html::getHtmlCleaner(); for( i = mainArticles.begin(); i != mainArticles.end(); ++i ) { diff --git a/utils.cc b/utils.cc index 5d565ff1..6b2b9589 100644 --- a/utils.cc +++ b/utils.cc @@ -32,3 +32,11 @@ void Utils::Widget::setNoResultColor(QWidget * widget, bool noResult) widget->setPalette( pal ); } } + +std::string Utils::Html::getHtmlCleaner() +{ + return R"( + + + )"; +} diff --git a/utils.hh b/utils.hh index 5d322f36..6907d5d2 100644 --- a/utils.hh +++ b/utils.hh @@ -319,6 +319,11 @@ namespace Widget{ void setNoResultColor(QWidget * widget, bool noResult); } +namespace Html { +// See Issue #271: A mechanism to clean-up invalid HTML cards. +std::string getHtmlCleaner(); +} + } #endif // UTILS_HH diff --git a/website.cc b/website.cc index bb2f933e..190ae3dc 100644 --- a/website.cc +++ b/website.cc @@ -275,11 +275,7 @@ void WebSiteArticleRequest::requestFinished( QNetworkReply * r ) } // See Issue #271: A mechanism to clean-up invalid HTML cards. - articleString += """""""""""" - """""""""""" - "" - "" - ""; + articleString += QString::fromStdString(Utils::Html::getHtmlCleaner()); QByteArray articleBody = articleString.toUtf8(); diff --git a/xdxf.cc b/xdxf.cc index 01e9169f..ea884366 100644 --- a/xdxf.cc +++ b/xdxf.cc @@ -596,10 +596,7 @@ void XdxfArticleRequest::run() multimap< wstring, pair< string, string > >::const_iterator i; - string cleaner = """""""""""" - """""""""""" - "" - ""; + string cleaner = Utils::Html::getHtmlCleaner(); for( i = mainArticles.begin(); i != mainArticles.end(); ++i ) { diff --git a/zim.cc b/zim.cc index 58f827f8..85241c58 100644 --- a/zim.cc +++ b/zim.cc @@ -1382,11 +1382,7 @@ void ZimArticleRequest::run() string result; // See Issue #271: A mechanism to clean-up invalid HTML cards. - string cleaner = """""""""""" - """""""""""" - "" - "" - ""; + string cleaner = Utils::Html::getHtmlCleaner(); multimap< wstring, pair< string, string > >::const_iterator i;