executablebooks / sphinx-tabs

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

Reference code instead of inline code? #111

Closed JosephPJordan closed 3 years ago

JosephPJordan commented 3 years ago

Is your feature request related to a problem? Please describe.

Just came across this, it's exactly what we are looking for.

I'm far from a sphinx expert, so not sure if this is already possible, but it would be great to be able to reference code files from a different location instead of including the actual code inline in the page, with something like .. literalinclude:: ../examples/example-code.json

I tried a few different ways but couldn't get it to work.. maybe it just can't. For example:

.. tabs::

    .. code-tab:: json classic

        .. literalinclude:: ../examples/example-code.json

Describe the solution you'd like

Would be great to reference code instead of putting it inline. We are trying to use it for an code examples page where there would be maybe 10 examples or more on a page, and sometimes more, and each example can be 100 or more lines... so it just makes the page much longer. Again, not sure it's even possible.

Describe alternatives you've considered

It does work with just putting the code inline, so definitely not a show-stopper.

Additional context

Add any other context or screenshots about the feature request here.

welcome[bot] commented 3 years ago

Thanks for opening your first issue here! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.
If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).
Welcome to the EBP community! :tada:

foster999 commented 3 years ago

Hi @JosephPJordan, good question - that approach would make the document much more concise.

I think you should be able to achieve this with our group-tab and the literalinclude directive:

.. tabs::

    .. group-tab:: json classic

        .. literalinclude:: ../examples/example-code.json
            :language: json

code-tabs currently expect the code inline, while group-tab's can hold any content. So I'd use the language option for literalinclude to set the code language and pass a custom name to the group-tab.

As long as you use consistent names for the tabs between tab sets, they should use the grouping action when changing between languages.

Hope this helps 😄

JosephPJordan commented 3 years ago

@foster999, thanks, that did the trick!! Appreciate the quick response.