executablebooks / sphinx-tabs

Tabbed views for Sphinx
https://sphinx-tabs.readthedocs.io
MIT License
263 stars 67 forks source link

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

Closed reiyw closed 2 years ago

reiyw commented 2 years ago

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.

https://github.com/executablebooks/sphinx-tabs/blob/0b04c8eb37075d57f6d5ad321ca40f4e800894f8/sphinx_tabs/tabs.py#L187

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[bot] commented 2 years ago

Thanks for submitting your first pull request! You are awesome! :hugs:
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! :tada:

foster999 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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

foster999 commented 2 years ago

pre-commit.ci run

foster999 commented 2 years ago

Created #165 to merge master and run tests