mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-12-18 03:14:06 +00:00
MDict: Use reluctant matching for anchor processing
This commit is contained in:
parent
dd627e940b
commit
341e5a7ebf
14
mdx.cc
14
mdx.cc
|
@ -814,6 +814,8 @@ string MdxDictionary::filterResource( const char * articleId, const char * artic
|
||||||
{
|
{
|
||||||
QString id = QString::fromStdString( getId() );
|
QString id = QString::fromStdString( getId() );
|
||||||
QString uniquePrefix = QString::fromStdString( getId() + "_" + articleId + "_" );
|
QString uniquePrefix = QString::fromStdString( getId() + "_" + articleId + "_" );
|
||||||
|
QRegExp anchorLinkRe( "(<\\s*a\\s+[^>]*\\b(name|id)\\b\\s*=\\s*[\"'])", Qt::CaseInsensitive );
|
||||||
|
anchorLinkRe.setMinimal( true );
|
||||||
|
|
||||||
return string( QString::fromUtf8( article )
|
return string( QString::fromUtf8( article )
|
||||||
// word cross links
|
// word cross links
|
||||||
|
@ -822,24 +824,24 @@ string MdxDictionary::filterResource( const char * articleId, const char * artic
|
||||||
// anchors
|
// anchors
|
||||||
.replace( QRegExp( "(href\\s*=\\s*[\"'])entry://#", Qt::CaseInsensitive ),
|
.replace( QRegExp( "(href\\s*=\\s*[\"'])entry://#", Qt::CaseInsensitive ),
|
||||||
"\\1#" + uniquePrefix )
|
"\\1#" + uniquePrefix )
|
||||||
.replace( QRegExp( "(<\\s*a\\s+[^>]*(name|id)\\s*=\\s*[\"'])", Qt::CaseInsensitive ),
|
.replace( anchorLinkRe,
|
||||||
"\\1" + uniquePrefix )
|
"\\1" + uniquePrefix )
|
||||||
// sounds, and audio link script
|
// sounds, and audio link script
|
||||||
.replace( QRegExp( "(<\\s*(?:a|area)\\s+[^>]*href\\s*=\\s*\")sound://([^\"']*)", Qt::CaseInsensitive ),
|
.replace( QRegExp( "(<\\s*(?:a|area)\\s+[^>]*\\bhref\\b\\s*=\\s*\")sound://([^\"']*)", Qt::CaseInsensitive ),
|
||||||
QString::fromStdString( addAudioLink( "\"gdau://" + getId() + "/\\2\"", getId() ) ) +
|
QString::fromStdString( addAudioLink( "\"gdau://" + getId() + "/\\2\"", getId() ) ) +
|
||||||
"\\1gdau://" + id + "/\\2" )
|
"\\1gdau://" + id + "/\\2" )
|
||||||
// stylesheets
|
// stylesheets
|
||||||
.replace( QRegExp( "(<\\s*link\\s+[^>]*href\\s*=\\s*[\"']+)(?:file://)?[\\x00-\\x30\\x7f]*([^\"']*)",
|
.replace( QRegExp( "(<\\s*link\\s+[^>]*\\bhref\\b\\s*=\\s*[\"']+)(?:file://)?[\\x00-\\x30\\x7f]*([^\"']*)",
|
||||||
Qt::CaseInsensitive, QRegExp::RegExp2 ),
|
Qt::CaseInsensitive, QRegExp::RegExp2 ),
|
||||||
"\\1bres://" + id + "/\\2" )
|
"\\1bres://" + id + "/\\2" )
|
||||||
.replace( QRegExp( "(<\\s*link\\s+[^>]*href\\s*=\\s*)(?!['\"]+)(?!bres:|data:)(?:file://)?([^\\s>]+)",
|
.replace( QRegExp( "(<\\s*link\\s+[^>]*\\bhref\\b\\s*=\\s*)(?!['\"]+)(?!bres:|data:)(?:file://)?([^\\s>]+)",
|
||||||
Qt::CaseInsensitive, QRegExp::RegExp2 ),
|
Qt::CaseInsensitive, QRegExp::RegExp2 ),
|
||||||
"\\1\"bres://" + id + "/\\\"" )
|
"\\1\"bres://" + id + "/\\\"" )
|
||||||
// images
|
// images
|
||||||
.replace( QRegExp( "(<\\s*img\\s+[^>]*src\\s*=\\s*[\"']+)(?:file://)?[\\x00-\\x30\\x7f]*([^\"']*)",
|
.replace( QRegExp( "(<\\s*img\\s+[^>]*\\bsrc\\b\\s*=\\s*[\"']+)(?:file://)?[\\x00-\\x30\\x7f]*([^\"']*)",
|
||||||
Qt::CaseInsensitive, QRegExp::RegExp2 ),
|
Qt::CaseInsensitive, QRegExp::RegExp2 ),
|
||||||
"\\1bres://" + id + "/\\2" )
|
"\\1bres://" + id + "/\\2" )
|
||||||
.replace( QRegExp( "(<\\s*img\\s+[^>]*src\\s*=\\s*)(?!['\"]+)(?!bres:|data:)(?:file://)?([^\\s>]+)",
|
.replace( QRegExp( "(<\\s*img\\s+[^>]*\\bsrc\\b\\s*=\\s*)(?!['\"]+)(?!bres:|data:)(?:file://)?([^\\s>]+)",
|
||||||
Qt::CaseInsensitive, QRegExp::RegExp2 ),
|
Qt::CaseInsensitive, QRegExp::RegExp2 ),
|
||||||
"\\1\"bres://" + id + "/\\2\"" )
|
"\\1\"bres://" + id + "/\\2\"" )
|
||||||
.toUtf8().constData() );
|
.toUtf8().constData() );
|
||||||
|
|
Loading…
Reference in a new issue