mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 12:44:07 +00:00
Merge pull request #269 from timonwong/master
MDict: Add unique prefix for anchor and any references link to it
This commit is contained in:
commit
f4529e8fd4
20
mdx.cc
20
mdx.cc
|
@ -19,6 +19,7 @@
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#include <stub_msvc.h>
|
#include <stub_msvc.h>
|
||||||
|
@ -265,7 +266,7 @@ private:
|
||||||
void loadArticle( uint32_t offset, string & headword, string & articleText );
|
void loadArticle( uint32_t offset, string & headword, string & articleText );
|
||||||
|
|
||||||
/// Process resource links (images, audios, etc)
|
/// Process resource links (images, audios, etc)
|
||||||
string filterResource( const char * article );
|
string filterResource( const char * articleId, const char * article );
|
||||||
|
|
||||||
friend class MdxHeadwordsRequest;
|
friend class MdxHeadwordsRequest;
|
||||||
friend class MdxArticleRequest;
|
friend class MdxArticleRequest;
|
||||||
|
@ -760,21 +761,30 @@ void MdxDictionary::loadArticle( uint32_t offset, string & headword, string & ar
|
||||||
Mutex::Lock _( idxMutex );
|
Mutex::Lock _( idxMutex );
|
||||||
|
|
||||||
char * articleData = chunks.getBlock( offset, chunk );
|
char * articleData = chunks.getBlock( offset, chunk );
|
||||||
|
|
||||||
|
// Make an sub unique id for this article
|
||||||
|
char articleId[32] = { 0 };
|
||||||
|
_ui64toa( ( uintptr_t )articleData, articleId, 16 );
|
||||||
|
|
||||||
headword = articleData;
|
headword = articleData;
|
||||||
articleText = string( articleData + headword.size() + 1 );
|
articleText = string( articleData + headword.size() + 1 );
|
||||||
articleText = MdxParser::substituteStylesheet( articleText, styleSheets );
|
articleText = MdxParser::substituteStylesheet( articleText, styleSheets );
|
||||||
articleText = filterResource( articleText.c_str() );
|
articleText = filterResource( articleId, articleText.c_str() );
|
||||||
}
|
}
|
||||||
|
|
||||||
string MdxDictionary::filterResource( const char * article )
|
string MdxDictionary::filterResource( const char * articleId, const char * article )
|
||||||
{
|
{
|
||||||
|
QString uniquePrefix = QString::fromStdString( getId() + "_" + articleId + "_" );
|
||||||
|
|
||||||
return string( QString::fromUtf8( article )
|
return string( QString::fromUtf8( article )
|
||||||
// word cross links
|
// word cross links
|
||||||
.replace( QRegExp( "(href\\s*=\\s*[\"'])entry://([^#\"']+)#?[^\"']*", Qt::CaseInsensitive ),
|
.replace( QRegExp( "(href\\s*=\\s*[\"'])entry://([^#\"']+)#?[^\"']*", Qt::CaseInsensitive ),
|
||||||
"\\1gdlookup://localhost/\\2" )
|
"\\1gdlookup://localhost/\\2" )
|
||||||
// anchors
|
// anchors
|
||||||
.replace( QRegExp( "(href\\s*=\\s*[\"'])entry://#" , Qt::CaseInsensitive ),
|
.replace( QRegExp( "(href\\s*=\\s*[\"'])entry://#", Qt::CaseInsensitive ),
|
||||||
"\\1#" )
|
"\\1#" + uniquePrefix )
|
||||||
|
.replace( QRegExp( "(<\\s*a\\s+[^>]*(name|id)\\s*=\\s*\")", Qt::CaseInsensitive ),
|
||||||
|
"\\1" + uniquePrefix )
|
||||||
// sounds, and audio link script
|
// sounds, and audio link script
|
||||||
.replace( QRegExp( "(<\\s*a\\s+[^>]*href\\s*=\\s*\")sound://([^\"']*)", Qt::CaseInsensitive ),
|
.replace( QRegExp( "(<\\s*a\\s+[^>]*href\\s*=\\s*\")sound://([^\"']*)", Qt::CaseInsensitive ),
|
||||||
QString::fromStdString( addAudioLink( "\"gdau://" + getId() + "/\\2\"", getId() ) ) +
|
QString::fromStdString( addAudioLink( "\"gdau://" + getId() + "/\\2\"", getId() ) ) +
|
||||||
|
|
Loading…
Reference in a new issue