mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-30 17:24:08 +00:00
DICT servers: ignore refs in html
This commit is contained in:
parent
c6f8d29a5a
commit
73ec1b5950
141
dictserver.cc
141
dictserver.cc
|
@ -833,92 +833,95 @@ void DictServerArticleRequest::run()
|
||||||
else
|
else
|
||||||
articleStr = Html::preformat( articleText.toUtf8().data() );
|
articleStr = Html::preformat( articleText.toUtf8().data() );
|
||||||
|
|
||||||
articleText = QString::fromUtf8( articleStr.c_str(), articleStr.size() )
|
articleText = QString::fromUtf8( articleStr.c_str(), articleStr.size() );
|
||||||
.replace(refs, "<a href=\"gdlookup://localhost/\\1\">\\1</a>" );
|
if( !contentInHtml )
|
||||||
|
{
|
||||||
|
articleText = articleText.replace(refs, "<a href=\"gdlookup://localhost/\\1\">\\1</a>" );
|
||||||
|
|
||||||
pos = 0;
|
pos = 0;
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
|
#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
|
||||||
QString articleNewText;
|
QString articleNewText;
|
||||||
|
|
||||||
// Handle phonetics
|
// Handle phonetics
|
||||||
|
|
||||||
QRegularExpressionMatchIterator it = phonetic.globalMatch( articleText );
|
QRegularExpressionMatchIterator it = phonetic.globalMatch( articleText );
|
||||||
while( it.hasNext() )
|
while( it.hasNext() )
|
||||||
{
|
{
|
||||||
QRegularExpressionMatch match = it.next();
|
QRegularExpressionMatch match = it.next();
|
||||||
articleNewText += articleText.midRef( pos, match.capturedStart() - pos );
|
articleNewText += articleText.midRef( pos, match.capturedStart() - pos );
|
||||||
pos = match.capturedEnd();
|
pos = match.capturedEnd();
|
||||||
|
|
||||||
QString phonetic_text = match.captured( 1 );
|
QString phonetic_text = match.captured( 1 );
|
||||||
phonetic_text.replace( divs_inside_phonetic, "</span></div\\1><div\\2><span class=\"dictd_phonetic\">" );
|
phonetic_text.replace( divs_inside_phonetic, "</span></div\\1><div\\2><span class=\"dictd_phonetic\">" );
|
||||||
|
|
||||||
articleNewText += "<span class=\"dictd_phonetic\">" + phonetic_text + "</span>";
|
articleNewText += "<span class=\"dictd_phonetic\">" + phonetic_text + "</span>";
|
||||||
}
|
}
|
||||||
if( pos )
|
if( pos )
|
||||||
{
|
{
|
||||||
articleNewText += articleText.midRef( pos );
|
articleNewText += articleText.midRef( pos );
|
||||||
articleText = articleNewText;
|
articleText = articleNewText;
|
||||||
articleNewText.clear();
|
articleNewText.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle links
|
// Handle links
|
||||||
|
|
||||||
pos = 0;
|
pos = 0;
|
||||||
it = links.globalMatch( articleText );
|
it = links.globalMatch( articleText );
|
||||||
while( it.hasNext() )
|
while( it.hasNext() )
|
||||||
{
|
{
|
||||||
QRegularExpressionMatch match = it.next();
|
QRegularExpressionMatch match = it.next();
|
||||||
articleNewText += articleText.midRef( pos, match.capturedStart() - pos );
|
articleNewText += articleText.midRef( pos, match.capturedStart() - pos );
|
||||||
pos = match.capturedEnd();
|
pos = match.capturedEnd();
|
||||||
|
|
||||||
QString link = match.captured( 1 );
|
QString link = match.captured( 1 );
|
||||||
link.replace( tags, " " );
|
link.replace( tags, " " );
|
||||||
link.replace( " ", " " );
|
link.replace( " ", " " );
|
||||||
|
|
||||||
QString newLink = match.captured();
|
QString newLink = match.captured();
|
||||||
newLink.replace( 30, match.capturedLength( 1 ),
|
newLink.replace( 30, match.capturedLength( 1 ),
|
||||||
QString::fromUtf8( QUrl::toPercentEncoding( link.simplified() ) ) );
|
QString::fromUtf8( QUrl::toPercentEncoding( link.simplified() ) ) );
|
||||||
articleNewText += newLink;
|
articleNewText += newLink;
|
||||||
}
|
}
|
||||||
if( pos )
|
if( pos )
|
||||||
{
|
{
|
||||||
articleNewText += articleText.midRef( pos );
|
articleNewText += articleText.midRef( pos );
|
||||||
articleText = articleNewText;
|
articleText = articleNewText;
|
||||||
articleNewText.clear();
|
articleNewText.clear();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
// Handle phonetics
|
// Handle phonetics
|
||||||
|
|
||||||
for( ; ; )
|
for( ; ; )
|
||||||
{
|
{
|
||||||
pos = articleText.indexOf( phonetic, pos );
|
pos = articleText.indexOf( phonetic, pos );
|
||||||
if( pos < 0 )
|
if( pos < 0 )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
QString phonetic_text = phonetic.cap( 1 );
|
QString phonetic_text = phonetic.cap( 1 );
|
||||||
phonetic_text.replace( divs_inside_phonetic, "</span></div\\1><div\\2><span class=\"dictd_phonetic\">" );
|
phonetic_text.replace( divs_inside_phonetic, "</span></div\\1><div\\2><span class=\"dictd_phonetic\">" );
|
||||||
phonetic_text = "<span class=\"dictd_phonetic\">" + phonetic_text + "</span>";
|
phonetic_text = "<span class=\"dictd_phonetic\">" + phonetic_text + "</span>";
|
||||||
articleText.replace( pos, phonetic.cap().length(), phonetic_text );
|
articleText.replace( pos, phonetic.cap().length(), phonetic_text );
|
||||||
pos += phonetic_text.length();
|
pos += phonetic_text.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle links
|
// Handle links
|
||||||
|
|
||||||
pos = 0;
|
pos = 0;
|
||||||
for( ; ; )
|
for( ; ; )
|
||||||
{
|
{
|
||||||
pos = articleText.indexOf( links, pos );
|
pos = articleText.indexOf( links, pos );
|
||||||
if( pos < 0 )
|
if( pos < 0 )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
QString link = links.cap( 1 );
|
QString link = links.cap( 1 );
|
||||||
link.replace( tags, " " );
|
link.replace( tags, " " );
|
||||||
link.replace( " ", " " );
|
link.replace( " ", " " );
|
||||||
articleText.replace( pos + 30, links.cap( 1 ).length(),
|
articleText.replace( pos + 30, links.cap( 1 ).length(),
|
||||||
QString::fromUtf8( QUrl::toPercentEncoding( link.simplified() ) ) );
|
QString::fromUtf8( QUrl::toPercentEncoding( link.simplified() ) ) );
|
||||||
pos += 30;
|
pos += 30;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
articleData += string( "<div class=\"dictd_article\">" )
|
articleData += string( "<div class=\"dictd_article\">" )
|
||||||
+ articleText.toUtf8().data()
|
+ articleText.toUtf8().data()
|
||||||
|
|
Loading…
Reference in a new issue