defmodule Shadix.Website.Components.Highlight do @moduledoc """ Server-side HEEx syntax highlighting via `makeup_eex`'s HEEx lexer. The lexer is looked up from Makeup's registry by name ("heex"), so we don't hardcode its module. On any lexing error we fall back to HTML-escaped plain text. Only the token markup is produced here; the colors live in `assets/css/app.css` (a Flexoki palette with light/dark variants) so they can theme with the page. """ @spec heex(String.t()) :: String.t() def heex(code) when is_binary(code) do {lexer, opts} = Makeup.Registry.fetch_lexer_by_name!("heex") Makeup.highlight_inner_html(code, lexer: lexer, lexer_options: opts) rescue _ -> code |> Phoenix.HTML.html_escape() |> Phoenix.HTML.safe_to_string() end end