mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 00:14:06 +00:00
Stardict: Handle local url's in loaded .css
This commit is contained in:
parent
7fa2df772e
commit
0a59dd6e5b
26
stardict.cc
26
stardict.cc
|
@ -1507,6 +1507,32 @@ void StardictResourceRequest::run()
|
|||
Mutex::Lock _( dataMutex );
|
||||
|
||||
QString css = QString::fromUtf8( data.data(), data.size() );
|
||||
|
||||
// Correct some url's
|
||||
|
||||
QRegExp links( "url\\(\\s*(['\"])([^'\"]*)(['\"])\\s*\\)");
|
||||
QString id = QString::fromUtf8( dict.getId().c_str() );
|
||||
int pos = 0;
|
||||
for( ; ; )
|
||||
{
|
||||
pos = links.indexIn( css, pos );
|
||||
if( pos < 0 )
|
||||
break;
|
||||
QString url = links.cap( 2 );
|
||||
|
||||
if( url.indexOf( "/" ) >= 0 )
|
||||
{
|
||||
// External link
|
||||
pos += links.cap().size();
|
||||
continue;
|
||||
}
|
||||
|
||||
QString newUrl = QString( "url(" ) + links.cap( 1 ) + "bres://"
|
||||
+ id + "/" + url + links.cap( 3 ) + ")";
|
||||
css.replace( pos, links.cap().size(), newUrl );
|
||||
pos += newUrl.size();
|
||||
}
|
||||
|
||||
dict.isolateCSS( css );
|
||||
QByteArray bytes = css.toUtf8();
|
||||
data.resize( bytes.size() );
|
||||
|
|
Loading…
Reference in a new issue