Module data

Module data 

Source
Expand description

Tera template functions for data loading and content rendering

Functions§

highlight_filter
highlight filter - Syntax highlight code with a specified language Usage: {{ code | highlight(lang=“python”) }}
html_to_text_filter
html_to_text filter - Convert HTML to beautifully formatted plain text
linebreaks_filter
linebreaks filter - Convert newlines to
tags and double newlines to paragraphs Also supports basic markdown: bold, label, code
make_asset_filter
Create the asset filter that looks up hashed paths from the manifest Usage: {{ “/styles/main.css” | asset }} Returns the hashed path if found, otherwise returns the original path
make_list_dirs
list_dirs(path) - List subdirectories Returns array of directory names (strings)
make_list_files
list_files(path, pattern?) - List files with metadata Returns array of objects: [{path, name, stem, ext}, …] Optional pattern argument supports glob syntax (e.g., “solution.”, “.py”)
make_load_json
load_json(path) - Load and parse a JSON file Returns the parsed JSON value, or Null if file doesn’t exist or is invalid
make_read_file
read_file(path) - Read a file as text Returns the file content as string, or Null if file doesn’t exist
make_read_markdown
read_markdown(path) - Read a Markdown file and return as HTML Returns the rendered HTML as string, or Null if file doesn’t exist
markdown_filter
markdown filter - Convert markdown text to HTML
register_data_functions
Register all data functions with Tera