Skip to content

Commit

Permalink
fix: [mdx]object data html (#1602)
Browse files Browse the repository at this point in the history
* fix: mdx object data subsitition

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
xiaoyifang and autofix-ci[bot] authored Jun 21, 2024
1 parent c8e10b6 commit 21aeb27
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/common/globalregex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ QRegularExpression Ftx::token( R"((".*?")|([\w\W\+\-]+))",
//mdx
//<audio src="xxx"> is also a valid url.
QRegularExpression Mdx::allLinksRe( R"((?:<\s*(a(?:rea)?|img|link|script|source|audio|video)(?:\s+[^>]+|\s*)>))",
QRegularExpression Mdx::allLinksRe( R"((?:<\s*(a(?:rea)?|img|link|script|source|audio|video|object)(?:\s+[^>]+|\s*)>))",
QRegularExpression::CaseInsensitiveOption );
QRegularExpression Mdx::wordCrossLink( R"(([\s"']href\s*=)\s*(["'])entry://([^>#]*?)((?:#[^>]*?)?)\2)",
QRegularExpression::CaseInsensitiveOption );
Expand Down Expand Up @@ -58,6 +58,10 @@ QRegularExpression Mdx::srcRe2(
QRegularExpression Mdx::srcset( R"((?<before>[\s]srcset\s*=\s*["'])\s*(?<text>[\s\S]*)(?<after>["']))",
QRegularExpression::CaseInsensitiveOption );

// matches srcset in <object data="text">
QRegularExpression Mdx::objectdata( R"((?<before>[\s]data\s*=\s*["'])\s*(?<text>[\s\S]*)(?<after>["']))",
QRegularExpression::CaseInsensitiveOption );

QRegularExpression Mdx::links( R"(url\(\s*(['"]?)([^'"]*)(['"]?)\s*\))", QRegularExpression::CaseInsensitiveOption );

QRegularExpression Mdx::fontFace( R"((?:url\s*\(\s*\"(.*?)\"\s*)\))",
Expand Down
1 change: 1 addition & 0 deletions src/common/globalregex.hh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public:
static QRegularExpression srcRe;
static QRegularExpression srcRe2;
static QRegularExpression srcset;
static QRegularExpression objectdata;

static QRegularExpression links;
static QRegularExpression fontFace;
Expand Down
15 changes: 15 additions & 0 deletions src/dict/mdx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,21 @@ void MdxDictionary::replaceLinks( QString & id, QString & article )
match.captured( "before" ) % srcsetNewText.join( ',' ) % match.captured( "after" ) );
}
}

if ( linkType.compare( "object" ) == 0 ) {
match = RX::Mdx::objectdata.match( newLink );
if ( match.hasMatch() ) {
auto srcsetOriginalText = match.captured( "text" );
QString srcsetNewText;
if ( !srcsetOriginalText.contains( "//" ) ) {
srcsetNewText = QString( R"(bres://%1/%2)" ).arg( id, srcsetOriginalText );
}

newLink.replace( match.capturedStart(),
match.capturedLength(),
match.captured( "before" ) % srcsetNewText % match.captured( "after" ) );
}
}
}

if ( !newLink.isEmpty() ) {
Expand Down

0 comments on commit 21aeb27

Please sign in to comment.