Skip to content

Commit

Permalink
fix:epwing dictionary link target is not correct
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyifang committed May 17, 2022
1 parent e06f865 commit 2eccf7a
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions epwing_book.cc
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,11 @@ bool EpwingBook::setSubBook( int book_nom )
if( f.open( QFile::ReadOnly | QFile::Text ) )
{
QTextStream ts( &f );
//todo?
// ts.setCodec( "UTF-8" );
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
ts.setCodec( "UTF-8" );
#else
ts.setEncoding(QStringConverter::Utf8);
#endif

QString line = ts.readLine();
while( !line.isEmpty() )
Expand Down Expand Up @@ -1204,18 +1207,20 @@ void EpwingBook::finalizeText( QString & text )
// Replace references

int pos = 0;
QRegularExpression reg1( "<R[^<]*>", QRegularExpression::CaseInsensitiveOption );
QRegularExpression reg2( "</R[^<]*>", QRegularExpression::CaseInsensitiveOption );
QString reg1( "<R%1>");
QString reg2( "</R%1>");

EContainer cont( this, true );

char buf[ TextBufferSize + 1 ];

for( int x = 0; x < refCloseCount; x++ )
{
pos = text.indexOf( reg1, pos );
auto tag1=reg1.arg(x);
auto tag2=reg2.arg(x);
pos = text.indexOf( tag1, pos );
if( pos < 0 )
break;
continue;

EB_Position ebpos;
ebpos.page = refPages[ x ];
Expand All @@ -1241,14 +1246,13 @@ void EpwingBook::finalizeText( QString & text )

QString link = "<a href=\"" + url.toEncoded() + "\">";

//todo ? iterate cap ,or replace as a whole?
text.replace( reg1, link );
text.replace( tag1, link );

pos = text.indexOf( reg2, pos );
pos = text.indexOf( tag2, pos );
if( pos < 0 )
break;
continue;

text.replace( reg2, "</a>" );
text.replace( tag2, "</a>" );
}
}

Expand Down

0 comments on commit 2eccf7a

Please sign in to comment.