Documenter.jl
Documenter.jl copied to clipboard
jldoctest fails if # output has trailing space
Currently named doctests fail, if there is a trailing space after the beginning the jldoctest block. Example
a = 1
b = 2
a + b
# output
3
where I have one trailing space behind the # output
line fails with
┌ Warning: invalid doctest block in ...
│ Requires `julia> ` or `# output`
│
│ ```jldoctest mytest
which took me quite a while to find.
We should probably loosen the regex here, by allowing arbitrary whitespace here: https://github.com/JuliaDocs/Documenter.jl/blob/056284a9850a0e74a439a694e267aff20a7311f5/src/DocTests.jl#L193
Why do we want this? Isn't it better to be explicit? Trailing whitespace is usually never a good thing to include. You can configure your editor to automatically remove it.
Yeah, that also crossed my mind. But I do think that the current error you get is not very helpful. I think we have three options here:
- We just allow trailing whitespace
- We allow whitespace, but issue a warning.
- We disallow trailing whitespace (like now), but issue a more helpful error, pointing out that extra whitespace.
I vote 3), just make the warning say `# output` (with no trailing whitespace)
Working around ambiguities just leads to long-term mess.
That is fair enough. If there is a consensus for option 3 I can go ahead and alter my PR to implement that (unless, of coures, somebody else wants to do that)
I can go ahead and alter my PR to implement that
Sure. The lines to change are:
https://github.com/JuliaDocs/Documenter.jl/blob/056284a9850a0e74a439a694e267aff20a7311f5/src/DocTests.jl#L198-L206
Let's go with (3). But I would suggest complaining about the whitespace only if it actually is there. I.e. still update the regex here
https://github.com/JuliaDocs/Documenter.jl/blob/056284a9850a0e74a439a694e267aff20a7311f5/src/DocTests.jl#L193-L194
but @docerror
if there we capture any trailing whitespace.