Example #1
0
QString HtmlTemplate::buildHtmlHeader(RenderOptions options) const
{
    QString header;

    // add javascript for scrollbar synchronization
    if (options.testFlag(Template::ScrollbarSynchronization)) {
        header += "<script type=\"text/javascript\">window.onscroll = function() { synchronizer.webViewScrolled(); }; </script>\n";
    }

    // add MathJax.js script to HTML header
    if (options.testFlag(Template::MathSupport)) {
        header += "<script type=\"text/javascript\" src=\"http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML\"></script>\n";
    }

    // add Highlight.js script to HTML header
    if (options.testFlag(Template::CodeHighlighting)) {
        header += QString("<link rel=\"stylesheet\" href=\"qrc:/scripts/highlight.js/styles/%1.css\">\n").arg(codeHighlightingStyle());
        header += "<script src=\"qrc:/scripts/highlight.js/highlight.pack.js\"></script>\n";
        header += "<script>hljs.initHighlightingOnLoad();</script>\n";
    }

    // add mermaid.js script to HTML header
    if (options.testFlag(Template::DiagramSupport)) {
        header += "<script src=\"qrc:/scripts/mermaid/mermaid.full.min.js\"></script>\n";
    }

    return header;
}
Example #2
0
QString HtmlTemplate::render(const QString &body, RenderOptions options) const
{
    // add scrollbar synchronization
    options |= Template::ScrollbarSynchronization;

    QString htmlBody(body);

    // Mermaid and highlighting.js don't work nicely together
    // So we need to replace the <code> section by a <div> section
    if (options.testFlag(Template::CodeHighlighting) && options.testFlag(Template::DiagramSupport)) {
        convertDiagramCodeSectionToDiv(htmlBody);
    }

    return renderAsHtml(QString(), htmlBody, options);
}