Skip to content

Commit

Permalink
fix: mdx audio/video html5 tag src value replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyifang committed Oct 8, 2023
1 parent 9486f5f commit e8d70f2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/common/globalregex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ QRegularExpression Ftx::token( R"((".*?")|([\w\W\+\-]+))",
| QRegularExpression::CaseInsensitiveOption );
//mdx
QRegularExpression Mdx::allLinksRe( R"((?:<\s*(a(?:rea)?|img|link|script|source)(?:\s+[^>]+|\s*)>))",
//<audio src="xxx"> is also a valid url.
QRegularExpression Mdx::allLinksRe( R"((?:<\s*(a(?:rea)?|img|link|script|source|audio|video)(?:\s+[^>]+|\s*)>))",
QRegularExpression::CaseInsensitiveOption );
QRegularExpression Mdx::wordCrossLink( R"(([\s"']href\s*=)\s*(["'])entry://([^>#]*?)((?:#[^>]*?)?)\2)",
QRegularExpression::CaseInsensitiveOption );
Expand Down
8 changes: 5 additions & 3 deletions src/dict/mdx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ void MdxDictionary::replaceLinks( QString & id, QString & article )
QString linkType = allLinksMatch.captured( 1 ).toLower();
QString newLink;

if ( !linkType.isEmpty() && linkType.at( 0 ) == 'a' ) {
if ( linkType == "a" ) {
newLink = linkTxt;

QRegularExpressionMatch match = RX::Mdx::audioRe.match( newLink );
Expand Down Expand Up @@ -956,8 +956,8 @@ void MdxDictionary::replaceLinks( QString & id, QString & article )
else
newLink = linkTxt.replace( RX::Mdx::stylesRe2, R"(\1"bres://)" + id + R"(/\2")" );
}
else if ( linkType.compare( "script" ) == 0 || linkType.compare( "img" ) == 0
|| linkType.compare( "source" ) == 0 ) {
else{
//linkType in ("script","img","source","audio","video")
// javascripts and images
QRegularExpressionMatch match = RX::Mdx::inlineScriptRe.match( linkTxt );
if ( linkType.at( 1 ) == 'c' // "script" tag
Expand All @@ -972,6 +972,7 @@ void MdxDictionary::replaceLinks( QString & id, QString & article )
continue;
}
else {
//audio ,video ,html5 tags fall here.
match = RX::Mdx::srcRe.match( linkTxt );
if ( match.hasMatch() ) {
QString newText;
Expand All @@ -992,6 +993,7 @@ void MdxDictionary::replaceLinks( QString & id, QString & article )
newLink = linkTxt.replace( RX::Mdx::srcRe2, R"(\1"bres://)" + id + R"(/\2")" );
}
}

if ( !newLink.isEmpty() ) {
articleNewText += newLink;
}
Expand Down

0 comments on commit e8d70f2

Please sign in to comment.