📝 Markdown / HTML

To render markdown files, the renderMarkdown function is used, which receives the following parameters: request, file: str, base_path: str='templates/markdown/', css_files: list=[], js_files: list=[], picocss: bool=False

file is the name of the Markdown file starting from base_path. For example: index.md. It will look for index.md inside templates/markdown/.

css_files and js_files are lists of CSS and JS files to include in the rendered HTML.

picocss is a boolean indicating whether the PicoCSS stylesheet should be loaded.

Now, you can use layout.html in templates/markdown/ as a base editable template:

Below is an example of rendering a Markdown file with bilingual support in Lilac:

example.md

# {{ translate["welcome"] }}

This is a simple **Markdown** example. 

## {{ translate["features"] }}
- {{ translate["easy_write"] }}
- {{ translate["convert_html"] }}
- {{ translate["supports_links"] }}

### {{ translate["example_code"] }}

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

Python code to render it using renderMarkdown:

Python

from lila.core.templates import renderMarkdown

@router.route(path='/markdown', methods=['GET'])
async def home(request: Request):
    css = ["/public/css/styles.css"]
    response = renderMarkdown(
        request=request,
        file='example',
        css_files=css,
        picocss=True
    )
    return response