From 56770cf4ff241482794254c59eb891b97681d2e0 Mon Sep 17 00:00:00 2001 From: Abs62 Date: Fri, 23 May 2014 21:43:44 +0400 Subject: [PATCH] Zim: Fix new format links handling --- article-style.css | 6 +++- article_netmgr.cc | 6 ++++ zim.cc | 84 +++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 89 insertions(+), 7 deletions(-) diff --git a/article-style.css b/article-style.css index 4607cc01..2131de68 100644 --- a/article-style.css +++ b/article-style.css @@ -499,10 +499,14 @@ div.xdxf /************* Zim dictionaries **************/ +.zimdict +{ + font-size: 120%!important; +} + .zimdict_headword { font-weight: bold!important; -/* font-size: 150%; */ } /************* Spelling suggestions *****************/ diff --git a/article_netmgr.cc b/article_netmgr.cc index 51bb495e..e1cc3541 100644 --- a/article_netmgr.cc +++ b/article_netmgr.cc @@ -132,6 +132,12 @@ sptr< Dictionary::DataRequest > ArticleNetworkAccessManager::getResource( if ( url.scheme() == "gdlookup" ) { + if( !url.host().isEmpty() && url.host() != "localhost" ) + { + // Strange request - ignore it + return new Dictionary::DataRequestInstant( false ); + } + contentType = "text/html"; if ( url.queryItemValue( "blank" ) == "1" ) diff --git a/zim.cc b/zim.cc index 00d32330..65cd93e0 100644 --- a/zim.cc +++ b/zim.cc @@ -600,17 +600,89 @@ string ZimDictionary::convert( const string & in ) text.replace( QRegExp( "<\\s*body\\s*([^>]*)background:([^;\"]*)" ), QString( "]*)src=\"/" ), - QString( "<\\1 \\2src=\"bres://%1/").arg( getId().c_str() ) ); + text.replace( QRegExp( "<\\s*(img|script)\\s*([^>]*)src=(\"|)/" ), + QString( "<\\1 \\2src=\\3bres://%1/").arg( getId().c_str() ) ); + + // Fix links without '"' + text.replace( QRegExp( "href=/([^\\s>]+)" ), QString( "href=\"/\\1\"" ) ); text.replace( QRegExp( "<\\s*link\\s*([^>]*)href=\"/" ), QString( "]*)href=\"/[^\"]*\"\\s*title=\"([^\"]*)\"" ), - QString( "]*)href=\"/[^\"]*\"\\s*title=\"([^\"]*)\"", + Qt::CaseSensitive, + QRegExp::RegExp2 ); - text.replace( QRegExp( "<\\s*a\\s*([^>]*)href=\"/A/([^\"]*)\"" ), - QString( "]*)href=\"/A/([^\"]*)\"", + Qt::CaseSensitive, + QRegExp::RegExp2 ); + + QRegExp linkRegexp3( ".(s|)htm(l|)", Qt::CaseInsensitive ); + + int pos = 0; + while( pos >= 0 ) + { + pos = linkRegexp1.indexIn( text, pos ); + if( pos < 0 ) + break; + + QStringList list = linkRegexp1.capturedTexts(); + + QString tag = QString( "= 0 ) + { + pos = linkRegexp2.indexIn( text, pos ); + if( pos < 0 ) + break; + + QStringList list = linkRegexp2.capturedTexts(); + + QString tag = QString( "";