Documenter.jl icon indicating copy to clipboard operation
Documenter.jl copied to clipboard

An empty line breaks REPL-style doctest

Open tkf opened this issue 6 years ago • 3 comments

An empty line inside a for loop does not work

```jldoctest
julia> for i in 1:1

           @show i
       end
i = 1
```

although

```jldoctest
julia> for i in 1:1
           @show i
       end
i = 1
```

does.

tkf avatar Feb 16 '19 01:02 tkf

Not sure if we can do anything about this. We use the fact that source lines have a bunch of whitespace before them as a heuristic to determine if it is a source line or an output line. See SOURCE_REGEX and how it's used in repl_splitter.

mortenpi avatar May 15 '19 07:05 mortenpi

How about using Meta.parse?

code = """
julia> for i in 1:1

           @show i
       end
i = 1
"""

expr, i = Meta.parse(code, length("julia> "))
output = code[i:end]
@assert output == "i = 1\n"

tkf avatar May 15 '19 15:05 tkf

I guess you need to combine Meta.parse with the whitespace-based heuristic to treat multiple expressions like

julia> println(1)
       println(2)
1
2

tkf avatar May 15 '19 15:05 tkf