Skip to content

Error when parsing a directive option with ** #712

@arwedus

Description

@arwedus

Describe the bug

context
When parsing the following document snippet, I get an error:

The maps component is composed of the following packages:

```{sw-package-import}
:dependency_graph: False
:glob: **
```

I wrote a little sphinx plug-in to provide the "sw-package-import" directive. It takes an option glob ("directives.unchanged") which takes a string, in this case the glob pattern "**", which should be passed directly to the directive.

The following syntax also fails with the same error message:

```{sw-package-import}
---
dependency_graph: False
glob: **
---
```

When I replace the above snippet by this, it works:

The maps component is composed of the following packages:

```{eval-rst}
.. sw-package-import::
   :dependency_graph: False
   :glob: **
```

When I put the string into double quotes in the examples 1 and 2, it also works:

```{sw-package-import}
:dependency_graph: False
:glob: "**"
```

expectation

I expected that the option strings are passed "as-is" to the sphinx/docutils directive parser, i.e. I expected all three styles to have the same result.

bug

Here's the error message I ran into with variant 1 and 2:

..../lib/readme.md:5: ERROR: Directive 'sw-package-import': Invalid options YAML: while scanning an alias
  in "<unicode string>", line 2, column 7:
    glob: **
          ^
expected alphabetic or numeric character, but found '*'
  in "<unicode string>", line 2, column 8:
    glob: **
           ^

:dependency_graph: False
:glob: **

I interpreted the hint about YAML syntax right - if you put the ** in double quotes (which makes sure YAML interprets the argument as a string and not something else), the string "**" is returned as option value, as expected.

problem

This is a problem for us because we usually avoid using the extra "eval-rst" directive around sphinx directives to keep the documents shorter. It also feels kinda inconsistent. If this behavior is intended and as specified, I have missed the hint in the documentation. In this case, I kindly ask you to explain the argument parsing in myst markdown directives in more detail in the user documentation.

I think it's actually okay to put strings like these in double quotes, but the documentation should make clear that even the :option: value syntax differs from restructuredtext.

Reproduce the bug

I did not publish the code of my little "sw-package-import" directive yet, but if you need that to get to the root cause of this error message, contact me directly.

List your environment

myst-parser==0.18.1
sphinx==5.3.0
docutils==0.17.1
sphinx-needs==1.2.2

Python version: 3.8.10

OS: Ubuntu Linux 20.04

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions