mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
Wiki: Fix urls in "srcset" attribute (issue #1096)
This commit is contained in:
parent
e7e37cbbeb
commit
9bae6d2201
37
mediawiki.cc
37
mediawiki.cc
|
@ -541,6 +541,43 @@ void MediaWikiArticleRequest::requestFinished( QNetworkReply * r )
|
|||
// Add url scheme to other urls like "//xxx"
|
||||
articleString.replace( " href=\"//", " href=\"" + wikiUrl.scheme() + "://" );
|
||||
|
||||
// Fix urls in "srcset" attribute
|
||||
pos = 0;
|
||||
#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
|
||||
QRegularExpression regSrcset( " srcset\\s*=\\s*\"/[^\"]+\"" );
|
||||
it = regSrcset.globalMatch( articleString );
|
||||
while( it.hasNext() )
|
||||
{
|
||||
QRegularExpressionMatch match = it.next();
|
||||
articleNewString += articleString.midRef( pos, match.capturedStart() - pos );
|
||||
pos = match.capturedEnd();
|
||||
|
||||
QString srcset = match.captured();
|
||||
#else
|
||||
QRegExp regSrcset( " srcset\\s*=\\s*\"/([^\"]+)\"" );
|
||||
for( ; ; )
|
||||
{
|
||||
pos = regSrcset.indexIn( articleString, pos );
|
||||
if( pos < 0 )
|
||||
break;
|
||||
QString srcset = regSrcset.cap();
|
||||
#endif
|
||||
QString newSrcset = srcset.replace( "//", wikiUrl.scheme() + "://" );
|
||||
#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
|
||||
articleNewString += newSrcset;
|
||||
}
|
||||
if( pos )
|
||||
{
|
||||
articleNewString += articleString.midRef( pos );
|
||||
articleString = articleNewString;
|
||||
articleNewString.clear();
|
||||
}
|
||||
#else
|
||||
articleString.replace( pos, regSrcset.cap().size(), newSrcset );
|
||||
pos += newSrcset.size();
|
||||
}
|
||||
#endif
|
||||
|
||||
QByteArray articleBody = articleString.toUtf8();
|
||||
|
||||
articleBody.prepend( dictPtr->isToLanguageRTL() ? "<div class=\"mwiki\" dir=\"rtl\">" :
|
||||
|
|
Loading…
Reference in a new issue