diff --git a/website.cc b/website.cc index b19d3fb9..2cce5e67 100644 --- a/website.cc +++ b/website.cc @@ -61,6 +61,10 @@ public: wstring const & context ) throw( std::exception ); + virtual sptr< Dictionary::DataRequest > getResource( string const & name ) throw( std::exception ); + + void isolateWebCSS( QString & css ); + protected: virtual void loadIcon() throw(); @@ -76,9 +80,13 @@ sptr< WordSearchRequest > WebSiteDictionary::prefixMatch( wstring const & /*word return sr; } +void WebSiteDictionary::isolateWebCSS( QString & css ) +{ + isolateCSS( css, ".website" ); +} + class WebSiteArticleRequest: public WebSiteDataRequestSlots { - typedef std::list< std::pair< QNetworkReply *, bool > > NetReplies; QNetworkReply * netReply; QString url; Class * dictPtr; @@ -161,8 +169,6 @@ void WebSiteArticleRequest::requestFinished( QNetworkReply * r ) else articleString = QString::fromUtf8( replyData ); - QString divName = QString( "website_" ) + dictPtr->getId().c_str(); - // Change links from relative to absolute QString root = netReply->url().scheme() + "://" + netReply->url().host(); @@ -216,6 +222,24 @@ void WebSiteArticleRequest::requestFinished( QNetworkReply * r ) pos += tag.size(); } + // Redirect CSS links to own handler + + QString prefix = QString( "bres://" ) + dictPtr->getId().c_str() + "/"; + QRegExp linkTags( "(<\\s*link\\s[^>]*rel\\s*=\\s*['\"]stylesheet['\"]\\s+[^>]*href\\s*=\\s*['\"])([^'\"]+)://([^'\"]+['\"][^>]+>)", + Qt::CaseInsensitive, QRegExp::RegExp2 ); + pos = 0; + while( pos >= 0 ) + { + pos = articleString.indexOf( linkTags, pos ); + if( pos < 0 ) + break; + + QString newTag = linkTags.cap( 1 ) + prefix + linkTags.cap( 2 ) + + "/" + linkTags.cap( 3 ); + articleString.replace( pos, linkTags.cap().size(), newTag ); + pos += newTag.size(); + } + // Check for unclosed and
int openTags = articleString.count( QRegExp( "<\\s*span\\b", Qt::CaseInsensitive ) ); @@ -243,7 +267,7 @@ void WebSiteArticleRequest::requestFinished( QNetworkReply * r ) QByteArray articleBody = articleString.toUtf8(); - QString divStr = QString( "
isToLanguageRTL() ? " dir=\"rtl\">" : ">"; articleBody.prepend( divStr.toUtf8() ); @@ -275,8 +299,6 @@ sptr< DataRequest > WebSiteDictionary::getArticle( wstring const & str, wstring const & context ) throw( std::exception ) { - sptr< DataRequestInstant > dr = new DataRequestInstant( true ); - QByteArray urlString; // Context contains the right url to go to @@ -327,6 +349,8 @@ sptr< DataRequest > WebSiteDictionary::getArticle( wstring const & str, { // Just insert link in