diff options
author | Dimitri van Heesch <doxygen@gmail.com> | 2021-05-24 17:50:32 (GMT) |
---|---|---|
committer | Dimitri van Heesch <doxygen@gmail.com> | 2021-05-24 17:50:32 (GMT) |
commit | 9822babd32bcbec76125362c108ec7b63ff528d4 (patch) | |
tree | 36d4312da5975df079afb2b3282365c1b40efd23 | |
parent | 8fa6f9c282ee328df22b0ba007a407e2c2751bab (diff) | |
download | Doxygen-9822babd32bcbec76125362c108ec7b63ff528d4.zip Doxygen-9822babd32bcbec76125362c108ec7b63ff528d4.tar.gz Doxygen-9822babd32bcbec76125362c108ec7b63ff528d4.tar.bz2 |
Optimized MathJax HTML output and made the template output the same.
-rw-r--r-- | src/context.cpp | 20 | ||||
-rw-r--r-- | src/htmlgen.cpp | 91 | ||||
-rw-r--r-- | src/htmlgen.h | 1 | ||||
-rw-r--r-- | templates/html/htmlbase.tpl | 31 | ||||
-rw-r--r-- | templates/html/htmljsmenudata.tpl | 2 | ||||
-rw-r--r-- | templates/html/htmllayout.tpl | 4 | ||||
-rw-r--r-- | templates/html/htmlpage.tpl | 2 | ||||
-rw-r--r-- | templates/html/htmltabs.tpl | 2 |
8 files changed, 90 insertions, 63 deletions
diff --git a/src/context.cpp b/src/context.cpp index 7d1c6a7..6835d98 100644 --- a/src/context.cpp +++ b/src/context.cpp @@ -395,9 +395,13 @@ class DoxygenContext::Private { return dateToString(TRUE); } - TemplateVariant maxJaxCodeFile() const + TemplateVariant mathJaxCodeFile() const { - return m_cache.maxJaxCodeFile; + return m_cache.mathJaxCodeFile; + } + TemplateVariant mathJaxMacros() const + { + return m_cache.mathJaxMacros; } Private() { @@ -409,7 +413,9 @@ class DoxygenContext::Private //%% string date s_inst.addProperty("date", &Private::date); //%% string maxJaxCodeFile - s_inst.addProperty("mathJaxCodeFile", &Private::maxJaxCodeFile); + s_inst.addProperty("mathJaxCodeFile", &Private::mathJaxCodeFile); + //%% string maxJaxMacros + s_inst.addProperty("mathJaxMacros", &Private::mathJaxMacros); init=TRUE; } } @@ -424,8 +430,12 @@ class DoxygenContext::Private private: struct Cachable { - Cachable() { maxJaxCodeFile=fileToString(Config_getString(MATHJAX_CODEFILE)); } - QCString maxJaxCodeFile; + Cachable() { + mathJaxCodeFile=fileToString(Config_getString(MATHJAX_CODEFILE)); + mathJaxMacros=HtmlGenerator::getMathJaxMacros(); + } + QCString mathJaxCodeFile; + QCString mathJaxMacros; }; mutable Cachable m_cache; static PropertyMapper<DoxygenContext::Private> s_inst; diff --git a/src/htmlgen.cpp b/src/htmlgen.cpp index c8c8021..86825e4 100644 --- a/src/htmlgen.cpp +++ b/src/htmlgen.cpp @@ -449,19 +449,25 @@ static QCString substituteHtmlKeywords(const QCString &str, if (mathJaxVersion == "MathJax_3") { - mathJaxJs += "<script src=\"https://polyfill.io/v3/polyfill.min.js?features=es6\"></script>\n"; - mathJaxJs += "<script>\n" - " window.MathJax = {\n" - " options: {\n" - " ignoreHtmlClass: 'tex2jax_ignore',\n" - " processHtmlClass: 'tex2jax_process'\n" - " },\n"; + mathJaxJs += "<script src=\"https://polyfill.io/v3/polyfill.min.js?features=es6\"></script>\n" + "<script type=\"text/javascript\">\n" + "window.MathJax = {\n" + " options: {\n" + " ignoreHtmlClass: 'tex2jax_ignore',\n" + " processHtmlClass: 'tex2jax_process'\n" + " }"; const StringVector &mathJaxExtensions = Config_getList(MATHJAX_EXTENSIONS); if (!mathJaxExtensions.empty() || !g_latex_macro.isEmpty()) { - mathJaxJs+= " tex: {\n" - " macros: {},\n" - " packages: ['base','configmacros'"; + mathJaxJs+= ",\n" + " tex: {\n" + " macros: {"; + if (!g_latex_macro.isEmpty()) + { + mathJaxJs += g_latex_macro+" "; + } + mathJaxJs+="},\n" + " packages: ['base','configmacros'"; if (!g_latex_macro.isEmpty()) { mathJaxJs+= ",'newcommand'"; @@ -471,46 +477,30 @@ static QCString substituteHtmlKeywords(const QCString &str, mathJaxJs+= ",'"+QCString(s.c_str())+"'"; } mathJaxJs += "]\n" - " }\n"; + " }\n"; } - mathJaxJs += " };\n"; - mathJaxJs += "</script>\n"; - - if (!g_latex_macro.isEmpty()) + else { - mathJaxJs += "<script>\n" - " Object.assign(MathJax.tex.macros, {\n"; - mathJaxJs += g_latex_macro; - mathJaxJs += "\n" - " });\n" - "</script>\n"; + mathJaxJs += "\n"; } - + mathJaxJs += "};\n"; // MATHJAX_CODEFILE if (!g_mathjax_code.isEmpty()) { - mathJaxJs += "<script>\n"; mathJaxJs += g_mathjax_code; mathJaxJs += "\n"; - mathJaxJs += "</script>\n"; } + mathJaxJs += "</script>\n"; - - mathJaxJs += "<script type=\"text/javascript\" id=\"MathJax-script\" async=\"async\" src=\"" + path; - if (mathJaxFormat == "chtml") - { - mathJaxJs += "es5/tex-chtml.js\"></script>\n" ; - } - else if (mathJaxFormat == "SVG") - { - mathJaxJs += "es5/tex-svg.js\"></script>\n" ; - } + mathJaxJs += "<script type=\"text/javascript\" id=\"MathJax-script\" async=\"async\" src=\"" + + path + "es5/tex-" + mathJaxFormat.lower() + ".js\">"; + mathJaxJs+="</script>\n"; } - else + else // MathJax v2 { mathJaxJs = "<script type=\"text/x-mathjax-config\">\n" - " MathJax.Hub.Config({\n" - " extensions: [\"tex2jax.js\""; + "MathJax.Hub.Config({\n" + " extensions: [\"tex2jax.js\""; const StringVector &mathJaxExtensions = Config_getList(MATHJAX_EXTENSIONS); for (const auto &s : mathJaxExtensions) { @@ -521,25 +511,21 @@ static QCString substituteHtmlKeywords(const QCString &str, mathJaxFormat = "HTML-CSS"; } mathJaxJs += "],\n" - " jax: [\"input/TeX\",\"output/"+mathJaxFormat+"\"],\n" - "});\n"; + " jax: [\"input/TeX\",\"output/"+mathJaxFormat+"\"],\n"; + if (!g_latex_macro.isEmpty()) + { + mathJaxJs += " TeX: { Macros: {\n"; + mathJaxJs += g_latex_macro; + mathJaxJs += "\n" + " } }\n"; + } + mathJaxJs += "});\n"; if (!g_mathjax_code.isEmpty()) { mathJaxJs += g_mathjax_code; mathJaxJs += "\n"; } mathJaxJs += "</script>\n"; - if (!g_latex_macro.isEmpty()) - { - mathJaxJs += "<script type=\"text/x-mathjax-config\">\n" - " MathJax.Hub.Config({\n" - " TeX: { Macros: {\n"; - mathJaxJs += g_latex_macro; - mathJaxJs += "\n" - " } }\n" - "});\n" - "</script>\n"; - } mathJaxJs += "<script type=\"text/javascript\" async=\"async\" src=\"" + path + "MathJax.js\"></script>\n"; } } @@ -3066,3 +3052,8 @@ void HtmlGenerator::addWord(const QCString &word,bool hiPriority) Doxygen::searchIndex->addWord(word,hiPriority); } } + +QCString HtmlGenerator::getMathJaxMacros() +{ + return getConvertLatexMacro(); +} diff --git a/src/htmlgen.h b/src/htmlgen.h index 845f259..c66e622 100644 --- a/src/htmlgen.h +++ b/src/htmlgen.h @@ -83,6 +83,7 @@ class HtmlGenerator : public OutputGenerator static void writeExternalSearchPage(); static QCString writeLogoAsString(const QCString &path); static QCString writeSplitBarAsString(const QCString &name,const QCString &relpath); + static QCString getMathJaxMacros(); // ---- CodeOutputInterface void codify(const QCString &text) diff --git a/templates/html/htmlbase.tpl b/templates/html/htmlbase.tpl index 8343af9..39bfa8a 100644 --- a/templates/html/htmlbase.tpl +++ b/templates/html/htmlbase.tpl @@ -43,14 +43,37 @@ {% endif %} {% endif %} {% if config.USE_MATHJAX %} +{% if config.MATHJAX_VERSION=="MathJax_3" %} +<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script> +<script type="text/javascript"> +window.MathJax = { + options: { + ignoreHtmlClass: 'tex2jax_ignore', + processHtmlClass: 'tex2jax_process' + }, + tex: { +{% if doxygen.mathJaxMacros %} + macros: { {{ doxygen.mathJaxMacros|raw }} }, +{% endif %} + packages: ['base','configmacros'{% if doxygen.mathJaxMacros %},'newcommand'{% endif %}{% for ext in config.MATHJAX_EXTENSIONS %},'{{ ext }}'{% endfor %}] + } +}; +{{ doxygen.mathJaxCodeFile }} +</script> +<script type="text/javascript" id="MathJax-script" async="async" src="{{ config.MATHJAX_RELPATH }}{% if config.MATHJAX_RELPATH|relative %}{{ page.relPath }}{% endif %}es5/tex-{{ config.MATHJAX_FORMAT|lower }}.js"></script> +{% else %}{# MathJax_2 #} <script type="text/x-mathjax-config"> - MathJax.Hub.Config({ - extensions: ["tex2jax.js"{% for ext in config.MATHJAX_EXTENSIONS %}, "{{ ext }}"{% endfor %}], - jax: ["input/TeX","output/{{ config.MATHJAX_FORMAT|default:'HTML-CSS' }}"], +MathJax.Hub.Config({ + extensions: ["tex2jax.js"{% for ext in config.MATHJAX_EXTENSIONS %}, "{{ ext }}.js"{% endfor %}], + jax: ["input/TeX","output/{{ config.MATHJAX_FORMAT|default:'HTML-CSS' }}"], +{% if doxygen.mathJaxMacros %} + TeX: { Macros: { {{ doxygen.mathJaxMacros|raw }} } } +{% endif %} }); {{ doxygen.mathJaxCodeFile }} </script> -<script type="text/javascript" src="{{ config.MATHJAX_RELPATH }}{% if config.MATHJAX_RELPATH|relative %}{{ page.relPath }}{% endif %}MathJax.js"></script> +<script type="text/javascript" async="async" src="{{ config.MATHJAX_RELPATH }}{% if config.MATHJAX_RELPATH|relative %}{{ page.relPath }}{% endif %}MathJax.js"></script> +{% endif %}{# MathJax_3 #} {% endif %}{# MathJax #} <link href="{{ page.relPath }}{{ config.HTML_STYLESHEET|default:'doxygen.css' }}" rel="stylesheet" type="text/css" /> {% if config.HTML_EXTRA_STYLESHEET %} diff --git a/templates/html/htmljsmenudata.tpl b/templates/html/htmljsmenudata.tpl index e795918..2d0a53e 100644 --- a/templates/html/htmljsmenudata.tpl +++ b/templates/html/htmljsmenudata.tpl @@ -46,7 +46,7 @@ var menudata={children:[ ,{text:"{{ tr.classes }}",url:"annotated{{ config.HTML_FILE_EXTENSION }}",children:[ {text:"{{ tr.classList }}",url:"annotated{{ config.HTML_FILE_EXTENSION }}"} ,{text:"{{ tr.classIndex }}",url:"classes{{ config.HTML_FILE_EXTENSION }}"} -{% if classHierarchy.tree %} +{% if classHierarchy.tree and classHierarchy.maxDepth>1 %} ,{text:"{{ tr.classHierarchy }}",url:"hierarchy{{ config.HTML_FILE_EXTENSION }}"} {% endif %} {% if classMembersIndex.all %} diff --git a/templates/html/htmllayout.tpl b/templates/html/htmllayout.tpl index 0fbe458..f96de7e 100644 --- a/templates/html/htmllayout.tpl +++ b/templates/html/htmllayout.tpl @@ -30,9 +30,11 @@ {% resource 'nav_f.lum' %} {% resource 'nav_g.png' %} {% resource 'nav_h.lum' %} +{% if config.GENERATE_TREEVIEW %} {% resource 'navtree.css' %} {% resource 'navtree.js' %} {% resource 'resize.js' %} +{% endif %} {% resource 'menu.js' %} {% resource 'doc.luma' %} {% resource 'folderopen.luma' %} @@ -221,7 +223,7 @@ {% endif %} {# write the class inheritance hierarchy #} - {% if classHierarchy.tree %} + {% if classHierarchy.tree and classHierarchy.maxDepth>1 %} {% with page=classHierarchy %} {% create classHierarchy.fileName|append:config.HTML_FILE_EXTENSION from 'htmlhierarchy.tpl' %} {% if config.HAVE_DOT and config.GRAPHICAL_HIERARCHY %} diff --git a/templates/html/htmlpage.tpl b/templates/html/htmlpage.tpl index 449f601..74396e7 100644 --- a/templates/html/htmlpage.tpl +++ b/templates/html/htmlpage.tpl @@ -33,7 +33,7 @@ <ul> <li><a href="{{ page.relPath }}annotated{{ config.HTML_FILE_EXTENSION }}"><span>{{ tr.classList }}</span></a></li> <li><a href="{{ page.relPath }}classes{{ config.HTML_FILE_EXTENSION }}"><span>{{ tr.classIndex }}</span></a></li> - {% if classHierarchy.tree %} + {% if classHierarchy.tree and classHierarchy.maxDepth>1 %} <li><a href="{{ page.relPath }}hierarchy{{ config.HTML_FILE_EXTENSION }}"><span>{{ tr.classHierarchy }} </span></a></li> {% endif %} {% if classMembersIndex.all %} diff --git a/templates/html/htmltabs.tpl b/templates/html/htmltabs.tpl index b8632cb..7ade5f1 100644 --- a/templates/html/htmltabs.tpl +++ b/templates/html/htmltabs.tpl @@ -81,7 +81,7 @@ {% if page.highlight=='classes' %} <li{% if page.subhighlight=='classlist' %} class="current"{% endif %}><a href="{{ page.relPath }}annotated{{ config.HTML_FILE_EXTENSION }}"><span>{{ tr.classList|nowrap }}</span></a></li> <li{% if page.subhighlight=='classindex' %} class="current"{% endif %}><a href="{{ page.relPath }}classes{{ config.HTML_FILE_EXTENSION }}"><span>{{ tr.classIndex|nowrap }}</span></a></li> - {% if classHierarchy.tree %} + {% if classHierarchy.tree and classHierarchy.maxDepth>1 %} <li{% if page.subhighlight=='classhierarchy' %} class="current"{% endif %}><a href="{{ page.relPath }}hierarchy{{ config.HTML_FILE_EXTENSION }}"><span>{{ tr.classHierarchy|nowrap }}</span></a></li> {% endif %} {% if classMembersIndex.all %} |