Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 FIX: Parsing directive content, when body followed by arguments #28

Merged
merged 2 commits into from
Feb 15, 2022

Conversation

rowanc1
Copy link
Member

@rowanc1 rowanc1 commented Feb 13, 2022

There is a bug that the content did not get bumped if there were options.

I have rearranged the admonition tests to add some more coverage for this.

This is the bug:
broken-admonition

if (
!directive.required_arguments &&
!directive.optional_arguments &&
!Object.keys(options).length
) {
if (!directive.required_arguments && !directive.optional_arguments) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the change, all other changes are around the tests.

@chrisjsewell
Copy link
Member

chrisjsewell commented Feb 15, 2022

Hey @rowanc1 there is an issue, but not the one you think 😬

Firstly, seealso has 0 required/optional arguments, i.e. the title here is not a title, it's actually body text 😕


with restructuredtext

.. seealso:: A title
    :class: tip

    A body


.. seealso:: A title


    A body

gives you:

image


with myst-parser

```{seealso} A title
:class: tip

A body
```


```{seealso} A title


A body
```

you get

image


So https://github.com/executablebooks/MyST-Parser/blob/e477a75940b7a943ca834a98cbea8bcb8d824a6c/myst_parser/parse_directives.py#L52, is "mistakenly" omitting the first line, wheras the code here is mistaking it for a title

Although yeh, as we've discussed before, the "variability of the directive structure does mean that syntax can be terser, but its not ideal for the parser

@rowanc1
Copy link
Member Author

rowanc1 commented Feb 15, 2022

The GIF that I included was a poor choice, there was some other code that was marking the first paragraph as the title that is unrelated. The test does show the appropriate change, although there is additional work that needs to bring the class to the front to make that the first choice in styling.

The code change that is in this PR produces the following in mystjs:

image

I think we do have the choice in MyST to be stricter/more sensible than RST here if we want (I think we should!). We could introduce warnings when people put in arguments that is interpreted as inline content, and eventually deprecate that syntax in MyST. Regardless, I think we should make the behaviour consistent with RST for now, and this PR does do the trick!

I will introduce another test case to cover the tip class being at the front.

Copy link
Member Author

@rowanc1 rowanc1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the tests below that document the expected behaviour, i.e. how RST works.

Comment on lines +203 to +216
`see also` admonition with class, bump title new paragraph
.
```{seealso} Not a title
:class: tip

See other things here!
```
.
<aside class="tip admonition seealso">
<header class="admonition-title">See Also</header>
<p>Not a title</p>
<p>See other things here!</p>
</aside>
.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the test shown in the PR conversation that is passing!

Comment on lines +188 to +199
`see also` admonition with class, bump title
.
```{seealso} Not a title
:class: tip
See other things here!
```
.
<aside class="tip admonition seealso">
<header class="admonition-title">See Also</header>
<p>Not a title
See other things here!</p>
</aside>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the other relevant test case.

Comment on lines +39 to +47
```{admonition} This is a title
:class: tip
An example of a `tip` with a custom _title_.
```
.
<aside class="tip admonition">
<header class="admonition-title">This is a title</header>
<p>An example of a <code>tip</code> with a custom <em>title</em>.</p>
</aside>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these now put the custom class first, as is done in RST. I will make a note of that in the docs I am writing about this.

@chrisjsewell
Copy link
Member

there was some other code that was marking the first paragraph as the title that is unrelated

Ok cheers, so is this unrelated code something present in this repo, or some upstream thing?

@rowanc1
Copy link
Member Author

rowanc1 commented Feb 15, 2022

The header flicker had to do with the mystjs repo and the mdast tree (since fixed), not related at all to docutils or this change. The tests I highlighted in the review in this repo and the exported html from the myst are the place to look to verify this change is correct!

@chrisjsewell
Copy link
Member

Checked in executablebooks/MyST-Parser#520, that this change does not break any tests over there 👍

Copy link
Member

@chrisjsewell chrisjsewell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good cross-validation cheers!

@chrisjsewell chrisjsewell changed the title Bump content when no arguments 🐛 FIX: Parsing directive content when body followed by arguments Feb 15, 2022
@chrisjsewell chrisjsewell changed the title 🐛 FIX: Parsing directive content when body followed by arguments 🐛 FIX: Parsing directive content, when body followed by arguments Feb 15, 2022
@chrisjsewell chrisjsewell merged commit a96f2e2 into main Feb 15, 2022
@chrisjsewell chrisjsewell deleted the bug/no-args branch February 15, 2022 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants