Skip to content

templates

tit.reporting.core.templates

CSS and JavaScript templates for TI-Toolbox reports.

Contains the default styling and interactivity for generated reports. Templates are consumed by ReportAssembler.render_html to produce a self-contained HTML document.

Public API

DEFAULT_CSS_STYLES : str Complete CSS stylesheet for TI-Toolbox reports. DEFAULT_JS_SCRIPTS : str JavaScript for copy-to-clipboard, section toggling, and scroll-tracking. get_html_template Render a complete HTML document from content fragments.

See Also

tit.reporting.core.assembler : Uses get_html_template during rendering.

get_html_template

get_html_template(title: str, content: str, toc_html: str = '', metadata_html: str = '', footer_html: str = '', custom_css: str = '', custom_js: str = '') -> str

Generate a complete HTML document with the report content.

Parameters

title : str The report title (used in <title> and the header <h1>). content : str The main HTML content (rendered sections). toc_html : str, optional Table of contents HTML fragment. metadata_html : str, optional Header metadata HTML fragment. footer_html : str, optional Footer HTML. Defaults to a TI-Toolbox credit line. custom_css : str, optional Additional CSS appended after the default styles. custom_js : str, optional Additional JavaScript appended after the default scripts.

Returns

str Complete HTML document as a string.

Source code in tit/reporting/core/templates.py
def get_html_template(
    title: str,
    content: str,
    toc_html: str = "",
    metadata_html: str = "",
    footer_html: str = "",
    custom_css: str = "",
    custom_js: str = "",
) -> str:
    """Generate a complete HTML document with the report content.

    Parameters
    ----------
    title : str
        The report title (used in ``<title>`` and the header ``<h1>``).
    content : str
        The main HTML content (rendered sections).
    toc_html : str, optional
        Table of contents HTML fragment.
    metadata_html : str, optional
        Header metadata HTML fragment.
    footer_html : str, optional
        Footer HTML.  Defaults to a TI-Toolbox credit line.
    custom_css : str, optional
        Additional CSS appended after the default styles.
    custom_js : str, optional
        Additional JavaScript appended after the default scripts.

    Returns
    -------
    str
        Complete HTML document as a string.
    """
    css = DEFAULT_CSS_STYLES
    if custom_css:
        css += f"\n/* Custom Styles */\n{custom_css}"

    js = DEFAULT_JS_SCRIPTS
    if custom_js:
        js += f"\n// Custom Scripts\n{custom_js}"

    nav_html = ""
    if toc_html:
        nav_html = f"""
        <nav class="report-nav">
            <h2>Contents</h2>
            {toc_html}
        </nav>
        """

    footer = footer_html or """
        <footer class="report-footer">
            <p>Generated by <a href="https://github.com/idossha/TI-toolbox" target="_blank">TI-Toolbox</a></p>
        </footer>
    """

    return f"""<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{title}</title>
    <style>
{css}
    </style>
</head>
<body>
    <div class="report-container">
        <header class="report-header">
            <h1>{title}</h1>
            {metadata_html}
        </header>

        {nav_html}

        <main class="report-main">
            {content}
        </main>

        {footer}
    </div>

    <script>
{js}
    </script>
</body>
</html>
"""