Skip to main content

MathRenderer

Trait MathRenderer 

Source
pub trait MathRenderer: Debug {
    // Required method
    fn render_html_label(
        &self,
        text: &str,
        config: &MermaidConfig,
    ) -> Option<String>;

    // Provided method
    fn measure_html_label(
        &self,
        _text: &str,
        _config: &MermaidConfig,
        _style: &TextStyle,
        _max_width_px: Option<f64>,
        _wrap_mode: WrapMode,
    ) -> Option<TextMetrics> { ... }
}
Expand description

Optional math renderer used to transform label HTML and (optionally) provide measurements.

Implementations should be:

  • deterministic (stable output across runs),
  • side-effect free (no global mutations),
  • non-panicking (return None to decline handling).

Required Methods§

Source

fn render_html_label( &self, text: &str, config: &MermaidConfig, ) -> Option<String>

Attempts to render math fragments within an HTML label string.

If the renderer declines to handle the input, it should return None.

The returned string is treated as raw HTML and will still be sanitized by merman before emitting into an SVG <foreignObject>.

Provided Methods§

Source

fn measure_html_label( &self, _text: &str, _config: &MermaidConfig, _style: &TextStyle, _max_width_px: Option<f64>, _wrap_mode: WrapMode, ) -> Option<TextMetrics>

Optionally measures the rendered HTML label in pixels.

This is intended to mirror upstream Mermaid’s DOM measurement behavior for math labels. The default implementation returns None.

Implementors§