mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 04:24:09 +00:00
fix:zim regression
image can not displayed
This commit is contained in:
parent
4a129005df
commit
aa9ed9bc38
53
zim.cc
53
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( "<body \\1" ) );
|
||||
|
||||
// pattern of img and script
|
||||
text.replace( QRegularExpression( "<\\s*(img|script)\\s+([^>]*)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
|
||||
// <meta http-equiv="Refresh" content="0;url=../dsalsrv02.uchicago.edu/cgi-bin/0994.html">
|
||||
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 );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue