I’d suggest moving the formatting out of the heex sigil:
def highlight(assigns) do
formatted =
assigns.inner_block
|> render_slot()
|> Phoenix.HTML.html_escape()
|> Phoenix.HTML.safe_to_string()
|> Makeup.Lexers.Bootstrap.HTMLLexer.lex()
|> Makeup.Formatters.HTML.HTMLFormatter.format_inner_as_binary([])
|> Phoenix.HTML.raw()
assigns = assign(assigns, :formatted, formatted)
~H"""
<pre class="chroma"><code class="language-html"><%= @formatted %></code></pre>
"""
end
Besides being easier to maintain it should also make it clear that the formatted code is not granularly change tracked when used in LiveView.






















