From f9085fad1fe4e87c0612884eb2d63b49864b463a Mon Sep 17 00:00:00 2001 From: Abs62 Date: Wed, 11 May 2016 17:44:07 +0300 Subject: [PATCH] Fix links with anchor while save article to file --- mainwindow.cc | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/mainwindow.cc b/mainwindow.cc index 443f8715..253691c1 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -3308,12 +3308,25 @@ void MainWindow::on_saveArticle_triggered() while ( ( pos = rx3.indexIn( html, pos ) ) != -1 ) { QString name = QUrl::fromPercentEncoding( rx3.cap( 2 ).simplified().toLatin1() ); + QString anchor; + name.replace( "?gdanchor=", "#" ); + int n = name.indexOf( '#' ); + if( n > 0 ) + { + anchor = name.mid( n ); + name.truncate( n ); + anchor.replace( QRegExp( "(g[0-9a-f]{32}_)[0-9a-f]+_" ), "\\1" ); // MDict anchors + } name.replace( rxName, "_" ); - name = QString( "href=\"" ) + QUrl::toPercentEncoding( name ) + ".html\""; + name = QString( "href=\"" ) + QUrl::toPercentEncoding( name ) + ".html" + anchor + "\""; html.replace( pos, rx3.cap().length(), name ); pos += name.length(); } + // MDict anchors + QRegExp anchorLinkRe( "(<\\s*a\\s+[^>]*\\b(?:name|id)\\b\\s*=\\s*[\"']*g[0-9a-f]{32}_)([0-9a-f]+_)(?=[^\"'])", Qt::CaseInsensitive ); + html.replace( anchorLinkRe, "\\1" ); + if ( complete ) { QString folder = fi.absoluteDir().absolutePath() + "/" + fi.baseName() + "_files";