Git Product home page Git Product logo

sphinx-inline-tabs's Introduction

Sphinx Inline Tabs

demo image

Add inline tabbed content to your Sphinx documentation.

Installation

This project is available on PyPI, and can be installed using pip:

pip install sphinx-inline-tabs

You'll also want to add the extension to extensions in conf.py:

extensions = [
    ...,
    "sphinx_inline_tabs",
    ...,
]

Features

  • Elegant design: Small footprint in the markup and generated website, while looking good.
  • Configurable: All the colors can be configured using CSS variables.
  • Synchronisation: Tabs with the same label all switch with a single click.
  • Works without JavaScript: JavaScript is not required for the basics, only for synchronisation.

Contributing

sphinx-inline-tabs is a volunteer maintained open source project, and we welcome contributions of all forms.

The Code of Conduct applies within all community spaces. If you are not familiar with our Code of Conduct policy, take a minute to read the policy before starting with your first contribution.

sphinx-inline-tabs's People

Contributors

choldgraf avatar henryiii avatar nedbat avatar pradyunsg avatar pre-commit-ci[bot] avatar webknjaz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

sphinx-inline-tabs's Issues

Declare parallel reading capabilities to remove Sphinx warnings

Using sphinx-inline-tabs in a project gave me very loud Sphinx warnings โ€“ nothing important, but would be nice to get rid of eventually:

WARNING: the sphinx_inline_tabs extension does not declare if it is safe for parallel reading, assuming it isn't - please ask the extension author to check and make it explicit
WARNING: doing serial read

Sphinx man pages for beta9

sphinx 4.0.2

$ PYTHONPATH=$PWD/src  sphinx-build -b man -d python-sphinx-inline-tabs docs .
Running Sphinx v4.0.2
loading intersphinx inventory from https://docs.python.org/3/objects.inv...
loading intersphinx inventory from https://www.sphinx-doc.org/objects.inv...
intersphinx inventory has moved: https://www.sphinx-doc.org/objects.inv -> https://www.sphinx-doc.org/en/master/objects.inv
myst v0.15.1: MdParserConfig(renderer='sphinx', commonmark_only=False, enable_extensions=['dollarmath'], dmath_allow_labels=True, dmath_allow_space=True, dmath_allow_digits=True, dmath_double_inline=False, update_mathjax=True, mathjax_classes='tex2jax_process|mathjax_process|math|output_area', disable_syntax=[], url_schemes=['http', 'https', 'mailto', 'ftp'], heading_anchors=3, heading_slug_func=None, html_meta=[], footnote_transition=True, substitutions=[], sub_delimiters=['{', '}'], words_per_minute=200)
building [mo]: targets for 0 po files that are out of date
building [man]: all manpages
updating environment: [new config] 2 added, 0 changed, 0 removed
reading sources... [100%] usage
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
writing... python-sphinx-inline-tabs.3 { usage } /home/tkloczko/rpmbuild/BUILD/sphinx-inline-tabs-2021.04.11.beta9/docs/index.md:10: WARNING: "unsupported "label"
/home/tkloczko/rpmbuild/BUILD/sphinx-inline-tabs-2021.04.11.beta9/docs/index.md:14: WARNING: "unsupported "label"
/home/tkloczko/rpmbuild/BUILD/sphinx-inline-tabs-2021.04.11.beta9/docs/index.md:18: WARNING: "unsupported "label"
/home/tkloczko/rpmbuild/BUILD/sphinx-inline-tabs-2021.04.11.beta9/docs/index.md:22: WARNING: "unsupported "label"
/home/tkloczko/rpmbuild/BUILD/sphinx-inline-tabs-2021.04.11.beta9/docs/index.md:28: WARNING: "unsupported "label"
/home/tkloczko/rpmbuild/BUILD/sphinx-inline-tabs-2021.04.11.beta9/docs/index.md:34: WARNING: "unsupported "label"
/home/tkloczko/rpmbuild/BUILD/sphinx-inline-tabs-2021.04.11.beta9/docs/index.md:40: WARNING: "unsupported "label"
/home/tkloczko/rpmbuild/BUILD/sphinx-inline-tabs-2021.04.11.beta9/docs/index.md:46: WARNING: "unsupported "label"
/home/tkloczko/rpmbuild/BUILD/sphinx-inline-tabs-2021.04.11.beta9/docs/usage.md:31: WARNING: "unsupported "label"
/home/tkloczko/rpmbuild/BUILD/sphinx-inline-tabs-2021.04.11.beta9/docs/usage.md:35: WARNING: "unsupported "label"
/home/tkloczko/rpmbuild/BUILD/sphinx-inline-tabs-2021.04.11.beta9/docs/usage.md:39: WARNING: "unsupported "label"
/home/tkloczko/rpmbuild/BUILD/sphinx-inline-tabs-2021.04.11.beta9/docs/usage.md:43: WARNING: "unsupported "label"
/home/tkloczko/rpmbuild/BUILD/sphinx-inline-tabs-2021.04.11.beta9/docs/usage.md:83: WARNING: "unsupported "label"
/home/tkloczko/rpmbuild/BUILD/sphinx-inline-tabs-2021.04.11.beta9/docs/usage.md:87: WARNING: "unsupported "label"
/home/tkloczko/rpmbuild/BUILD/sphinx-inline-tabs-2021.04.11.beta9/docs/usage.md:93: WARNING: "unsupported "label"
/home/tkloczko/rpmbuild/BUILD/sphinx-inline-tabs-2021.04.11.beta9/docs/usage.md:97: WARNING: "unsupported "label"
/home/tkloczko/rpmbuild/BUILD/sphinx-inline-tabs-2021.04.11.beta9/docs/usage.md:101: WARNING: "unsupported "label"
/home/tkloczko/rpmbuild/BUILD/sphinx-inline-tabs-2021.04.11.beta9/docs/usage.md:106: WARNING: "unsupported "label"
/home/tkloczko/rpmbuild/BUILD/sphinx-inline-tabs-2021.04.11.beta9/docs/usage.md:115: WARNING: "unsupported "label"
/home/tkloczko/rpmbuild/BUILD/sphinx-inline-tabs-2021.04.11.beta9/docs/usage.md:123: WARNING: "unsupported "label"
/home/tkloczko/rpmbuild/BUILD/sphinx-inline-tabs-2021.04.11.beta9/docs/usage.md:143: WARNING: "unsupported "label"
/home/tkloczko/rpmbuild/BUILD/sphinx-inline-tabs-2021.04.11.beta9/docs/usage.md:149: WARNING: "unsupported "label"
/home/tkloczko/rpmbuild/BUILD/sphinx-inline-tabs-2021.04.11.beta9/docs/usage.md:155: WARNING: "unsupported "label"
/home/tkloczko/rpmbuild/BUILD/sphinx-inline-tabs-2021.04.11.beta9/docs/usage.md:162: WARNING: "unsupported "label"
/home/tkloczko/rpmbuild/BUILD/sphinx-inline-tabs-2021.04.11.beta9/docs/usage.md:177: WARNING: "unsupported "label"
/home/tkloczko/rpmbuild/BUILD/sphinx-inline-tabs-2021.04.11.beta9/docs/usage.md:1: WARNING: "unsupported "label"
/home/tkloczko/rpmbuild/BUILD/sphinx-inline-tabs-2021.04.11.beta9/docs/usage.md:4: WARNING: "unsupported "label"
/home/tkloczko/rpmbuild/BUILD/sphinx-inline-tabs-2021.04.11.beta9/docs/usage.md:186: WARNING: "unsupported "label"
/home/tkloczko/rpmbuild/BUILD/sphinx-inline-tabs-2021.04.11.beta9/docs/usage.md:5: WARNING: "unsupported "label"
/home/tkloczko/rpmbuild/BUILD/sphinx-inline-tabs-2021.04.11.beta9/docs/usage.md:8: WARNING: "unsupported "label"
/home/tkloczko/rpmbuild/BUILD/sphinx-inline-tabs-2021.04.11.beta9/docs/usage.md:11: WARNING: "unsupported "label"
/home/tkloczko/rpmbuild/BUILD/sphinx-inline-tabs-2021.04.11.beta9/docs/usage.md:14: WARNING: "unsupported "label"
done
build succeeded, 32 warnings.

Clicking and dragging a tab title causes *other* tabs to change but not the clicked tab

This seems edge-casey but I think it may be more common than expected. If you click and accidentally drag to highlight a letter or two, then all other tabs on the page will change, but the clicked tab will not. I accidentally did this a few times when testing it out, enough that it might be worth mentioning in the docs or edge-casing in the code.

2020-11-14_17-28-17

JS function onLabelClick is conflicting with same function from Sphinx design

Hello,

For our documentation we are using both Sphinx design and Sphinx inline tabs extensions, because inline tabs are easier to use, and we only use tab-set when we have more complex needs.

However, when using both extension, tab synchronization doesn't work for inline tabs because the JS function onLabelClick of tab.js is overwritten by the one from design-tab.js.

Any chance you could prefix this function in one or both projects?

Thank you.

RFE: PEP 440 compatible git tags

Hello. it seems this packages has version defined as 2020.10.19.beta4 whilst flit happily converts that to 2020.10.19b4 when packaging the sdist and wheel. o the git tag is not equal to the version on PyPI.

Would you please consider using a PEP 440 compatible version tag for the next beta? Thanks.

Render tab title as section heading for latex

Non-HTML build targets (e.g., Latex) don't support tabs.

Multiple tabs are correctly serialized in PDFs but the original Tab title is lost. It would be good if that tab title could be inserted has headings in that case.

Edit:

@BrennanGit 's comment contains a well working workaround: #34 (comment)

Support code tabs in rst files

The following snippet renders as normal text, not as code:

.. tab:: curl

    $ curl http://example.com

.. tab:: wget

    $ wget http://example.com

The demo for code tabs in this project is written in markdown. Wow would one flag this as code so that it renders properly?

Support for copy-button in code tabs

We are using the 'sphinx-copybutton' extension in our documentation which enables the reader to click on the code block and gets code (minus configured shell prompts) copied to the clipboard.

Would it be possible to enable sphinx-inline-tabs to work with this (or a similar) copybutton extension? This would be an excellent combination.

Make it possible to link to a specific tab's contents

This would make it easier to utilize this for linking to specific content that's under a non-default tab. It can also be used to provide OS-specific instructions by putting ?tab=windows or something at the end of a URL.

Support nesting tabs

It is currently not possible to nest tabs:
2021-02-27_16-21-09

Source code for the GIF:

*****************
Operating systems
*****************

.. tab:: Windows

    Owned by Microsoft

.. tab:: Linux

    Created by Linus Torvalds

    .. tab:: Ubuntu

        Owned by Canonical

    .. tab:: CentOS

        Owned by Red Hat

.. tab:: MacOS

    Owned by Apple

Allow to disable synchronization

Synchronization may be a good default but it shouldn't be enforced. There's a common scenario for tabs where synchronization is not desirable: the "input / output" scenario. I think it is as common as the "multiple languages" scenario, if not more common.

I'm using sphinx-panels at the moment but it'd be nice to have this feature in this nice extension.

Thanks for your work!

Inline 'dollarmath' rich tab label doesn't render right on https://sphinx-inline-tabs.readthedocs.io/

Hi,

I was just reading the docs on Rich Tab labels, which currently looks like this:

Screenshot 2024-02-02 at 10 37 47

I think the $2^2$ is meant to be dollar-delimited-math from MyST, but that it isn't rendering properly.

Maybe this is because the dollarmath MyST extension needs to be enabled? According to the docs this should be enabled by a block like:

myst_enable_extensions = [
    "dollarmath",
]

in the docs/conf.py of sphinx-inline-tabs - but I don't see this present. I could be misdiagnosing this thought, but thought it was worth mentioning. I'll keep looking and see if I can find a resolution (and if so, open a PR).

Allow use on Python 3.6

pyproject.toml defines the minimum Python version as 3.8. Installing on 3.6 seems to work fine, however.

As someone who's stuck on 3.6 it'd be great if this constraint could be relaxed. I'd understand if you want to keep the possibility of 3.8 features open, though.

Q: how to install sphinx-inline-tabs offline from source tar ball?

Maybe it is dumb question but packaging python modules so far all of them have been installed using setup.py file whicj in this project does not exist.
I cannot find some usefull documentation about type of build, install and executing test suite in project like that one.
May I as for help or some hint how to install sphinx-inline-tabs offline from source tar ball on system without access to the network?

PR for tabulated formats in rst/md

Hi, would it make sense to have the documentation show different tabs for rst/md formatting issues?

I at least managed to get the rst tabs to work with codes, but it seems (from the *md) files that you didn't get this to work? Or?

Allow use on Python 3.7

I'd love to switch from sphinx_tabs to sphinx-inline-tabs but the hard requirement on Python >= 3.8 make it impossible to do so: my project works with Python >= 3.7, which is still getting security fixes until 2023-06-27.

So in the same spirit as #24, is there any possibility to have Python requirement relaxed to 3.7 as a minimum? ๐Ÿ™‚

Large height differences between tab content causes problems with synchronisation

When you have a large height difference between the content of one set of tabs, and then switch tabs further down the page, the height difference above causes content to move around - sometimes so much that what you were looking at disappears from the page.

In the example below, when selecting from the second set of tabs, they move away from the position they were in.

Example:

..  tab:: Tall

    many
    lines
    of
    content
    many
    lines
    of
    content
    many
    lines
    of
    content
    many
    lines
    of
    content
    many
    lines
    of
    content

..  tab:: Short

    one line

Back to untabbed content, briefly.

..  tab:: Tall

    more stuff

..  tab:: Short

    more stuff

Using this extension breaks `sphinx-build -b xml`

With this extension installed and configured I started seeing this error:

% sphinx-build -b xml . _build
Running Sphinx v6.1.3
building [mo]: targets for 0 po files that are out of date
writing output... 
building [xml]: targets for 28 source files that are out of date
updating environment: [new config] 28 added, 0 changed, 0 removed
reading sources... [100%] writing_plugins                                                                                                                          
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [  3%] authentication                                                                                                                            
Exception occurred:
  File "/Users/simon/.local/share/virtualenvs/datasette-AWNrQs95/lib/python3.10/site-packages/docutils/nodes.py", line 2028, in unknown_visit
    raise NotImplementedError(
NotImplementedError: <class 'docutils.writers.docutils_xml.XMLTranslator'> visiting unknown node type: TabContainer
The full traceback has been saved in /var/folders/x6/31xf1vxj0nn9mxqq8z0mmcfw0000gn/T/sphinx-err-1wkxmkji.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!

Key error message in there:

visiting unknown node type: TabContainer

I tracked it down to this code in docutils/docutils here: https://github.com/docutils/docutils/blob/3b53ded52bc439d8068b6ecb20ea0a761247e479/docutils/docutils/nodes.py#L2021-L2031

Make it possible to override the synchronisation ID

Synchronization is obviously great for many purposes, but sometimes this is not something that you want. Take this example where I want to give input and (long) output in separate tabs. At the moment, the only way to prevent all tabs from switching is to rename the tab (Input 1, Input 2 etc.), which also changes its caption. I think a better way to do this would be to separate the caption from the name/label.
image

Multiple sets with same name will change all sets

@pradyunsg Thank you for this package! Amazing!

tabs.js

var labels_by_text = {};
function ready() {
var li = document.getElementsByClassName("tab-label");
for (const label of li) {
label.onclick = onLabelClick;
const text = label.textContent;
if (!labels_by_text[text]) {
labels_by_text[text] = [];
}
labels_by_text[text].push(label);
}
}
function onLabelClick() {
// Activate other labels with the same text.
for (label of labels_by_text[this.textContent]) {
label.previousSibling.checked = true;
}
}
document.addEventListener("DOMContentLoaded", ready, false);

example video
2022-03-12.15-45-45.-.sphinx-inline-tabs.-.label.jump.issue.mp4

In https://tmuxp.git-pull.com/examples.html (file) I have multiple sets of [YAML] [JSON] tabs:

image

If you scroll to any of the sections, such as Set tmux options, the page will jump because all the sets are switched based on the text

I will try to find a way to experiment locally, but using the id's already provided (id="tab-set--1-input--1") as a lookup table rather than text labels would be extremely effective.

Using `:math:` directives in the beginning of tab titles renders raw html

Found an interesting bug.

.. tab:: :math:`O(n)`
    
    hello world

Will render <math>O(n)</math>, while using the directive somewhere in the middle of a tab's title seems to be fine.

Here are screenshots of the problem

Screenshot from 2021-03-26 16-49-20

Naturally, I'm using Furo.

I've made a branch to show the error. (make livehtml should work for you once you've set up the requirements.)

Later additions:
Also, I've got more interesting variations of this bug.

Play around with the titles, I've tried using :term: with a glossary file, and this just fails at the build stage. Doesn't seem to be a
sphinx bug, but I am not sure.
Log here: sphinx-err-b9355wxr.log

Let me know how I can be of help.

Feature request: Can tab names be added to side nav?

Hi,
Is it possible to add tabs to sidebar nav of the page?

Tabs are basically replacing two section headings, and in a long page its nice to have the tab heading present in the side bar to scroll down to it on click.

image

Thanks!

toggling tabs cause page to jump

I have a single page with several sets of two tabs, e.g each tab contains a code-block for a CLI command and equivalent code in Python. For the first tab set on the page, toggling the tabs back and forth is smooth. However, for all subsequent tab sets on the page, when I toggle between the two tabs, it causes the page to jump erratically back and forth, as if it was jumping to an internal anchor on the page. This behavior isn't present in your usage docs, so maybe it's an issue with how I'm creating the tabs or another bug?

Each tab set is pretty much the same , e.g.

.. tab:: CLI

    .. code-block:: console

        $ command-line code

.. tab:: Python

    .. code-block:: python

        python code

Are there any tests?

Hello. I see the nox configuration and the test extra definition here, but there seem to be no tests at all. Is that the case?

(I am packaging this into Fedora, for pip, and this got me confused a bit.)

Using with sphinx-book-theme

When using these tabs with the book-theme I get a weird empty region:
Note the light gray bounding box line around the tabbed region.

sphinx-book-theme-inline-tabs

This looks a bit weird. This does not occur in the rtfd docs theme where the background gets correctly filled.

I have this custom css:

/*The parent container of tabs*/
.tab-set {
  border: 1px solid #ccc
}

/*Individual box of each tab*/
.tab-set > label {
  margin-bottom: 0
}

/*Container appearing below the tabs, with the contents of the active tab*/
.tab-content {
  background-color: aliceblue;
  padding: 20px
}

/*Initial paragraph of the content. By default there's a top margin 
 but we already specify a padding of 20 px for the content no matter what the
 first child is.*/
.tab-content > p:first-child {
  margin-top: 0
}

I much prefer the look of these minimal tabs compared to the others around. :)

Thanks for the package!

Explain the differences from sphinx-tabs in the README

sphinx-tabs was the way to create tabs in Sphinx before this extension was made, so I assume there are good reasons for creating a competing extension.

The README lists under "Features" some benefits of this extension such as small footprint, but can you add an explicit comparison with sphinx-tabs?

I think it will help people (like me) choose. Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.