SnakeBridge.Docs.MarkdownConverter (SnakeBridge v0.16.0)

Copy Markdown View Source

Converts parsed Python docstrings to Elixir ExDoc Markdown format.

This module transforms structured docstring data into Markdown that is compatible with ExDoc and follows Elixir documentation conventions.

Summary

Functions

Converts a parsed docstring structure to ExDoc Markdown format.

Converts a Python doctest example to Elixir iex format.

Converts a Python exception type to an Elixir exception module.

Converts a Python type annotation to an Elixir typespec format.

Functions

convert(parsed)

@spec convert(map()) :: String.t()

Converts a parsed docstring structure to ExDoc Markdown format.

Parameters

  • parsed - A map with keys: :short_description, :long_description, :params, :returns, :raises, :examples

Returns

A Markdown string suitable for use in @doc or @moduledoc.

convert_example(example)

@spec convert_example(String.t()) :: String.t()

Converts a Python doctest example to Elixir iex format.

Examples

iex> MarkdownConverter.convert_example(">>> func(1, 2)\n3")
"    iex> func(1, 2)\n    3"

convert_exception(python_exception)

@spec convert_exception(String.t() | nil) :: String.t()

Converts a Python exception type to an Elixir exception module.

Examples

iex> MarkdownConverter.convert_exception("ValueError")
"ArgumentError"

convert_type(python_type)

@spec convert_type(String.t() | nil) :: String.t()

Converts a Python type annotation to an Elixir typespec format.

Examples

iex> MarkdownConverter.convert_type("int")
"integer()"

iex> MarkdownConverter.convert_type("list[str]")
"list(String.t())"