myfish
Odd doctest to html docs formatting
Just some odd behaviour between iex> , doctest and I think :ex_doc
Here is a simple module snippet…
@doc """
Function 'subtract' takes 2 args and returns answer.
## Example
iex> MyProject.subtract(10, 5) == 5
true
"""
def subtract(a, b) do
a - b
end
iex> iex(4)> MyProject.subtract(10, 5) == 5
true
So all is as expected here. Doctest builds OK too.
But, mix docs builds this …
Example
iex> MyProject.subtract(10, 5) == 5 true
Of course, this is a silly formatting gripe but I don’t understand why the answer, is being appended to the same line ???
I’m very new to this so may have missed something super basic of course.
Most Liked
hauleth
You can also use GitHub “fenced” syntax like:
```
iex> MyProject.subtract(10, 5) == 5
true
```
In the docs. That is why doctest looks for any line that starts with iex>.
blatyo
I’m not sure if this’ll fix the issue, but I believe you’re supposed to indent 4 spaces for doc tests. This has to do with markdown formatting, where it’s not seen as a code block unless it is indented or has code fences (three backticks).
So:
@doc """
Function 'subtract' takes 2 args and returns answer.
## Example
iex> MyProject.subtract(10, 5) == 5
true
"""
def subtract(a, b) do
a - b
end
myfish
OK, I did indeed shift the actual example iex> stuff 4 ‘further spaces’ indented.
Now it works…
Nice one but still leaves me baffled as to why I got clean builds with incorrect formatting ?
Many thanks anyway.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #hex
- #security









