PhoenixEmail.Highlight (PhoenixEmail v0.1.0)

Copy Markdown View Source

Inline-styled syntax highlighting for PhoenixEmail.Components.code_block/1.

Uses makeup when available — add :makeup plus a lexer such as :makeup_elixir to your dependencies. Without makeup (or for unknown languages) the code renders escaped but unstyled.

A theme is a map from makeup token type to an inline CSS string, plus a :base entry applied to the surrounding <pre>. Token types fall back to their parent type (:keyword_declaration:keyword), so a few entries cover a whole language.

Summary

Functions

default_theme()

The default theme, GitHub-light-like colors.

highlight(code, language, theme \\ %{base: "background:#f6f8fa;border-radius:6px;color:#24292e;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:13px;line-height:20px;padding:16px;white-space:pre", comment: "color:#6a737d;font-style:italic", generic_deleted: "color:#b31d28", generic_inserted: "color:#22863a", keyword: "color:#d73a49", name_attribute: "color:#005cc5", name_builtin: "color:#005cc5", name_class: "color:#6f42c1", name_constant: "color:#005cc5", name_decorator: "color:#6f42c1", name_function: "color:#6f42c1", number: "color:#005cc5", operator: "color:#d73a49", punctuation: "color:#24292e", string: "color:#032f62", string_symbol: "color:#005cc5"})

Highlights code for language, returning HTML-escaped iodata where each styled token is wrapped in a <span style="...">.