Raxol.UI.Components.CodeBlock (Raxol v2.6.0)

View Source

Renders a block of code with syntax highlighting.

Uses Makeup for tokenization when available, with graceful fallback to plain text when Makeup is not loaded.

Summary

Functions

Handles events for the component. No events are handled by default.

Initializes the component state from props.

Mount hook - called when component is mounted. No special setup needed for CodeBlock.

Renders the code block.

Unmount hook - called when component is unmounted. No cleanup needed for CodeBlock.

Updates the component state. No updates are handled by default.

Functions

broadcast(msg)

command(cmd)

handle_event(event, state, context)

@spec handle_event(term(), map(), map()) :: {map(), list()}

Handles events for the component. No events are handled by default.

init(props)

@spec init(map()) :: {:ok, map()}

Initializes the component state from props.

mount(state)

@spec mount(map()) :: {map(), list()}

Mount hook - called when component is mounted. No special setup needed for CodeBlock.

render(state, context)

@spec render(map(), map()) :: any()

Renders the code block.

Props:

  • content (required): The source code string.
  • language (optional): The language name (e.g., "elixir"). Defaults to "text".

schedule(msg, delay)

unmount(state)

@spec unmount(map()) :: map()

Unmount hook - called when component is unmounted. No cleanup needed for CodeBlock.

update(props, state)

@spec update(term(), map()) :: map()

Updates the component state. No updates are handled by default.