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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 FIX: Fix to stop stripping of first line in MyST content #163

Closed

Conversation

reiyw
Copy link
Contributor

@reiyw reiyw commented Jun 16, 2022

This pull request fixes a problem where the first line of content in a tab or group-tab directive is stripped in MyST.

The following in MyST will render with the first line in the tab and group-tab blocks stripped.

````{tabs}
```{tab} test
The first line.
The second line.
```
````

````{tabs}
```{group-tab} test
The first line.
The second line.
```
````

````{tabs}
```{code-tab} py
# The first line.
# The second line.
```
````

image

The cause of this is the index specification when getting the directive content within the TabDirective.run method.

self.state.nested_parse(self.content[2:], self.content_offset, panel)

The directive syntax in reStructuredText requires a blank line before the content, so self.content[1] is guaranteed to be a blank line. However, MyST has no such restriction; the actual content starts from self.content[1] when written as in the example above. Therefore, if one slices it as self.content[2:], the first line of the content will be stripped.

So, I modified it so that the first line of content is parsed in MyST by slicing the content from [1:]. I think that this change does not affect the parsing of content in reStructuredText.

@welcome
Copy link

welcome bot commented Jun 16, 2022

Thanks for submitting your first pull request! You are awesome! 馃

If you haven't done so already, check out EBP's Code of Conduct and our Contributing Guide, as this will greatly help the review process.

Welcome to the EBP community! 馃帀

@foster999
Copy link
Collaborator

Thanks for this change @reiyw, I hadn't realised this was different in MyST vs rST

Does the nested_parse strip off the blank line from rST?

@reiyw
Copy link
Contributor Author

reiyw commented Jun 17, 2022

Yes, I am not aware of the detailed behavior of nested_parse, but at least when I tested it in my environment it was stripping off the line from the rST.

.. tabs::

   .. tab:: test

      test

Before this change:
image

After this change:
image

@foster999
Copy link
Collaborator

Once I've merged #164 we can rerun the tests here to confirm it doesn't break any tested rST behaviour

@foster999 foster999 changed the title Fix the starting index of the content 馃悰 FIX: Fix to stop stripping of first line in MyST content Jun 25, 2022
@foster999
Copy link
Collaborator

pre-commit.ci run

@foster999
Copy link
Collaborator

Created #165 to merge master and run tests

@foster999 foster999 closed this Jun 25, 2022
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.

None yet

2 participants