How to call functions in moduledocs for easier formatting in exdoc

Hello friends,

I’m curious how to call functions in moduledocs when generating documentation.

Given the following module, how do I use my provided functions for formatting?

defmodule ModuleDocFormatterQuestion do
  @moduledoc """
  | name | type | default | description |
  #{render_env_var_in_md_table("First column", "second_column", "third_column", "fourth column")}
  """

  defp render_env_var_in_table(name, type, default, description) do
    "| `#{name}` | `#{type}` | `#{default}` | #{description} |"
  end
end

thanks a bunch!

Since the @moduledoc is built at compile time, your function render_env_var_in_table/4 won’t be available in the current module - since that module is being build. Place your render_env_var_in_table/4 function in another module and you should be good to go.

2 Likes