Description
This follows gh-220. After gh-221 it is documented that a markdown block needs to end with a blank line before the backticks like:
```
>>> 1 + 1
2
```
I think that this should be considered a bug so I'm opening this issue.
The source of the bug is the stdlib doctest module (python/cpython#116546). It probably does not make sense to fix it at the stdlib level because the stdlib doctest parser is very rudimentary and does not even know that it is parsing markdown syntax at all. There is also a pytest issue (pytest-dev/pytest#7374) which was closed because pytest's doctest support is unmaintained.
It seems to me that here in pytest-doctestplus is the place to fix this since markdown files for documentation are common.
The erroneous result from the stdlib parser comes in here at the start of parsing:
pytest-doctestplus/pytest_doctestplus/plugin.py
Lines 393 to 394 in 84fd2e2
To handle markdown properly the parser would need to be designed for markdown. I suggest having an alternate MarkdownParser
class that would look for backticks rather than depending on the stdlib's PS1 regex. The rst directives would ideally also have markdown variants but I am not sure how those could look. Once the fenced sections are extracted from the markdown file they can be parsed by the existing parser to separate input/output.