Markdown / HTML

To render markdown documents, use render_markdown from lila.core.templates. Signature:


def render_markdown(
    request: Request,
    markdown_path: str,
    context: dict | None = None,
    css_files: list[str] | None = None,
    js_files: list[str] | None = None,
) -> HTMLResponse: ...
                    

markdown_path is resolved inside resources/markdown/ (the .md extension is optional). Absolute paths and ../ traversal are rejected with 400; a missing document returns 404. The rendered HTML is wrapped in the bundled markdown/layout.jinja layout, which you can override in your project by creating the same file under resources/html/.

css_files and js_files are lists of URLs (or public paths) added to the layout. A v1-compatible alias, renderMarkdown, also exists but new code should use the snake_case name. Markdown conversion requires the optional markdown package (pip install "lila-framework[markdown]"); without it the raw text is escaped and shown inside a <pre>.

Note: the Markdown file itself is not processed as a Jinja2 template. Placeholders such as {{ translate["welcome"] }} would be shown literally. Pass values through context= to the layout, or keep one .md file per language.

Example document (resources/markdown/example.md):

example.md

# Welcome

This is a simple **Markdown** example.

## Features
- Easy to write
- Converts to HTML
- Supports links and code blocks

\`\`\`python
print("Hello, Markdown!")
\`\`\`

Python route rendering it:

Python

from lila.core.request import Request
from lila.core.templates import render_markdown

@router.get("/markdown")
async def docs_page(request: Request):
    return render_markdown(
        request,
        "example",                      # -> resources/markdown/example.md
        context={"title": "Docs"},
        css_files=["/public/css/styles.css"],
        js_files=["/js/highlight.min.js"],
    )