fix: replace reference link

the call eb_backward_text , the <R1> tags is arranged backward
the original replace method with position does not work
This commit is contained in:
Xiao YiFang 2023-03-22 21:05:20 +08:00 committed by xiaoyifang
parent f8f3ce966e
commit e9459c1066

View file

@ -1059,8 +1059,7 @@ bool EpwingBook::processRef( EpwingHeadword & head)
auto key = ( (uint64_t)pos.page ) << 32 | ( pos.offset ); auto key = ( (uint64_t)pos.page ) << 32 | ( pos.offset );
//this only add the existed reference point which has already in the headwords as another headword(rxxxxAtxxxx) in the headword list. //this only add the existed reference point which has already in the headwords as another headword(rxxxxAtxxxx) in the headword list.
//this will make the loadarticle's real reference link judgement easier. //this will make the loadarticle's real reference link judgement easier.
if( allHeadwordPositions.contains( key ) )
if( allRefPositions.contains( key ) )
{ {
// fixed the reference headword ,to avoid the headword collision with other entry . // fixed the reference headword ,to avoid the headword collision with other entry .
//if(!allHeadwordPositions.contains(key)) //if(!allHeadwordPositions.contains(key))
@ -1371,20 +1370,15 @@ void EpwingBook::finalizeText( QString & text )
} }
// Replace references // Replace references
int pos = 0; int pos = 0;
QString reg1( "<R%1>"); QString reg1( "<R%1>");
QString reg2( "</R%1>"); QString reg2( "</R%1>");
EContainer cont( this, true );
char buf[ TextBufferSize + 1 ];
for( int x = 0; x < refCloseCount; x++ ) for( int x = 0; x < refCloseCount; x++ )
{ {
auto tag1=reg1.arg(x); auto tag1=reg1.arg(x);
auto tag2=reg2.arg(x); auto tag2=reg2.arg(x);
pos = text.indexOf( tag1, pos ); pos = text.indexOf( tag1 );
if( pos < 0 ) if( pos < 0 )
continue; continue;
@ -1396,25 +1390,13 @@ void EpwingBook::finalizeText( QString & text )
url.setScheme( "gdlookup" ); url.setScheme( "gdlookup" );
url.setHost( "localhost" ); url.setHost( "localhost" );
// Read headword url.setPath( Utils::Url::ensureLeadingSlash( QString( "r%1At%2" ).arg( ebpos.page ).arg(ebpos.offset) ) );
eb_seek_text( &book, &ebpos );
ssize_t length;
EB_Error_Code ret = eb_read_heading( &book, &appendix, &hookSet, &cont,
TextBufferSize, buf, &length );
if( ret == EB_SUCCESS )
{
QString headword = QString::fromUtf8( buf, length );
fixHeadword( headword );
url.setPath( Utils::Url::ensureLeadingSlash( QString( "r%1At%2" ).arg( ebpos.page ).arg(ebpos.offset) ) );
}
QString link = "<a href=\"" + url.toEncoded() + "\">"; QString link = "<a href=\"" + url.toEncoded() + "\">";
text.replace( tag1, link ); text.replace( tag1, link );
pos = text.indexOf( tag2, pos ); pos = text.indexOf( tag2 );
if( pos < 0 ) if( pos < 0 )
continue; continue;