TermUI.Markdown (TermUI v1.0.0)

View Source

Markdown processor for rendering styled text in TermUI.

Converts markdown content to styled segments that can be rendered by TermUI components. MDEx parses CommonMark input; this renderer handles headings, paragraphs, emphasis, code, lists, blockquotes, thematic breaks, links, and image alt text. Unsupported nodes degrade to their text/children where possible.

Usage

iex> lines = TermUI.Markdown.render("**bold** and *italic*", 80)

iex> result = TermUI.Markdown.render_with_elements("```elixir\ndef hello, do: :world\n```", 80)

Summary

Functions

Renders markdown content as a list of styled lines.

Converts a styled line to a TermUI render node.

Renders markdown content with interactive element tracking.

Types

interactive_element()

@type interactive_element() :: %{
  id: String.t(),
  type: :code_block,
  content: String.t(),
  language: String.t() | nil,
  start_line: non_neg_integer(),
  end_line: non_neg_integer()
}

render_result()

@type render_result() :: %{
  lines: [styled_line()],
  elements: [interactive_element()],
  content_height: non_neg_integer()
}

styled_line()

@type styled_line() :: [styled_segment()]

styled_segment()

@type styled_segment() :: {String.t(), TermUI.Renderer.Style.t() | nil}

Functions

render(content, max_width)

@spec render(String.t(), pos_integer()) :: [styled_line()]

Renders markdown content as a list of styled lines.

render_line_to_node(segments)

@spec render_line_to_node(styled_line()) :: TermUI.Component.RenderNode.t()

Converts a styled line to a TermUI render node.

render_with_elements(content, max_width, opts)

@spec render_with_elements(String.t(), pos_integer(), keyword()) :: render_result()

Renders markdown content with interactive element tracking.

wrap_styled_lines(lines, max_width)

@spec wrap_styled_lines([styled_line()], pos_integer()) :: [styled_line()]