Cherry.Content.CodeHead (cherry v0.6.0)

Copy Markdown View Source

The header bar above fenced code blocks: the language in small text, an optional file path, and a file-type icon.

The fence info string carries both, Docusaurus-style:

```elixir title="lib/cherry/cli.ex"

Language and title are each optional; a fence with neither renders the bare <pre> it always did. The header is a <figcaption class="code-head"> inside a <figure class="code-block"> wrapper, and the icon is an empty span the theme paints with a CSS mask: code-icon code-icon--KEY. The official themes ship the glyph set (sourced from devicon, MIT — the same icons editor file trees use); a language without a glyph falls back to the generic file icon that .code-icon carries by default.

Summary

Functions

Parses a fence info string into {language, title}, either nil when absent. The language is the first token as the author wrote it; the title is the value of a title="…" pair anywhere in the rest.

Wraps a rendered <pre> block in the figure + header. Call only when parse/1 produced a language or a title.

Functions

parse(info)

@spec parse(String.t() | nil) :: {String.t() | nil, String.t() | nil}

Parses a fence info string into {language, title}, either nil when absent. The language is the first token as the author wrote it; the title is the value of a title="…" pair anywhere in the rest.

wrap(pre_html, lang, title)

@spec wrap(String.t(), String.t() | nil, String.t() | nil) :: String.t()

Wraps a rendered <pre> block in the figure + header. Call only when parse/1 produced a language or a title.