myfish

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

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

blatyo

Conduit Core Team

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

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.

Where Next?

Popular in Questions Top

ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New

Other popular topics Top

jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42533 114
New

We're in Beta

About us Mission Statement