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

vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

Other popular topics Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
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

We're in Beta

About us Mission Statement