Format elixir code examples in your docs!
ExamplesStyler
is a Mix.Tasks.Format
plugin to bring the same styling rules to your
docstrings and markdown files!
This package implements a mix format
plugin. Add the following plugins
value to your
.formatter.exs
file:
[
plugins: [ExamplesStyler],
inputs: ...
]
If you use a non-default plugin like adobe/elixir-styler to style your code, it will also need to be added:
[
plugins: [Styler, ExamplesStyler],
inputs: ...
]
Don't forget to add any .md
or .cheatmd
files you want examples styled for!
We follow the same approach as ExUnit doc tests: example code must be prefaced by
iex>
.
iex> # Input
iex> 1 + 1
iex> # Output
iex> 1 + 1
Code found on contiguous lines is styled together:
iex> # Input
iex> def add(a, b),
iex> do: a + b
iex> # Input
iex> def add(a, b),
iex> do: a + b
Any lines prefaced with iex>
that are separated in any way will be styled separately.
This package is still in very early development; be sure to back up your code before running the formatter!
If available in Hex, the package can be installed
by adding examples_styler
to your list of dependencies in mix.exs
:
def deps do
[
{:examples_styler, "~> 0.2", only: [:dev, :test], runtime: false}
]
end