diff --git a/src/dict/mdx.cc b/src/dict/mdx.cc index 49a15bb11..a48338e2a 100644 --- a/src/dict/mdx.cc +++ b/src/dict/mdx.cc @@ -877,7 +877,8 @@ QString & MdxDictionary::filterResource( QString & article ) void MdxDictionary::replaceLinks( QString & id, QString & article ) { QString articleNewText; - int linkPos = 0; + qsizetype linkPos = 0; + QRegularExpressionMatchIterator it = RX::Mdx::allLinksRe.globalMatch( article ); while ( it.hasNext() ) { QRegularExpressionMatch allLinksMatch = it.next(); @@ -953,7 +954,8 @@ void MdxDictionary::replaceLinks( QString & id, QString & article ) articleNewText += linkTxt; match = RX::Mdx::closeScriptTagRe.match( article, linkPos ); if ( match.hasMatch() ) { - articleNewText += article.mid( linkPos, match.capturedEnd() - linkPos ); + articleNewText += QString( QStringLiteral( "gdOnReady(()=>{%1});" ) ) + .arg( article.mid( linkPos, match.capturedStart() - linkPos ) ); linkPos = match.capturedEnd(); } continue; diff --git a/src/scripts/gd-builtin.js b/src/scripts/gd-builtin.js index edc6913d9..716454980 100644 --- a/src/scripts/gd-builtin.js +++ b/src/scripts/gd-builtin.js @@ -1,3 +1,11 @@ +function gdOnReady(func) { + if (document.readyState !== "loading") { + func(); + } else { + document.addEventListener("DOMContentLoaded", func); + } +} + function gdMakeArticleActive(newId, noEvent) { const gdCurrentArticle = document.querySelector(".gdactivearticle").attributes.id;