Skip to main content

examples/comrak_syntax_highlight_lumis.exs

Mix.install([
  {:mdex_native, path: Path.expand("..", __DIR__)}
])

markdown = """
# Lumis

```rust
impl<T> Option<T> {
    #[must_use]
    #[inline]
    pub const fn is_some_and(self, f: impl FnOnce(T) -> bool) -> bool {
        match self {
            None => false,
            Some(x) => f(x),
        }
    }

    #[inline]
    pub const fn as_ref(&self) -> Option<&T> {
        match *self {
            Some(ref x) => Some(x),
            None => None,
        }
    }

    #[inline]
    pub const fn map<U, F>(self, f: F) -> Option<U>
    where
        F: FnOnce(T) -> U,
    {
        match self {
            Some(x) => Some(f(x)),
            None => None,
        }
    }
}
```
"""

options = [
  syntax_highlight: [
    engine: :lumis,
    opts: [
      formatter: {:html_inline, theme: "catppuccin_macchiato", pre_class: "code-block-example"}
    ]
  ]
]

markdown
|> MDExNative.Comrak.markdown_to_html(options)
|> IO.puts()