Skip to content

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

Closed
reiyw wants to merge 1 commit intoexecutablebooks:masterfrom
reiyw:fix-content-starting-index
Closed

🐛 FIX: Fix to stop stripping of first line in MyST content#163
reiyw wants to merge 1 commit intoexecutablebooks:masterfrom
reiyw:fix-content-starting-index

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.

2 participants