Code Block Decorators

View Source
Mix.install([
  {:mdex, "~> 0.8.1"},
  {:kino, "~> 0.16"}
])

Intro

Code block decorators let you add metadata to fenced code blocks using key-value pairs in the info string. Use them to highlight specific lines, apply custom themes per block, or add other visual enhancements without modifying the code itself.

All options and more examples at Guides / Code Block Decorators

Decorator: highlight_lines

import MDEx.Sigil

~MD"""
```elixir highlight_lines=2,5,8-10 theme=github_light
defmodule Lines do
  @langs ["elixir", "rust"]

  def langs do
    @langs
  end

  def libs do
    [:comrak, :ammonia, :lumis]
  end
end
```
"""HTML
|> Kino.HTML.new()

Decorator: theme

import MDEx.Sigil

~MD"""
```elixir theme=gruvbox_light
defmodule Lines do
  @langs ["elixir", "rust"]

  def langs do
    @langs
  end

  def libs do
    [:comrak, :ammonia, :lumis]
  end
end
```
"""HTML
|> Kino.HTML.new()

Decorator: highlight_lines_style

import MDEx.Sigil

~MD"""
```elixir highlight_lines=2 highlight_lines_style="background-color: purple; font-weight: bold; font-size: 18px"
defmodule Lines do
  @langs ["elixir", "rust"]

  def langs do
    @langs
  end

  def libs do
    [:comrak, :ammonia, :lumis]
  end
end
```
"""HTML
|> Kino.HTML.new()

Decorator: include_highlights

~MD"""
```elixir include_highlights
defmodule Lines do
  @langs ["elixir", "rust"]

  def langs do
    @langs
  end

  def libs do
    [:comrak, :ammonia, :lumis]
  end
end
```
"""HTML
|> Kino.HTML.new()