Slob: Handle inter-article anchors

This commit is contained in:
Abs62 2015-10-30 21:01:38 +03:00
parent c2eb4a0ef2
commit d8eba31d2d
2 changed files with 21 additions and 3 deletions

View file

@ -492,11 +492,13 @@ void ArticleView::loadFinished( bool )
QString anchor = QUrl::fromPercentEncoding( url.encodedQueryItemValue( "gdanchor" ) );
// Find GD anchor on page
// Pattern: (dictionary ID (32 chars))_(articleID(quint64, hex))_(original anchor)
int n = anchor.indexOf( '_' );
if( n > 0 )
if( n == 32 )
// MDict pattern: (dictionary ID (32 chars))_(articleID(quint64, hex))_(original anchor)
n = anchor.indexOf( '_', n + 1 );
else
n = 0;
if( n > 0 )
{
@ -524,6 +526,12 @@ void ArticleView::loadFinished( bool )
}
}
}
else
{
url.setFragment( anchor );
ui.definition->page()->mainFrame()->evaluateJavaScript(
QString( "window.location = \"%1\"" ).arg( QString::fromUtf8( url.toEncoded() ) ) );
}
}
#endif

12
slob.cc
View file

@ -757,6 +757,9 @@ string SlobDictionary::convert( const string & in, RefEntry const & entry )
QRegExp rxLink( "<\\s*a\\s+([^>]*)href=\"(?!(\\w+://|#|mailto:|tel:))(/|)([^\"]*)\"\\s*(title=\"[^\"]*\")?[^>]*>",
Qt::CaseSensitive,
QRegExp::RegExp2 );
QString anchor;
int pos = 0;
while( (pos = rxLink.indexIn( text, pos )) >= 0 )
{
@ -765,11 +768,18 @@ string SlobDictionary::convert( const string & in, RefEntry const & entry )
if ( !list[4].isEmpty() )
tag = list[4].split("\"")[1];
// Find anchor
int n = list[ 3 ].indexOf( '#' );
if( n > 0 )
anchor = QString( "?gdanchor=" ) + list[ 3 ].mid( n + 1 );
else
anchor.clear();
tag.remove( QRegExp(".*/") ).
remove( QRegExp( "\\.(s|)htm(l|)$", Qt::CaseInsensitive ) ).
replace( "_", "%20" ).
prepend( "<a href=\"gdlookup://localhost/" ).
append( "\" " + list[4] + ">" );
append( anchor + "\" " + list[4] + ">" );
text.replace( pos, list[0].length(), tag );
pos += tag.length() + 1;