diff --git a/zim.cc b/zim.cc index f352383d..04a5df12 100644 --- a/zim.cc +++ b/zim.cc @@ -128,7 +128,7 @@ __attribute__((packed)) enum { Signature = 0x584D495A, // ZIMX on little-endian, XMIZ on big-endian - CurrentFormatVersion = 3 + BtreeIndexing::FormatVersion + Folding::Version + CurrentFormatVersion = 4 + BtreeIndexing::FormatVersion + Folding::Version }; struct IdxHeader @@ -839,8 +839,44 @@ string ZimDictionary::convert( const string & in ) QString( "]*)src=(\"|)(\\.\\./)*" ), - QString( "<\\1 \\2src=\\3bres://%1/").arg( getId().c_str() ) ); + // text.replace( QRegularExpression( "<\\s*(img|script)\\s+([^>]*)src=(\")([^\"]*)\\3" ), + // QString( "<\\1 \\2src=\\3bres://%1/").arg( getId().c_str() ) ); + + QRegularExpression rxImgScript( "<\\s*(img|script)\\s+([^>]*)src=(\")([^\"]*)\\3" ); + QRegularExpressionMatchIterator it = rxImgScript.globalMatch( text ); + int pos = 0; + QString newText; + while( it.hasNext() ) + { + QRegularExpressionMatch match = it.next(); + + newText += text.mid( pos, match.capturedStart() - pos ); + pos = match.capturedEnd(); + + QStringList list = match.capturedTexts(); + + QString url = list[ 4 ]; // a url + + QString urlLink = match.captured(); + + QString replacedLink = urlLink; + if( !url.isEmpty() && !url.startsWith( "//" ) && !url.startsWith( "http://" ) && !url.startsWith( "https://" ) ) + { + //<\\1 \\2src=\\3bres://%1/ + url.replace( RX::Zim::linkSpecialChar, "" ); + replacedLink = + QString( "<%1 %2 src=\"bres://%3/%4\"" ).arg( list[ 1 ], list[ 2 ], QString::fromStdString( getId() ), url ); + } + + newText += replacedLink; + } + if( pos ) + { + newText += text.mid( pos ); + text = newText; + } + newText.clear(); + // Fix links without '"' text.replace( QRegularExpression( "href=(\\.\\.|)/([^\\s>]+)" ), @@ -860,9 +896,8 @@ string ZimDictionary::convert( const string & in ) // these links will be translated into local definitions // QRegularExpression rxLink( "<\\s*(?:a|meta)\\s+([^>]*)(?:href|url)=\"?(?!(?:\\w+://|#|mailto:|tel:))()([^\"]*)\"\\s*(title=\"[^\"]*\")?[^>]*>" ); - QRegularExpressionMatchIterator it = rxLink.globalMatch( text ); - int pos = 0; - QString newText; + it = rxLink.globalMatch( text ); + pos = 0; while( it.hasNext() ) { QRegularExpressionMatch match = it.next(); @@ -1658,6 +1693,8 @@ vector< sptr< Dictionary::Class > > makeDictionaries( } else { + url.insert( url.begin(), '/' ); + url.insert( url.begin(), nameSpace ); auto formatedUrl = QString::fromStdString(url).replace(RX::Zim::linkSpecialChar,""); indexedResources.addSingleWord( Utf8::decode( formatedUrl.toStdString() ), n ); } @@ -1695,8 +1732,8 @@ vector< sptr< Dictionary::Class > > makeDictionaries( } else { -// url.insert( url.begin(), '/' ); -// url.insert( url.begin(), nameSpace ); + url.insert( url.begin(), '/' ); + url.insert( url.begin(), nameSpace ); auto formatedUrl = QString::fromStdString(url).replace(RX::Zim::linkSpecialChar,""); indexedResources.addSingleWord( Utf8::decode( formatedUrl.toStdString() ), n ); }