Skip to content

Commit 6c2768f

Browse files
committed
issue doxygen#12221 Mermaid CDN loading in offline builds and unclear render mode behavio
1 parent 1251eee commit 6c2768f

4 files changed

Lines changed: 28 additions & 3 deletions

File tree

src/commentscan.l

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ typedef yyguts_t *yyscan_t;
5656
#include "entry.h"
5757
#include "formula.h"
5858
#include "language.h"
59+
#include "mermaid.h"
5960
#include "message.h"
6061
#include "parserintf.h"
6162
#include "reflist.h"
@@ -112,6 +113,7 @@ static bool handleAnchor(yyscan_t yyscanner,const QCString &, const StringVector
112113
static bool handleImage(yyscan_t yyscanner,const QCString &, const StringVector &);
113114
static bool handleCite(yyscan_t yyscanner,const QCString &, const StringVector &);
114115
static bool handleFormatBlock(yyscan_t yyscanner,const QCString &, const StringVector &);
116+
static bool handleMermaidFile(yyscan_t yyscanner,const QCString &s,const StringVector &);
115117
static bool handleAddIndex(yyscan_t yyscanner,const QCString &, const StringVector &);
116118
static bool handleIf(yyscan_t yyscanner,const QCString &, const StringVector &);
117119
static bool handleIfNot(yyscan_t yyscanner,const QCString &, const StringVector &);
@@ -327,7 +329,7 @@ static const std::unordered_map< std::string, DocCmdMap > docCmdMap =
327329
{ "msc", { &handleFormatBlock, CommandSpacing::Block, SectionHandling::Break }},
328330
{ "mscfile", { nullptr, CommandSpacing::Block, SectionHandling::Break }},
329331
{ "mermaid", { &handleFormatBlock, CommandSpacing::Block, SectionHandling::Break }},
330-
{ "mermaidfile", { nullptr, CommandSpacing::Block, SectionHandling::Break }},
332+
{ "mermaidfile", { &handleMermaidFile, CommandSpacing::Block, SectionHandling::Break }},
331333
{ "name", { &handleName, CommandSpacing::Invisible, SectionHandling::Escape }},
332334
{ "namespace", { &handleNamespace, CommandSpacing::Invisible, SectionHandling::Escape }},
333335
{ "noop", { &handleNoop, CommandSpacing::Invisible, SectionHandling::Replace }},
@@ -3608,6 +3610,10 @@ static bool handleFormatBlock(yyscan_t yyscanner,const QCString &s, const String
36083610
addOutput(yyscanner,yyextra->spaceBeforeCmd);
36093611
yyextra->spaceBeforeCmd.clear();
36103612
}
3613+
if (s=="mermaid")
3614+
{
3615+
MermaidManager::instance().setHasInlineDiagrams();
3616+
}
36113617
if (optList.empty())
36123618
{
36133619
addOutput(yyscanner,"@"+s+" ");
@@ -3623,6 +3629,14 @@ static bool handleFormatBlock(yyscan_t yyscanner,const QCString &s, const String
36233629
return FALSE;
36243630
}
36253631

3632+
static bool handleMermaidFile(yyscan_t yyscanner,const QCString &s,const StringVector &)
3633+
{
3634+
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
3635+
MermaidManager::instance().setHasInlineDiagrams();
3636+
addOutput(yyscanner,yytext);
3637+
return false;
3638+
}
3639+
36263640
static bool handleAddIndex(yyscan_t yyscanner,const QCString &, const StringVector &)
36273641
{
36283642
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;

src/htmlgen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#include "portable.h"
5757
#include "outputlist.h"
5858
#include "stringutil.h"
59+
#include "mermaid.h"
5960

6061
//#define DBG_HTML(x) x;
6162
#define DBG_HTML(x)
@@ -579,8 +580,7 @@ static QCString substituteHtmlKeywords(const QCString &file,
579580
darkModeJs="<script type=\"text/javascript\" src=\"$relpath^darkmode_toggle.js\"></script>\n";
580581
}
581582

582-
QCString mermaidRenderMode = Config_getEnumAsString(MERMAID_RENDER_MODE);
583-
if (mermaidRenderMode=="CLIENT_SIDE" || mermaidRenderMode=="AUTO")
583+
if (MermaidManager::instance().hasInlineDiagrams())
584584
{
585585
QCString mermaidJsUrl = Config_getString(MERMAID_JS_URL);
586586
mermaidJs = "<script type=\"module\">\n"

src/mermaid.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,13 @@ static void runMermaid(const MermaidManager::DiagramList &diagrams)
242242
}
243243
}
244244

245+
void MermaidManager::setHasInlineDiagrams()
246+
{
247+
// CLI mode creates images locally, other modes create inline diagram descriptions
248+
// in the HTML output and rely on rendering them in the browser.
249+
m_hasInlineDiagrams=Config_getEnum(MERMAID_RENDER_MODE)!=MERMAID_RENDER_MODE_t::CLI;
250+
}
251+
245252
void MermaidManager::run()
246253
{
247254
Debug::print(Debug::Mermaid, 0, "*** MermaidManager::run\n");

src/mermaid.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ class MermaidManager
4646

4747
static MermaidManager &instance();
4848

49+
void setHasInlineDiagrams();
50+
bool hasInlineDiagrams() const { return m_hasInlineDiagrams; }
51+
4952
/** Run mmdc tool for all collected diagrams */
5053
void run();
5154

@@ -85,6 +88,7 @@ class MermaidManager
8588
MermaidManager();
8689

8790
DiagramList m_diagrams;
91+
bool m_hasInlineDiagrams = false;
8892
};
8993

9094
#endif

0 commit comments

Comments
 (0)