View Source Mentor.Parser (mentor v0.1.0)

A minimal "Markdown" parser to extract structured field documentation from @moduledoc. Used for Mentor.Ecto.Schema.

Supports:

  • ## Fields section (case-sensitive)
  • Field definitions in the format: -field_name: Description
  • Multiline descriptions, which are joined as a single paragraph

Summary

Functions

Parses a Markdown string into an AST-like structure.

Types

ast()

@type ast() :: [section()]

field()

@type field() :: {:field, name :: atom(), desc :: String.t()}

section()

@type section() :: {:section, name :: String.t(), fields :: [field()]}

Functions

run(markdown)

@spec run(String.t()) :: ast()

Parses a Markdown string into an AST-like structure.

Supported Syntax

  • Sections: ## Section Title
  • Field Definitions: -field_name: Description
  • Multiline field descriptions (joined as a single paragraph)

Returns

  • {:ok, ast} on success
  • {:error, reason} on invalid syntax

Examples

iex> markdown = """
...> ## Fields
...> - `name`: The user's name.
...> - `age`: The user's age
...> that defines the user age
...> """
iex> Mentor.Parser.run(markdown)
[{:section, "Fields", [{:field, :name, "The user's name."}, {:field, :age, "The user's age that defines the user age"}]}]