Skip to content

Trailing backticks in markdown files #247

Open
@oscarbenjamin

Description

@oscarbenjamin

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:

def parse(self, s, name=None):
result = doctest.DocTestParser.parse(self, s, name=name)

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions