mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
parent
3ef35daec3
commit
e2617f3b9c
|
@ -130,26 +130,25 @@ string escapeForJavaScript( string const & str )
|
|||
return result;
|
||||
}
|
||||
|
||||
QString stripHtml( QString & tmp )
|
||||
QString stripHtml( QString tmp )
|
||||
{
|
||||
tmp.replace(
|
||||
QRegularExpression(
|
||||
"<(?:\\s*/?(?:div|h[1-6r]|q|p(?![alr])|br|li(?![ns])|td|blockquote|[uo]l|pre|d[dl]|nav|address))[^>]{0,}>",
|
||||
QRegularExpression::CaseInsensitiveOption ),
|
||||
" " );
|
||||
tmp.replace( QRegularExpression( "<[^>]*>" ), " " );
|
||||
static QRegularExpression htmlRegex(
|
||||
"<(?:\\s*/?(?:div|h[1-6r]|q|p(?![alr])|br|li(?![ns])|td|blockquote|[uo]l|pre|d[dl]|nav|address))[^>]{0,}>",
|
||||
QRegularExpression::CaseInsensitiveOption );
|
||||
tmp.replace( htmlRegex, " " );
|
||||
static QRegularExpression htmlElementRegex( "<[^>]*>" );
|
||||
tmp.replace( htmlElementRegex, " " );
|
||||
return tmp;
|
||||
}
|
||||
|
||||
QString unescape( QString const & str, HtmlOption option )
|
||||
QString unescape( QString str, HtmlOption option )
|
||||
{
|
||||
// Does it contain HTML? If it does, we need to strip it
|
||||
if ( str.contains( '<' ) || str.contains( '&' ) ) {
|
||||
QString tmp = str;
|
||||
if ( option == HtmlOption::Strip ) {
|
||||
stripHtml( tmp );
|
||||
str = stripHtml( str );
|
||||
}
|
||||
return QTextDocumentFragment::fromHtml( tmp.trimmed() ).toPlainText();
|
||||
return QTextDocumentFragment::fromHtml( str.trimmed() ).toPlainText();
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
|
|
@ -25,9 +25,9 @@ string preformat( string const &, bool baseRightToLeft = false );
|
|||
|
||||
// Escapes the given string to be included in JavaScript.
|
||||
string escapeForJavaScript( string const & );
|
||||
QString stripHtml( QString & tmp );
|
||||
QString stripHtml( QString tmp );
|
||||
// Replace html entities
|
||||
QString unescape( QString const & str, HtmlOption option = HtmlOption::Strip );
|
||||
QString unescape( QString str, HtmlOption option = HtmlOption::Strip );
|
||||
|
||||
QString fromHtmlEscaped( QString const & str );
|
||||
string unescapeUtf8( string const & str, HtmlOption option = HtmlOption::Strip );
|
||||
|
|
|
@ -525,20 +525,19 @@ string StardictDictionary::handleResource( char type, char const * resource, siz
|
|||
|
||||
QString src = match.captured( 2 );
|
||||
|
||||
if ( src.indexOf( "://" ) >= 0 )
|
||||
if ( src.indexOf( "://" ) >= 0 ) {
|
||||
articleNewText += match.captured();
|
||||
|
||||
}
|
||||
else {
|
||||
std::string href = "\"gdau://" + getId() + "/" + src.toUtf8().data() + "\"";
|
||||
QString newTag = QString::fromUtf8(
|
||||
( addAudioLink( href, getId() ) + "<span class=\"sdict_h_wav\"><a href=" + href + ">" ).c_str() );
|
||||
newTag += match.captured( 4 );
|
||||
if ( match.captured( 4 ).indexOf( "<img " ) < 0 )
|
||||
|
||||
std::string href = "\"gdau://" + getId() + "/" + src.toUtf8().data() + "\"";
|
||||
std::string newTag = addAudioLink( href, getId() ) + "<span class=\"sdict_h_wav\"><a href=" + href + ">";
|
||||
newTag += match.captured( 4 ).toUtf8().constData();
|
||||
if ( match.captured( 4 ).indexOf( "<img " ) < 0 ) {
|
||||
newTag += R"( <img src="qrc:///icons/playsound.png" border="0" alt="Play">)";
|
||||
}
|
||||
newTag += "</a></span>";
|
||||
|
||||
articleNewText += newTag;
|
||||
articleNewText += QString::fromStdString( newTag );
|
||||
}
|
||||
}
|
||||
if ( pos ) {
|
||||
|
@ -546,8 +545,8 @@ string StardictDictionary::handleResource( char type, char const * resource, siz
|
|||
articleText = articleNewText;
|
||||
articleNewText.clear();
|
||||
}
|
||||
|
||||
return articleText.toStdString();
|
||||
auto text = articleText.toUtf8();
|
||||
return text.data();
|
||||
}
|
||||
case 'm': // Pure meaning, usually means preformatted text
|
||||
return "<div class=\"sdct_m\">" + Html::preformat( string( resource, size ), isToLanguageRTL() ) + "</div>";
|
||||
|
|
Loading…
Reference in a new issue