Skip to content

Conversation

@fingolfin
Copy link
Collaborator

@fingolfin fingolfin commented Nov 4, 2025

These are minor usability errors, "paper cuts" if you will, that have annoyed me repeatedly in the past, and clearly also other people:

Resolves #2031
Resolves #2083
Resolves #2679
Alternative to and hence closes #2810

Alternative in PR #2810: we could also just allow all of this. (For the leading empty line: Should it then be rendered, or hidden?)

Downside: such a doctest would not work with older Documenter versions. I therefore am inclined to prefer the strict version implemented here.

But in the end, either is preferable over the current errors.

(I am waiting with changelog and test cases until I know which direction we'll take)

@fingolfin fingolfin force-pushed the mh/doctest-first-line-empty branch from f5b0bf0 to 4675d15 Compare November 4, 2025 12:22
@fingolfin fingolfin changed the title Warn/error if jldoctest starts with empty line Warn/error if jldoctest has to many/few empty lines Nov 4, 2025
@fingolfin fingolfin changed the title Warn/error if jldoctest has to many/few empty lines Warn/error if jldoctest starts with an empty line; or lacks empty line between two REPL prompts Nov 4, 2025
@fingolfin
Copy link
Collaborator Author

Advantages of a loose version:

  • repl_splitter can stay being a function with one argument, which might be interesting for external projects
  • "it just works" experience for users (instead of forcing the user to adapt to the code, let the code adapt to the user)
    • note that doctests failing the tests being added here can be copy&pasted into a Julia REPL just fine, they work there, so why not in Documenter
  • ...

@mortenpi
Copy link
Member

mortenpi commented Nov 7, 2025

I am inclined to turn these into errors/warnings (i.e. doctest failures):

  • Empty line at the top just looks weird. Not sure why anyone would want that. So let's "lint" it away.
  • Between the prompts, the Julia REPL always forces an empty line between prompts. So I think it's reasonable to require this. It also feels like it should help with the heuristic a bit..

Requiring empty lines would mean that this case should be fine:

image

But it also shouldn't error. Also I feel like it should parse fine right now (but maybe it doesn't?).

So maybe the correct thing to do here is to parse. And when a doctest fails, then check if there is a ^julia> match somewhere in the output part (i.e. a missing empty line), and add to the error/warning we print to the user that "hey, maybe this is meant to be two separate prompts"? This would resolve #2083 I think?

@fingolfin
Copy link
Collaborator Author

Thinking some more about this, my conclusion is that the argument "this code can be pasted fine into the REPL, so we should accept it" isn't so great after all. I think the converse which @mortenpi brought up at least implicitly carries more weight: what does the output of the REPL look like? I think having the rule "the doctest content should match the REPL output exactly is more important.

Besides, if we reject it now, we can always switch to accepting it in the future. The other direction is much harder.

So I'd say, let's indeed go with this PR over the other.

I'll add some tests and a changelog entry.

@fingolfin fingolfin force-pushed the mh/doctest-first-line-empty branch from 73dc44a to 04eb3ab Compare November 7, 2025 15:00
@fingolfin
Copy link
Collaborator Author

Add changelog entry, added a test -- I split this into two commits: the first commit adds the test with the current output. The second commit has the fix and adapts the test to the new output. This way one nicely sees the difference in quality between old and new message.

@fingolfin fingolfin force-pushed the mh/doctest-first-line-empty branch 2 times, most recently from cc2649b to ab2f0e8 Compare November 7, 2025 15:29
- Don't allow empty lines at start of jldoctest.
- Require empty lines before `julia>` prompts other than the
  first one.
@fingolfin fingolfin force-pushed the mh/doctest-first-line-empty branch from ab2f0e8 to 5ecf963 Compare November 7, 2025 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

3 participants