@tola/icon
Render configured SVG icons inline in HTML or publish them as standalone SVG assets.
Import
#import "@tola/icon:0.0.0": *Icons whose fill or stroke uses currentColor automatically inherit surrounding text color when rendered inline with icon(...); explicit colors in the SVG stay unchanged.
Exports
icon
let icon(
id: string,
attrs: dictionary = (:),
label: none | string = none,
module: none | string = none,
) = content;Insert a configured icon as a 1em inline SVG inside HTML documents.
Validates id at call time. Works only in HTML documents; for PDF or other formats use icon-bytes or icon-url.
Positional parameters
idstringrequired: Case-sensitive"namespace:name"identifier declared under[icons.collections].
Named parameters
modulenone | stringdefault:none: Optional module alias owning the collection. Omit to use site collections.labelnone | stringdefault:none: Accessible label for screen readers (non-blank). Omit or passnoneto mark the icon decorative (aria-hidden="true").attrsdictionarydefault:(:): Extra string-valued attributes on the root<svg>(for example(class: "brand",)).classandstyleappend; accessibility attributes (aria-label,aria-labelledby,aria-hidden,role,focusable) are managed bylabeland rejected inattrs.
Render decorative and labeled inline icons
#import "@tola/icon:0.0.0": icon
#document("index.html")[
#icon("brand:mark")
#icon("brand:mark", label: "Site logo", attrs: (class: "brand",))
]icon-bytes
let icon-bytes(
id: str,
module: str | none = none,
) = bytes;Return the raw SVG bytes of a configured icon for Typst image(...) or custom asset(...) publishing.
Positional parameters
idstrrequired: Case-sensitive"namespace:name"icon identifier.
Named parameters
modulestr | nonedefault:none: Optional module alias owning the collection. Omit to use site collections.
icon-url
let icon-url(
id: str,
module: str | none = none,
) = str;Publish a configured icon as a standalone SVG file and return its browser URL (with site.base-path).
Only icons referenced during evaluation are published.
Positional parameters
idstrrequired: Case-sensitive"namespace:name"icon identifier.
Named parameters
modulestr | nonedefault:none: Optional module alias owning the collection. Omit to use site collections.
Load a published icon with `<img>`
#import "@tola/icon:0.0.0": icon-url
#document("index.html")[
#html.img(src: icon-url("brand:mark"), alt: "Site mark")
]